blob: 97e12d77a194258b6a84a996df755e5a7a6ffddf [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
Chandler Carruth55fc8732012-12-04 09:13:33 +000017#include "TypeLocBuilder.h"
Douglas Gregorc68afe22009-09-03 21:38:09 +000018#include "clang/AST/Decl.h"
John McCall7cd088e2010-08-24 07:21:54 +000019#include "clang/AST/DeclObjC.h"
Richard Smith3e4c6c42011-05-05 21:57:07 +000020#include "clang/AST/DeclTemplate.h"
Douglas Gregor657c1ac2009-08-06 22:17:10 +000021#include "clang/AST/Expr.h"
Douglas Gregorb98b1992009-08-11 05:31:07 +000022#include "clang/AST/ExprCXX.h"
23#include "clang/AST/ExprObjC.h"
Douglas Gregor43959a92009-08-20 07:17:43 +000024#include "clang/AST/Stmt.h"
25#include "clang/AST/StmtCXX.h"
26#include "clang/AST/StmtObjC.h"
Alexey Bataev4fa7eab2013-07-19 03:13:43 +000027#include "clang/AST/StmtOpenMP.h"
Douglas Gregorb98b1992009-08-11 05:31:07 +000028#include "clang/Lex/Preprocessor.h"
Chandler Carruth55fc8732012-12-04 09:13:33 +000029#include "clang/Sema/Designator.h"
30#include "clang/Sema/Lookup.h"
31#include "clang/Sema/Ownership.h"
32#include "clang/Sema/ParsedTemplate.h"
33#include "clang/Sema/ScopeInfo.h"
34#include "clang/Sema/SemaDiagnostic.h"
35#include "clang/Sema/SemaInternal.h"
David Blaikiea71f9d02011-09-22 02:34:54 +000036#include "llvm/ADT/ArrayRef.h"
John McCalla2becad2009-10-21 00:40:46 +000037#include "llvm/Support/ErrorHandling.h"
Douglas Gregor577f75a2009-08-04 16:50:30 +000038#include <algorithm>
39
40namespace clang {
John McCall781472f2010-08-25 08:40:02 +000041using namespace sema;
Mike Stump1eb44332009-09-09 15:08:12 +000042
Douglas Gregor577f75a2009-08-04 16:50:30 +000043/// \brief A semantic tree transformation that allows one to transform one
44/// abstract syntax tree into another.
45///
Mike Stump1eb44332009-09-09 15:08:12 +000046/// A new tree transformation is defined by creating a new subclass \c X of
47/// \c TreeTransform<X> and then overriding certain operations to provide
48/// behavior specific to that transformation. For example, template
Douglas Gregor577f75a2009-08-04 16:50:30 +000049/// instantiation is implemented as a tree transformation where the
50/// transformation of TemplateTypeParmType nodes involves substituting the
51/// template arguments for their corresponding template parameters; a similar
52/// transformation is performed for non-type template parameters and
53/// template template parameters.
54///
55/// This tree-transformation template uses static polymorphism to allow
Mike Stump1eb44332009-09-09 15:08:12 +000056/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregor577f75a2009-08-04 16:50:30 +000057/// override any of the transformation or rebuild operators by providing an
58/// operation with the same signature as the default implementation. The
59/// overridding function should not be virtual.
60///
61/// Semantic tree transformations are split into two stages, either of which
62/// can be replaced by a subclass. The "transform" step transforms an AST node
63/// or the parts of an AST node using the various transformation functions,
64/// then passes the pieces on to the "rebuild" step, which constructs a new AST
65/// node of the appropriate kind from the pieces. The default transformation
66/// routines recursively transform the operands to composite AST nodes (e.g.,
67/// the pointee type of a PointerType node) and, if any of those operand nodes
68/// were changed by the transformation, invokes the rebuild operation to create
69/// a new AST node.
70///
Mike Stump1eb44332009-09-09 15:08:12 +000071/// Subclasses can customize the transformation at various levels. The
Douglas Gregor670444e2009-08-04 22:27:00 +000072/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregor9151c112011-03-02 18:50:38 +000073/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(),
Douglas Gregor577f75a2009-08-04 16:50:30 +000074/// TransformTemplateName(), or TransformTemplateArgument() with entirely
75/// new implementations.
76///
77/// For more fine-grained transformations, subclasses can replace any of the
78/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
Douglas Gregor43959a92009-08-20 07:17:43 +000079/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregor577f75a2009-08-04 16:50:30 +000080/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump1eb44332009-09-09 15:08:12 +000081/// to substitute template arguments for their corresponding template
Douglas Gregor577f75a2009-08-04 16:50:30 +000082/// parameters. Additionally, subclasses can override the \c RebuildXXX
83/// functions to control how AST nodes are rebuilt when their operands change.
84/// By default, \c TreeTransform will invoke semantic analysis to rebuild
85/// AST nodes. However, certain other tree transformations (e.g, cloning) may
86/// be able to use more efficient rebuild steps.
87///
88/// There are a handful of other functions that can be overridden, allowing one
Mike Stump1eb44332009-09-09 15:08:12 +000089/// to avoid traversing nodes that don't need any transformation
Douglas Gregor577f75a2009-08-04 16:50:30 +000090/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
91/// operands have not changed (\c AlwaysRebuild()), and customize the
92/// default locations and entity names used for type-checking
93/// (\c getBaseLocation(), \c getBaseEntity()).
Douglas Gregor577f75a2009-08-04 16:50:30 +000094template<typename Derived>
95class TreeTransform {
Douglas Gregord3731192011-01-10 07:32:04 +000096 /// \brief Private RAII object that helps us forget and then re-remember
97 /// the template argument corresponding to a partially-substituted parameter
98 /// pack.
99 class ForgetPartiallySubstitutedPackRAII {
100 Derived &Self;
101 TemplateArgument Old;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000102
Douglas Gregord3731192011-01-10 07:32:04 +0000103 public:
104 ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) {
105 Old = Self.ForgetPartiallySubstitutedPack();
106 }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000107
Douglas Gregord3731192011-01-10 07:32:04 +0000108 ~ForgetPartiallySubstitutedPackRAII() {
109 Self.RememberPartiallySubstitutedPack(Old);
110 }
111 };
Chad Rosier4a9d7952012-08-08 18:46:20 +0000112
Douglas Gregor577f75a2009-08-04 16:50:30 +0000113protected:
114 Sema &SemaRef;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000115
Douglas Gregordfca6f52012-02-13 22:00:16 +0000116 /// \brief The set of local declarations that have been transformed, for
117 /// cases where we are forced to build new declarations within the transformer
118 /// rather than in the subclass (e.g., lambda closure types).
119 llvm::DenseMap<Decl *, Decl *> TransformedLocalDecls;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000120
Mike Stump1eb44332009-09-09 15:08:12 +0000121public:
Douglas Gregor577f75a2009-08-04 16:50:30 +0000122 /// \brief Initializes a new tree transformer.
Douglas Gregorb99268b2010-12-21 00:52:54 +0000123 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump1eb44332009-09-09 15:08:12 +0000124
Douglas Gregor577f75a2009-08-04 16:50:30 +0000125 /// \brief Retrieves a reference to the derived class.
126 Derived &getDerived() { return static_cast<Derived&>(*this); }
127
128 /// \brief Retrieves a reference to the derived class.
Mike Stump1eb44332009-09-09 15:08:12 +0000129 const Derived &getDerived() const {
130 return static_cast<const Derived&>(*this);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000131 }
132
John McCall60d7b3a2010-08-24 06:29:42 +0000133 static inline ExprResult Owned(Expr *E) { return E; }
134 static inline StmtResult Owned(Stmt *S) { return S; }
John McCall9ae2f072010-08-23 23:25:46 +0000135
Douglas Gregor577f75a2009-08-04 16:50:30 +0000136 /// \brief Retrieves a reference to the semantic analysis object used for
137 /// this tree transform.
138 Sema &getSema() const { return SemaRef; }
Mike Stump1eb44332009-09-09 15:08:12 +0000139
Douglas Gregor577f75a2009-08-04 16:50:30 +0000140 /// \brief Whether the transformation should always rebuild AST nodes, even
141 /// if none of the children have changed.
142 ///
143 /// Subclasses may override this function to specify when the transformation
144 /// should rebuild all AST nodes.
145 bool AlwaysRebuild() { return false; }
Mike Stump1eb44332009-09-09 15:08:12 +0000146
Douglas Gregor577f75a2009-08-04 16:50:30 +0000147 /// \brief Returns the location of the entity being transformed, if that
148 /// information was not available elsewhere in the AST.
149 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000150 /// By default, returns no source-location information. Subclasses can
Douglas Gregor577f75a2009-08-04 16:50:30 +0000151 /// provide an alternative implementation that provides better location
152 /// information.
153 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump1eb44332009-09-09 15:08:12 +0000154
Douglas Gregor577f75a2009-08-04 16:50:30 +0000155 /// \brief Returns the name of the entity being transformed, if that
156 /// information was not available elsewhere in the AST.
157 ///
158 /// By default, returns an empty name. Subclasses can provide an alternative
159 /// implementation with a more precise name.
160 DeclarationName getBaseEntity() { return DeclarationName(); }
161
Douglas Gregorb98b1992009-08-11 05:31:07 +0000162 /// \brief Sets the "base" location and entity when that
163 /// information is known based on another transformation.
164 ///
165 /// By default, the source location and entity are ignored. Subclasses can
166 /// override this function to provide a customized implementation.
167 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump1eb44332009-09-09 15:08:12 +0000168
Douglas Gregorb98b1992009-08-11 05:31:07 +0000169 /// \brief RAII object that temporarily sets the base location and entity
170 /// used for reporting diagnostics in types.
171 class TemporaryBase {
172 TreeTransform &Self;
173 SourceLocation OldLocation;
174 DeclarationName OldEntity;
Mike Stump1eb44332009-09-09 15:08:12 +0000175
Douglas Gregorb98b1992009-08-11 05:31:07 +0000176 public:
177 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump1eb44332009-09-09 15:08:12 +0000178 DeclarationName Entity) : Self(Self) {
Douglas Gregorb98b1992009-08-11 05:31:07 +0000179 OldLocation = Self.getDerived().getBaseLocation();
180 OldEntity = Self.getDerived().getBaseEntity();
Chad Rosier4a9d7952012-08-08 18:46:20 +0000181
Douglas Gregorae201f72011-01-25 17:51:48 +0000182 if (Location.isValid())
183 Self.getDerived().setBase(Location, Entity);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000184 }
Mike Stump1eb44332009-09-09 15:08:12 +0000185
Douglas Gregorb98b1992009-08-11 05:31:07 +0000186 ~TemporaryBase() {
187 Self.getDerived().setBase(OldLocation, OldEntity);
188 }
189 };
Mike Stump1eb44332009-09-09 15:08:12 +0000190
191 /// \brief Determine whether the given type \p T has already been
Douglas Gregor577f75a2009-08-04 16:50:30 +0000192 /// transformed.
193 ///
194 /// Subclasses can provide an alternative implementation of this routine
Mike Stump1eb44332009-09-09 15:08:12 +0000195 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregor577f75a2009-08-04 16:50:30 +0000196 /// not change. For example, template instantiation need not traverse
197 /// non-dependent types.
198 bool AlreadyTransformed(QualType T) {
199 return T.isNull();
200 }
201
Douglas Gregor6eef5192009-12-14 19:27:10 +0000202 /// \brief Determine whether the given call argument should be dropped, e.g.,
203 /// because it is a default argument.
204 ///
205 /// Subclasses can provide an alternative implementation of this routine to
206 /// determine which kinds of call arguments get dropped. By default,
207 /// CXXDefaultArgument nodes are dropped (prior to transformation).
208 bool DropCallArgument(Expr *E) {
209 return E->isDefaultArgument();
210 }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000211
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000212 /// \brief Determine whether we should expand a pack expansion with the
213 /// given set of parameter packs into separate arguments by repeatedly
214 /// transforming the pattern.
215 ///
Douglas Gregorb99268b2010-12-21 00:52:54 +0000216 /// By default, the transformer never tries to expand pack expansions.
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000217 /// Subclasses can override this routine to provide different behavior.
218 ///
219 /// \param EllipsisLoc The location of the ellipsis that identifies the
220 /// pack expansion.
221 ///
222 /// \param PatternRange The source range that covers the entire pattern of
223 /// the pack expansion.
224 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000225 /// \param Unexpanded The set of unexpanded parameter packs within the
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000226 /// pattern.
227 ///
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000228 /// \param ShouldExpand Will be set to \c true if the transformer should
229 /// expand the corresponding pack expansions into separate arguments. When
230 /// set, \c NumExpansions must also be set.
231 ///
Douglas Gregord3731192011-01-10 07:32:04 +0000232 /// \param RetainExpansion Whether the caller should add an unexpanded
233 /// pack expansion after all of the expanded arguments. This is used
234 /// when extending explicitly-specified template argument packs per
235 /// C++0x [temp.arg.explicit]p9.
236 ///
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000237 /// \param NumExpansions The number of separate arguments that will be in
Douglas Gregorcded4f62011-01-14 17:04:44 +0000238 /// the expanded form of the corresponding pack expansion. This is both an
239 /// input and an output parameter, which can be set by the caller if the
240 /// number of expansions is known a priori (e.g., due to a prior substitution)
241 /// and will be set by the callee when the number of expansions is known.
242 /// The callee must set this value when \c ShouldExpand is \c true; it may
243 /// set this value in other cases.
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000244 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000245 /// \returns true if an error occurred (e.g., because the parameter packs
246 /// are to be instantiated with arguments of different lengths), false
247 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000248 /// must be set.
249 bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
250 SourceRange PatternRange,
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +0000251 ArrayRef<UnexpandedParameterPack> Unexpanded,
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000252 bool &ShouldExpand,
Douglas Gregord3731192011-01-10 07:32:04 +0000253 bool &RetainExpansion,
David Blaikiedc84cd52013-02-20 22:23:23 +0000254 Optional<unsigned> &NumExpansions) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000255 ShouldExpand = false;
256 return false;
257 }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000258
Douglas Gregord3731192011-01-10 07:32:04 +0000259 /// \brief "Forget" about the partially-substituted pack template argument,
260 /// when performing an instantiation that must preserve the parameter pack
261 /// use.
262 ///
263 /// This routine is meant to be overridden by the template instantiator.
264 TemplateArgument ForgetPartiallySubstitutedPack() {
265 return TemplateArgument();
266 }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000267
Douglas Gregord3731192011-01-10 07:32:04 +0000268 /// \brief "Remember" the partially-substituted pack template argument
269 /// after performing an instantiation that must preserve the parameter pack
270 /// use.
271 ///
272 /// This routine is meant to be overridden by the template instantiator.
273 void RememberPartiallySubstitutedPack(TemplateArgument Arg) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000274
Douglas Gregor12c9c002011-01-07 16:43:16 +0000275 /// \brief Note to the derived class when a function parameter pack is
276 /// being expanded.
277 void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000278
Douglas Gregor577f75a2009-08-04 16:50:30 +0000279 /// \brief Transforms the given type into another type.
280 ///
John McCalla2becad2009-10-21 00:40:46 +0000281 /// By default, this routine transforms a type by creating a
John McCalla93c9342009-12-07 02:54:59 +0000282 /// TypeSourceInfo for it and delegating to the appropriate
John McCalla2becad2009-10-21 00:40:46 +0000283 /// function. This is expensive, but we don't mind, because
284 /// this method is deprecated anyway; all users should be
John McCalla93c9342009-12-07 02:54:59 +0000285 /// switched to storing TypeSourceInfos.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000286 ///
287 /// \returns the transformed type.
John McCall43fed0d2010-11-12 08:19:04 +0000288 QualType TransformType(QualType T);
Mike Stump1eb44332009-09-09 15:08:12 +0000289
John McCalla2becad2009-10-21 00:40:46 +0000290 /// \brief Transforms the given type-with-location into a new
291 /// type-with-location.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000292 ///
John McCalla2becad2009-10-21 00:40:46 +0000293 /// By default, this routine transforms a type by delegating to the
294 /// appropriate TransformXXXType to build a new type. Subclasses
295 /// may override this function (to take over all type
296 /// transformations) or some set of the TransformXXXType functions
297 /// to alter the transformation.
John McCall43fed0d2010-11-12 08:19:04 +0000298 TypeSourceInfo *TransformType(TypeSourceInfo *DI);
John McCalla2becad2009-10-21 00:40:46 +0000299
300 /// \brief Transform the given type-with-location into a new
301 /// type, collecting location information in the given builder
302 /// as necessary.
303 ///
John McCall43fed0d2010-11-12 08:19:04 +0000304 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
Mike Stump1eb44332009-09-09 15:08:12 +0000305
Douglas Gregor657c1ac2009-08-06 22:17:10 +0000306 /// \brief Transform the given statement.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000307 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000308 /// By default, this routine transforms a statement by delegating to the
Douglas Gregor43959a92009-08-20 07:17:43 +0000309 /// appropriate TransformXXXStmt function to transform a specific kind of
310 /// statement or the TransformExpr() function to transform an expression.
311 /// Subclasses may override this function to transform statements using some
312 /// other mechanism.
313 ///
314 /// \returns the transformed statement.
John McCall60d7b3a2010-08-24 06:29:42 +0000315 StmtResult TransformStmt(Stmt *S);
Mike Stump1eb44332009-09-09 15:08:12 +0000316
Alexey Bataev4fa7eab2013-07-19 03:13:43 +0000317 /// \brief Transform the given statement.
318 ///
319 /// By default, this routine transforms a statement by delegating to the
320 /// appropriate TransformOMPXXXClause function to transform a specific kind
321 /// of clause. Subclasses may override this function to transform statements
322 /// using some other mechanism.
323 ///
324 /// \returns the transformed OpenMP clause.
325 OMPClause *TransformOMPClause(OMPClause *S);
326
Douglas Gregor657c1ac2009-08-06 22:17:10 +0000327 /// \brief Transform the given expression.
328 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +0000329 /// By default, this routine transforms an expression by delegating to the
330 /// appropriate TransformXXXExpr function to build a new expression.
331 /// Subclasses may override this function to transform expressions using some
332 /// other mechanism.
333 ///
334 /// \returns the transformed expression.
John McCall60d7b3a2010-08-24 06:29:42 +0000335 ExprResult TransformExpr(Expr *E);
Mike Stump1eb44332009-09-09 15:08:12 +0000336
Richard Smithc83c2302012-12-19 01:39:02 +0000337 /// \brief Transform the given initializer.
338 ///
339 /// By default, this routine transforms an initializer by stripping off the
340 /// semantic nodes added by initialization, then passing the result to
341 /// TransformExpr or TransformExprs.
342 ///
343 /// \returns the transformed initializer.
344 ExprResult TransformInitializer(Expr *Init, bool CXXDirectInit);
345
Douglas Gregoraa165f82011-01-03 19:04:46 +0000346 /// \brief Transform the given list of expressions.
347 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000348 /// This routine transforms a list of expressions by invoking
349 /// \c TransformExpr() for each subexpression. However, it also provides
Douglas Gregoraa165f82011-01-03 19:04:46 +0000350 /// support for variadic templates by expanding any pack expansions (if the
351 /// derived class permits such expansion) along the way. When pack expansions
352 /// are present, the number of outputs may not equal the number of inputs.
353 ///
354 /// \param Inputs The set of expressions to be transformed.
355 ///
356 /// \param NumInputs The number of expressions in \c Inputs.
357 ///
358 /// \param IsCall If \c true, then this transform is being performed on
Chad Rosier4a9d7952012-08-08 18:46:20 +0000359 /// function-call arguments, and any arguments that should be dropped, will
Douglas Gregoraa165f82011-01-03 19:04:46 +0000360 /// be.
361 ///
362 /// \param Outputs The transformed input expressions will be added to this
363 /// vector.
364 ///
365 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
366 /// due to transformation.
367 ///
368 /// \returns true if an error occurred, false otherwise.
369 bool TransformExprs(Expr **Inputs, unsigned NumInputs, bool IsCall,
Chris Lattner686775d2011-07-20 06:58:45 +0000370 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +0000371 bool *ArgChanged = 0);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000372
Douglas Gregor577f75a2009-08-04 16:50:30 +0000373 /// \brief Transform the given declaration, which is referenced from a type
374 /// or expression.
375 ///
Douglas Gregordfca6f52012-02-13 22:00:16 +0000376 /// By default, acts as the identity function on declarations, unless the
377 /// transformer has had to transform the declaration itself. Subclasses
Douglas Gregordcee1a12009-08-06 05:28:30 +0000378 /// may override this function to provide alternate behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +0000379 Decl *TransformDecl(SourceLocation Loc, Decl *D) {
Douglas Gregordfca6f52012-02-13 22:00:16 +0000380 llvm::DenseMap<Decl *, Decl *>::iterator Known
381 = TransformedLocalDecls.find(D);
382 if (Known != TransformedLocalDecls.end())
383 return Known->second;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000384
385 return D;
Douglas Gregordfca6f52012-02-13 22:00:16 +0000386 }
Douglas Gregor43959a92009-08-20 07:17:43 +0000387
Chad Rosier4a9d7952012-08-08 18:46:20 +0000388 /// \brief Transform the attributes associated with the given declaration and
Douglas Gregordfca6f52012-02-13 22:00:16 +0000389 /// place them on the new declaration.
390 ///
391 /// By default, this operation does nothing. Subclasses may override this
392 /// behavior to transform attributes.
393 void transformAttrs(Decl *Old, Decl *New) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000394
Douglas Gregordfca6f52012-02-13 22:00:16 +0000395 /// \brief Note that a local declaration has been transformed by this
396 /// transformer.
397 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000398 /// Local declarations are typically transformed via a call to
Douglas Gregordfca6f52012-02-13 22:00:16 +0000399 /// TransformDefinition. However, in some cases (e.g., lambda expressions),
400 /// the transformer itself has to transform the declarations. This routine
401 /// can be overridden by a subclass that keeps track of such mappings.
402 void transformedLocalDecl(Decl *Old, Decl *New) {
403 TransformedLocalDecls[Old] = New;
404 }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000405
Douglas Gregor43959a92009-08-20 07:17:43 +0000406 /// \brief Transform the definition of the given declaration.
407 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000408 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregor43959a92009-08-20 07:17:43 +0000409 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +0000410 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
411 return getDerived().TransformDecl(Loc, D);
Douglas Gregor7c1e98f2010-03-01 15:56:25 +0000412 }
Mike Stump1eb44332009-09-09 15:08:12 +0000413
Douglas Gregor6cd21982009-10-20 05:58:46 +0000414 /// \brief Transform the given declaration, which was the first part of a
415 /// nested-name-specifier in a member access expression.
416 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000417 /// This specific declaration transformation only applies to the first
Douglas Gregor6cd21982009-10-20 05:58:46 +0000418 /// identifier in a nested-name-specifier of a member access expression, e.g.,
419 /// the \c T in \c x->T::member
420 ///
421 /// By default, invokes TransformDecl() to transform the declaration.
422 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +0000423 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
424 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregor6cd21982009-10-20 05:58:46 +0000425 }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000426
Douglas Gregorc22b5ff2011-02-25 02:25:35 +0000427 /// \brief Transform the given nested-name-specifier with source-location
428 /// information.
429 ///
430 /// By default, transforms all of the types and declarations within the
431 /// nested-name-specifier. Subclasses may override this function to provide
432 /// alternate behavior.
433 NestedNameSpecifierLoc TransformNestedNameSpecifierLoc(
434 NestedNameSpecifierLoc NNS,
435 QualType ObjectType = QualType(),
436 NamedDecl *FirstQualifierInScope = 0);
437
Douglas Gregor81499bb2009-09-03 22:13:48 +0000438 /// \brief Transform the given declaration name.
439 ///
440 /// By default, transforms the types of conversion function, constructor,
441 /// and destructor names and then (if needed) rebuilds the declaration name.
442 /// Identifiers and selectors are returned unmodified. Sublcasses may
443 /// override this function to provide alternate behavior.
Abramo Bagnara25777432010-08-11 22:01:17 +0000444 DeclarationNameInfo
John McCall43fed0d2010-11-12 08:19:04 +0000445 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump1eb44332009-09-09 15:08:12 +0000446
Douglas Gregor577f75a2009-08-04 16:50:30 +0000447 /// \brief Transform the given template name.
Mike Stump1eb44332009-09-09 15:08:12 +0000448 ///
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000449 /// \param SS The nested-name-specifier that qualifies the template
450 /// name. This nested-name-specifier must already have been transformed.
451 ///
452 /// \param Name The template name to transform.
453 ///
454 /// \param NameLoc The source location of the template name.
455 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000456 /// \param ObjectType If we're translating a template name within a member
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000457 /// access expression, this is the type of the object whose member template
458 /// is being referenced.
459 ///
460 /// \param FirstQualifierInScope If the first part of a nested-name-specifier
461 /// also refers to a name within the current (lexical) scope, this is the
462 /// declaration it refers to.
463 ///
464 /// By default, transforms the template name by transforming the declarations
465 /// and nested-name-specifiers that occur within the template name.
466 /// Subclasses may override this function to provide alternate behavior.
467 TemplateName TransformTemplateName(CXXScopeSpec &SS,
468 TemplateName Name,
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000469 SourceLocation NameLoc,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000470 QualType ObjectType = QualType(),
471 NamedDecl *FirstQualifierInScope = 0);
472
Douglas Gregor577f75a2009-08-04 16:50:30 +0000473 /// \brief Transform the given template argument.
474 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000475 /// By default, this operation transforms the type, expression, or
476 /// declaration stored within the template argument and constructs a
Douglas Gregor670444e2009-08-04 22:27:00 +0000477 /// new template argument from the transformed result. Subclasses may
478 /// override this function to provide alternate behavior.
John McCall833ca992009-10-29 08:12:44 +0000479 ///
480 /// Returns true if there was an error.
481 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
482 TemplateArgumentLoc &Output);
483
Douglas Gregorfcc12532010-12-20 17:31:10 +0000484 /// \brief Transform the given set of template arguments.
485 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000486 /// By default, this operation transforms all of the template arguments
Douglas Gregorfcc12532010-12-20 17:31:10 +0000487 /// in the input set using \c TransformTemplateArgument(), and appends
488 /// the transformed arguments to the output list.
489 ///
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000490 /// Note that this overload of \c TransformTemplateArguments() is merely
491 /// a convenience function. Subclasses that wish to override this behavior
492 /// should override the iterator-based member template version.
493 ///
Douglas Gregorfcc12532010-12-20 17:31:10 +0000494 /// \param Inputs The set of template arguments to be transformed.
495 ///
496 /// \param NumInputs The number of template arguments in \p Inputs.
497 ///
498 /// \param Outputs The set of transformed template arguments output by this
499 /// routine.
500 ///
501 /// Returns true if an error occurred.
502 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
503 unsigned NumInputs,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000504 TemplateArgumentListInfo &Outputs) {
505 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs);
506 }
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000507
508 /// \brief Transform the given set of template arguments.
509 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000510 /// By default, this operation transforms all of the template arguments
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000511 /// in the input set using \c TransformTemplateArgument(), and appends
Chad Rosier4a9d7952012-08-08 18:46:20 +0000512 /// the transformed arguments to the output list.
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000513 ///
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000514 /// \param First An iterator to the first template argument.
515 ///
516 /// \param Last An iterator one step past the last template argument.
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000517 ///
518 /// \param Outputs The set of transformed template arguments output by this
519 /// routine.
520 ///
521 /// Returns true if an error occurred.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000522 template<typename InputIterator>
523 bool TransformTemplateArguments(InputIterator First,
524 InputIterator Last,
525 TemplateArgumentListInfo &Outputs);
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000526
John McCall833ca992009-10-29 08:12:44 +0000527 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
528 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
529 TemplateArgumentLoc &ArgLoc);
530
John McCalla93c9342009-12-07 02:54:59 +0000531 /// \brief Fakes up a TypeSourceInfo for a type.
532 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
533 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall833ca992009-10-29 08:12:44 +0000534 getDerived().getBaseLocation());
535 }
Mike Stump1eb44332009-09-09 15:08:12 +0000536
John McCalla2becad2009-10-21 00:40:46 +0000537#define ABSTRACT_TYPELOC(CLASS, PARENT)
538#define TYPELOC(CLASS, PARENT) \
John McCall43fed0d2010-11-12 08:19:04 +0000539 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCalla2becad2009-10-21 00:40:46 +0000540#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +0000541
Douglas Gregorcefc3af2012-04-16 07:05:22 +0000542 QualType TransformFunctionProtoType(TypeLocBuilder &TLB,
543 FunctionProtoTypeLoc TL,
544 CXXRecordDecl *ThisContext,
545 unsigned ThisTypeQuals);
546
David Majnemerfc210492013-10-15 09:33:02 +0000547 StmtResult TransformSEHHandler(Stmt *Handler);
John Wiegley28bbe4b2011-04-28 01:08:34 +0000548
Chad Rosier4a9d7952012-08-08 18:46:20 +0000549 QualType
John McCall43fed0d2010-11-12 08:19:04 +0000550 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
551 TemplateSpecializationTypeLoc TL,
552 TemplateName Template);
553
Chad Rosier4a9d7952012-08-08 18:46:20 +0000554 QualType
John McCall43fed0d2010-11-12 08:19:04 +0000555 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
556 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +0000557 TemplateName Template,
558 CXXScopeSpec &SS);
Douglas Gregora88f09f2011-02-28 17:23:35 +0000559
Chad Rosier4a9d7952012-08-08 18:46:20 +0000560 QualType
Douglas Gregora88f09f2011-02-28 17:23:35 +0000561 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000562 DependentTemplateSpecializationTypeLoc TL,
563 NestedNameSpecifierLoc QualifierLoc);
564
John McCall21ef0fa2010-03-11 09:03:00 +0000565 /// \brief Transforms the parameters of a function type into the
566 /// given vectors.
567 ///
568 /// The result vectors should be kept in sync; null entries in the
569 /// variables vector are acceptable.
570 ///
571 /// Return true on error.
Douglas Gregora009b592011-01-07 00:20:55 +0000572 bool TransformFunctionTypeParams(SourceLocation Loc,
573 ParmVarDecl **Params, unsigned NumParams,
574 const QualType *ParamTypes,
Chris Lattner686775d2011-07-20 06:58:45 +0000575 SmallVectorImpl<QualType> &PTypes,
576 SmallVectorImpl<ParmVarDecl*> *PVars);
John McCall21ef0fa2010-03-11 09:03:00 +0000577
578 /// \brief Transforms a single function-type parameter. Return null
579 /// on error.
John McCallfb44de92011-05-01 22:35:37 +0000580 ///
581 /// \param indexAdjustment - A number to add to the parameter's
582 /// scope index; can be negative
Douglas Gregor6a24bfd2011-01-14 22:40:04 +0000583 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCallfb44de92011-05-01 22:35:37 +0000584 int indexAdjustment,
David Blaikiedc84cd52013-02-20 22:23:23 +0000585 Optional<unsigned> NumExpansions,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +0000586 bool ExpectParameterPack);
John McCall21ef0fa2010-03-11 09:03:00 +0000587
John McCall43fed0d2010-11-12 08:19:04 +0000588 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall833ca992009-10-29 08:12:44 +0000589
John McCall60d7b3a2010-08-24 06:29:42 +0000590 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
591 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Mike Stump1eb44332009-09-09 15:08:12 +0000592
Richard Smith612409e2012-07-25 03:56:55 +0000593 /// \brief Transform the captures and body of a lambda expression.
594 ExprResult TransformLambdaScope(LambdaExpr *E, CXXMethodDecl *CallOperator);
595
Richard Smithefeeccf2012-10-21 03:28:35 +0000596 ExprResult TransformAddressOfOperand(Expr *E);
597 ExprResult TransformDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E,
598 bool IsAddressOfOperand);
599
Eli Friedman1ac6c932013-09-06 01:13:30 +0000600// FIXME: We use LLVM_ATTRIBUTE_NOINLINE because inlining causes a ridiculous
601// amount of stack usage with clang.
Douglas Gregor43959a92009-08-20 07:17:43 +0000602#define STMT(Node, Parent) \
Eli Friedman1ac6c932013-09-06 01:13:30 +0000603 LLVM_ATTRIBUTE_NOINLINE \
John McCall60d7b3a2010-08-24 06:29:42 +0000604 StmtResult Transform##Node(Node *S);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000605#define EXPR(Node, Parent) \
Eli Friedman1ac6c932013-09-06 01:13:30 +0000606 LLVM_ATTRIBUTE_NOINLINE \
John McCall60d7b3a2010-08-24 06:29:42 +0000607 ExprResult Transform##Node(Node *E);
Sean Hunt7381d5c2010-05-18 06:22:21 +0000608#define ABSTRACT_STMT(Stmt)
Sean Hunt4bfe1962010-05-05 15:24:00 +0000609#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +0000610
Alexey Bataev4fa7eab2013-07-19 03:13:43 +0000611#define OPENMP_CLAUSE(Name, Class) \
Eli Friedman1ac6c932013-09-06 01:13:30 +0000612 LLVM_ATTRIBUTE_NOINLINE \
Alexey Bataev4fa7eab2013-07-19 03:13:43 +0000613 OMPClause *Transform ## Class(Class *S);
614#include "clang/Basic/OpenMPKinds.def"
615
Douglas Gregor577f75a2009-08-04 16:50:30 +0000616 /// \brief Build a new pointer type given its pointee type.
617 ///
618 /// By default, performs semantic analysis when building the pointer type.
619 /// Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000620 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000621
622 /// \brief Build a new block pointer type given its pointee type.
623 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000624 /// By default, performs semantic analysis when building the block pointer
Douglas Gregor577f75a2009-08-04 16:50:30 +0000625 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000626 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000627
John McCall85737a72009-10-30 00:06:24 +0000628 /// \brief Build a new reference type given the type it references.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000629 ///
John McCall85737a72009-10-30 00:06:24 +0000630 /// By default, performs semantic analysis when building the
631 /// reference type. Subclasses may override this routine to provide
632 /// different behavior.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000633 ///
John McCall85737a72009-10-30 00:06:24 +0000634 /// \param LValue whether the type was written with an lvalue sigil
635 /// or an rvalue sigil.
636 QualType RebuildReferenceType(QualType ReferentType,
637 bool LValue,
638 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000639
Douglas Gregor577f75a2009-08-04 16:50:30 +0000640 /// \brief Build a new member pointer type given the pointee type and the
641 /// class type it refers into.
642 ///
643 /// By default, performs semantic analysis when building the member pointer
644 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000645 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
646 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000647
Douglas Gregor577f75a2009-08-04 16:50:30 +0000648 /// \brief Build a new array type given the element type, size
649 /// modifier, size of the array (if known), size expression, and index type
650 /// qualifiers.
651 ///
652 /// By default, performs semantic analysis when building the array type.
653 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000654 /// Also by default, all of the other Rebuild*Array
Douglas Gregor577f75a2009-08-04 16:50:30 +0000655 QualType RebuildArrayType(QualType ElementType,
656 ArrayType::ArraySizeModifier SizeMod,
657 const llvm::APInt *Size,
658 Expr *SizeExpr,
659 unsigned IndexTypeQuals,
660 SourceRange BracketsRange);
Mike Stump1eb44332009-09-09 15:08:12 +0000661
Douglas Gregor577f75a2009-08-04 16:50:30 +0000662 /// \brief Build a new constant array type given the element type, size
663 /// modifier, (known) size of the array, 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 RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000668 ArrayType::ArraySizeModifier SizeMod,
669 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +0000670 unsigned IndexTypeQuals,
671 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000672
Douglas Gregor577f75a2009-08-04 16:50:30 +0000673 /// \brief Build a new incomplete array type given the element type, size
674 /// modifier, and index type qualifiers.
675 ///
676 /// By default, performs semantic analysis when building the array type.
677 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000678 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000679 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +0000680 unsigned IndexTypeQuals,
681 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000682
Mike Stump1eb44332009-09-09 15:08:12 +0000683 /// \brief Build a new variable-length array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000684 /// size modifier, size expression, and index type qualifiers.
685 ///
686 /// By default, performs semantic analysis when building the array type.
687 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000688 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000689 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +0000690 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000691 unsigned IndexTypeQuals,
692 SourceRange BracketsRange);
693
Mike Stump1eb44332009-09-09 15:08:12 +0000694 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000695 /// size modifier, size expression, and index type qualifiers.
696 ///
697 /// By default, performs semantic analysis when building the array type.
698 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000699 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000700 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +0000701 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000702 unsigned IndexTypeQuals,
703 SourceRange BracketsRange);
704
705 /// \brief Build a new vector type given the element type and
706 /// number of elements.
707 ///
708 /// By default, performs semantic analysis when building the vector type.
709 /// Subclasses may override this routine to provide different behavior.
John Thompson82287d12010-02-05 00:12:22 +0000710 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsone86d78c2010-11-10 21:56:12 +0000711 VectorType::VectorKind VecKind);
Mike Stump1eb44332009-09-09 15:08:12 +0000712
Douglas Gregor577f75a2009-08-04 16:50:30 +0000713 /// \brief Build a new extended vector type given the element type and
714 /// number of elements.
715 ///
716 /// By default, performs semantic analysis when building the vector type.
717 /// Subclasses may override this routine to provide different behavior.
718 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
719 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000720
721 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregor577f75a2009-08-04 16:50:30 +0000722 /// given the element type and number of elements.
723 ///
724 /// By default, performs semantic analysis when building the vector type.
725 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000726 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +0000727 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000728 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000729
Douglas Gregor577f75a2009-08-04 16:50:30 +0000730 /// \brief Build a new function type.
731 ///
732 /// By default, performs semantic analysis when building the function type.
733 /// Subclasses may override this routine to provide different behavior.
734 QualType RebuildFunctionProtoType(QualType T,
Jordan Rosebea522f2013-03-08 21:51:21 +0000735 llvm::MutableArrayRef<QualType> ParamTypes,
Jordan Rose09189892013-03-08 22:25:36 +0000736 const FunctionProtoType::ExtProtoInfo &EPI);
Mike Stump1eb44332009-09-09 15:08:12 +0000737
John McCalla2becad2009-10-21 00:40:46 +0000738 /// \brief Build a new unprototyped function type.
739 QualType RebuildFunctionNoProtoType(QualType ResultType);
740
John McCalled976492009-12-04 22:46:56 +0000741 /// \brief Rebuild an unresolved typename type, given the decl that
742 /// the UnresolvedUsingTypenameDecl was transformed to.
743 QualType RebuildUnresolvedUsingType(Decl *D);
744
Douglas Gregor577f75a2009-08-04 16:50:30 +0000745 /// \brief Build a new typedef type.
Richard Smith162e1c12011-04-15 14:24:37 +0000746 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
Douglas Gregor577f75a2009-08-04 16:50:30 +0000747 return SemaRef.Context.getTypeDeclType(Typedef);
748 }
749
750 /// \brief Build a new class/struct/union type.
751 QualType RebuildRecordType(RecordDecl *Record) {
752 return SemaRef.Context.getTypeDeclType(Record);
753 }
754
755 /// \brief Build a new Enum type.
756 QualType RebuildEnumType(EnumDecl *Enum) {
757 return SemaRef.Context.getTypeDeclType(Enum);
758 }
John McCall7da24312009-09-05 00:15:47 +0000759
Mike Stump1eb44332009-09-09 15:08:12 +0000760 /// \brief Build a new typeof(expr) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000761 ///
762 /// By default, performs semantic analysis when building the typeof type.
763 /// Subclasses may override this routine to provide different behavior.
John McCall2a984ca2010-10-12 00:20:44 +0000764 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000765
Mike Stump1eb44332009-09-09 15:08:12 +0000766 /// \brief Build a new typeof(type) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000767 ///
768 /// By default, builds a new TypeOfType with the given underlying type.
769 QualType RebuildTypeOfType(QualType Underlying);
770
Sean Huntca63c202011-05-24 22:41:36 +0000771 /// \brief Build a new unary transform type.
772 QualType RebuildUnaryTransformType(QualType BaseType,
773 UnaryTransformType::UTTKind UKind,
774 SourceLocation Loc);
775
Richard Smitha2c36462013-04-26 16:15:35 +0000776 /// \brief Build a new C++11 decltype type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000777 ///
778 /// By default, performs semantic analysis when building the decltype type.
779 /// Subclasses may override this routine to provide different behavior.
John McCall2a984ca2010-10-12 00:20:44 +0000780 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump1eb44332009-09-09 15:08:12 +0000781
Richard Smitha2c36462013-04-26 16:15:35 +0000782 /// \brief Build a new C++11 auto type.
Richard Smith34b41d92011-02-20 03:19:35 +0000783 ///
784 /// By default, builds a new AutoType with the given deduced type.
Richard Smitha2c36462013-04-26 16:15:35 +0000785 QualType RebuildAutoType(QualType Deduced, bool IsDecltypeAuto) {
Richard Smithdc7a4f52013-04-30 13:56:41 +0000786 // Note, IsDependent is always false here: we implicitly convert an 'auto'
787 // which has been deduced to a dependent type into an undeduced 'auto', so
788 // that we'll retry deduction after the transformation.
Faisal Valifad9e132013-09-26 19:54:12 +0000789 return SemaRef.Context.getAutoType(Deduced, IsDecltypeAuto,
790 /*IsDependent*/ false);
Richard Smith34b41d92011-02-20 03:19:35 +0000791 }
792
Douglas Gregor577f75a2009-08-04 16:50:30 +0000793 /// \brief Build a new template specialization type.
794 ///
795 /// By default, performs semantic analysis when building the template
796 /// specialization type. Subclasses may override this routine to provide
797 /// different behavior.
798 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall833ca992009-10-29 08:12:44 +0000799 SourceLocation TemplateLoc,
Douglas Gregor67714232011-03-03 02:41:12 +0000800 TemplateArgumentListInfo &Args);
Mike Stump1eb44332009-09-09 15:08:12 +0000801
Abramo Bagnara075f8f12010-12-10 16:29:40 +0000802 /// \brief Build a new parenthesized type.
803 ///
804 /// By default, builds a new ParenType type from the inner type.
805 /// Subclasses may override this routine to provide different behavior.
806 QualType RebuildParenType(QualType InnerType) {
807 return SemaRef.Context.getParenType(InnerType);
808 }
809
Douglas Gregor577f75a2009-08-04 16:50:30 +0000810 /// \brief Build a new qualified name type.
811 ///
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000812 /// By default, builds a new ElaboratedType type from the keyword,
813 /// the nested-name-specifier and the named type.
814 /// Subclasses may override this routine to provide different behavior.
John McCall21e413f2010-11-04 19:04:38 +0000815 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
816 ElaboratedTypeKeyword Keyword,
Douglas Gregor9e876872011-03-01 18:12:44 +0000817 NestedNameSpecifierLoc QualifierLoc,
818 QualType Named) {
Chad Rosier4a9d7952012-08-08 18:46:20 +0000819 return SemaRef.Context.getElaboratedType(Keyword,
820 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor9e876872011-03-01 18:12:44 +0000821 Named);
Mike Stump1eb44332009-09-09 15:08:12 +0000822 }
Douglas Gregor577f75a2009-08-04 16:50:30 +0000823
824 /// \brief Build a new typename type that refers to a template-id.
825 ///
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000826 /// By default, builds a new DependentNameType type from the
827 /// nested-name-specifier and the given type. Subclasses may override
828 /// this routine to provide different behavior.
John McCall33500952010-06-11 00:33:02 +0000829 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000830 ElaboratedTypeKeyword Keyword,
831 NestedNameSpecifierLoc QualifierLoc,
832 const IdentifierInfo *Name,
833 SourceLocation NameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +0000834 TemplateArgumentListInfo &Args) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000835 // Rebuild the template name.
836 // TODO: avoid TemplateName abstraction
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000837 CXXScopeSpec SS;
838 SS.Adopt(QualifierLoc);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000839 TemplateName InstName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000840 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(), 0);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000841
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000842 if (InstName.isNull())
843 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +0000844
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000845 // If it's still dependent, make a dependent specialization.
846 if (InstName.getAsDependentTemplateName())
Chad Rosier4a9d7952012-08-08 18:46:20 +0000847 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
848 QualifierLoc.getNestedNameSpecifier(),
849 Name,
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000850 Args);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000851
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000852 // Otherwise, make an elaborated type wrapping a non-dependent
853 // specialization.
854 QualType T =
855 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
856 if (T.isNull()) return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +0000857
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000858 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == 0)
859 return T;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000860
861 return SemaRef.Context.getElaboratedType(Keyword,
862 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000863 T);
864 }
865
Douglas Gregor577f75a2009-08-04 16:50:30 +0000866 /// \brief Build a new typename type that refers to an identifier.
867 ///
868 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000869 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregor577f75a2009-08-04 16:50:30 +0000870 /// different behavior.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000871 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000872 SourceLocation KeywordLoc,
Douglas Gregor2494dd02011-03-01 01:34:45 +0000873 NestedNameSpecifierLoc QualifierLoc,
874 const IdentifierInfo *Id,
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000875 SourceLocation IdLoc) {
Douglas Gregor40336422010-03-31 22:19:08 +0000876 CXXScopeSpec SS;
Douglas Gregor2494dd02011-03-01 01:34:45 +0000877 SS.Adopt(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000878
Douglas Gregor2494dd02011-03-01 01:34:45 +0000879 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregor40336422010-03-31 22:19:08 +0000880 // If the name is still dependent, just build a new dependent name type.
881 if (!SemaRef.computeDeclContext(SS))
Chad Rosier4a9d7952012-08-08 18:46:20 +0000882 return SemaRef.Context.getDependentNameType(Keyword,
883 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor2494dd02011-03-01 01:34:45 +0000884 Id);
Douglas Gregor40336422010-03-31 22:19:08 +0000885 }
886
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000887 if (Keyword == ETK_None || Keyword == ETK_Typename)
Douglas Gregor2494dd02011-03-01 01:34:45 +0000888 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
Douglas Gregore29425b2011-02-28 22:42:13 +0000889 *Id, IdLoc);
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000890
891 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
892
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000893 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregor40336422010-03-31 22:19:08 +0000894 // into a non-dependent elaborated-type-specifier. Find the tag we're
895 // referring to.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000896 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregor40336422010-03-31 22:19:08 +0000897 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
898 if (!DC)
899 return QualType();
900
John McCall56138762010-05-27 06:40:31 +0000901 if (SemaRef.RequireCompleteDeclContext(SS, DC))
902 return QualType();
903
Douglas Gregor40336422010-03-31 22:19:08 +0000904 TagDecl *Tag = 0;
905 SemaRef.LookupQualifiedName(Result, DC);
906 switch (Result.getResultKind()) {
907 case LookupResult::NotFound:
908 case LookupResult::NotFoundInCurrentInstantiation:
909 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000910
Douglas Gregor40336422010-03-31 22:19:08 +0000911 case LookupResult::Found:
912 Tag = Result.getAsSingle<TagDecl>();
913 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000914
Douglas Gregor40336422010-03-31 22:19:08 +0000915 case LookupResult::FoundOverloaded:
916 case LookupResult::FoundUnresolvedValue:
917 llvm_unreachable("Tag lookup cannot find non-tags");
Chad Rosier4a9d7952012-08-08 18:46:20 +0000918
Douglas Gregor40336422010-03-31 22:19:08 +0000919 case LookupResult::Ambiguous:
920 // Let the LookupResult structure handle ambiguities.
921 return QualType();
922 }
923
924 if (!Tag) {
Nick Lewycky446e4022011-01-24 19:01:04 +0000925 // Check where the name exists but isn't a tag type and use that to emit
926 // better diagnostics.
927 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
928 SemaRef.LookupQualifiedName(Result, DC);
929 switch (Result.getResultKind()) {
930 case LookupResult::Found:
931 case LookupResult::FoundOverloaded:
932 case LookupResult::FoundUnresolvedValue: {
Richard Smith3e4c6c42011-05-05 21:57:07 +0000933 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
Nick Lewycky446e4022011-01-24 19:01:04 +0000934 unsigned Kind = 0;
935 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
Richard Smith162e1c12011-04-15 14:24:37 +0000936 else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2;
937 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3;
Nick Lewycky446e4022011-01-24 19:01:04 +0000938 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
939 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
940 break;
Richard Smith3e4c6c42011-05-05 21:57:07 +0000941 }
Nick Lewycky446e4022011-01-24 19:01:04 +0000942 default:
943 // FIXME: Would be nice to highlight just the source range.
944 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
945 << Kind << Id << DC;
946 break;
947 }
Douglas Gregor40336422010-03-31 22:19:08 +0000948 return QualType();
949 }
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000950
Richard Trieubbf34c02011-06-10 03:11:26 +0000951 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
952 IdLoc, *Id)) {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000953 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregor40336422010-03-31 22:19:08 +0000954 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
955 return QualType();
956 }
957
958 // Build the elaborated-type-specifier type.
959 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000960 return SemaRef.Context.getElaboratedType(Keyword,
961 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor2494dd02011-03-01 01:34:45 +0000962 T);
Douglas Gregordcee1a12009-08-06 05:28:30 +0000963 }
Mike Stump1eb44332009-09-09 15:08:12 +0000964
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000965 /// \brief Build a new pack expansion type.
966 ///
967 /// By default, builds a new PackExpansionType type from the given pattern.
968 /// Subclasses may override this routine to provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +0000969 QualType RebuildPackExpansionType(QualType Pattern,
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000970 SourceRange PatternRange,
Douglas Gregorcded4f62011-01-14 17:04:44 +0000971 SourceLocation EllipsisLoc,
David Blaikiedc84cd52013-02-20 22:23:23 +0000972 Optional<unsigned> NumExpansions) {
Douglas Gregorcded4f62011-01-14 17:04:44 +0000973 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
974 NumExpansions);
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000975 }
976
Eli Friedmanb001de72011-10-06 23:00:33 +0000977 /// \brief Build a new atomic type given its value type.
978 ///
979 /// By default, performs semantic analysis when building the atomic type.
980 /// Subclasses may override this routine to provide different behavior.
981 QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
982
Douglas Gregord1067e52009-08-06 06:41:21 +0000983 /// \brief Build a new template name given a nested name specifier, a flag
984 /// indicating whether the "template" keyword was provided, and the template
985 /// that the template name refers to.
986 ///
987 /// By default, builds the new template name directly. Subclasses may override
988 /// this routine to provide different behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000989 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +0000990 bool TemplateKW,
991 TemplateDecl *Template);
992
Douglas Gregord1067e52009-08-06 06:41:21 +0000993 /// \brief Build a new template name given a nested name specifier and the
994 /// name that is referred to as a template.
995 ///
996 /// By default, performs semantic analysis to determine whether the name can
997 /// be resolved to a specific template, then builds the appropriate kind of
998 /// template name. Subclasses may override this routine to provide different
999 /// behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00001000 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
1001 const IdentifierInfo &Name,
1002 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +00001003 QualType ObjectType,
1004 NamedDecl *FirstQualifierInScope);
Mike Stump1eb44332009-09-09 15:08:12 +00001005
Douglas Gregorca1bdd72009-11-04 00:56:37 +00001006 /// \brief Build a new template name given a nested name specifier and the
1007 /// overloaded operator name that is referred to as a template.
1008 ///
1009 /// By default, performs semantic analysis to determine whether the name can
1010 /// be resolved to a specific template, then builds the appropriate kind of
1011 /// template name. Subclasses may override this routine to provide different
1012 /// behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00001013 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00001014 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00001015 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00001016 QualType ObjectType);
Douglas Gregor1aee05d2011-01-15 06:45:20 +00001017
1018 /// \brief Build a new template name given a template template parameter pack
Chad Rosier4a9d7952012-08-08 18:46:20 +00001019 /// and the
Douglas Gregor1aee05d2011-01-15 06:45:20 +00001020 ///
1021 /// By default, performs semantic analysis to determine whether the name can
1022 /// be resolved to a specific template, then builds the appropriate kind of
1023 /// template name. Subclasses may override this routine to provide different
1024 /// behavior.
1025 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
1026 const TemplateArgument &ArgPack) {
1027 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
1028 }
1029
Douglas Gregor43959a92009-08-20 07:17:43 +00001030 /// \brief Build a new compound statement.
1031 ///
1032 /// By default, performs semantic analysis to build the new statement.
1033 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001034 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001035 MultiStmtArg Statements,
1036 SourceLocation RBraceLoc,
1037 bool IsStmtExpr) {
John McCall9ae2f072010-08-23 23:25:46 +00001038 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregor43959a92009-08-20 07:17:43 +00001039 IsStmtExpr);
1040 }
1041
1042 /// \brief Build a new case statement.
1043 ///
1044 /// By default, performs semantic analysis to build the new statement.
1045 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001046 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001047 Expr *LHS,
Douglas Gregor43959a92009-08-20 07:17:43 +00001048 SourceLocation EllipsisLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001049 Expr *RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +00001050 SourceLocation ColonLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001051 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +00001052 ColonLoc);
1053 }
Mike Stump1eb44332009-09-09 15:08:12 +00001054
Douglas Gregor43959a92009-08-20 07:17:43 +00001055 /// \brief Attach the body to a new case statement.
1056 ///
1057 /// By default, performs semantic analysis to build the new statement.
1058 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001059 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001060 getSema().ActOnCaseStmtBody(S, Body);
1061 return S;
Douglas Gregor43959a92009-08-20 07:17:43 +00001062 }
Mike Stump1eb44332009-09-09 15:08:12 +00001063
Douglas Gregor43959a92009-08-20 07:17:43 +00001064 /// \brief Build a new default statement.
1065 ///
1066 /// By default, performs semantic analysis to build the new statement.
1067 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001068 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001069 SourceLocation ColonLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001070 Stmt *SubStmt) {
1071 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregor43959a92009-08-20 07:17:43 +00001072 /*CurScope=*/0);
1073 }
Mike Stump1eb44332009-09-09 15:08:12 +00001074
Douglas Gregor43959a92009-08-20 07:17:43 +00001075 /// \brief Build a new label statement.
1076 ///
1077 /// By default, performs semantic analysis to build the new statement.
1078 /// Subclasses may override this routine to provide different behavior.
Chris Lattner57ad3782011-02-17 20:34:02 +00001079 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1080 SourceLocation ColonLoc, Stmt *SubStmt) {
1081 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregor43959a92009-08-20 07:17:43 +00001082 }
Mike Stump1eb44332009-09-09 15:08:12 +00001083
Richard Smith534986f2012-04-14 00:33:13 +00001084 /// \brief Build a new label statement.
1085 ///
1086 /// By default, performs semantic analysis to build the new statement.
1087 /// Subclasses may override this routine to provide different behavior.
Alexander Kornienko49908902012-07-09 10:04:07 +00001088 StmtResult RebuildAttributedStmt(SourceLocation AttrLoc,
1089 ArrayRef<const Attr*> Attrs,
Richard Smith534986f2012-04-14 00:33:13 +00001090 Stmt *SubStmt) {
1091 return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt);
1092 }
1093
Douglas Gregor43959a92009-08-20 07:17:43 +00001094 /// \brief Build a new "if" statement.
1095 ///
1096 /// By default, performs semantic analysis to build the new statement.
1097 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001098 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Chad Rosier4a9d7952012-08-08 18:46:20 +00001099 VarDecl *CondVar, Stmt *Then,
Chris Lattner57ad3782011-02-17 20:34:02 +00001100 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00001101 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregor43959a92009-08-20 07:17:43 +00001102 }
Mike Stump1eb44332009-09-09 15:08:12 +00001103
Douglas Gregor43959a92009-08-20 07:17:43 +00001104 /// \brief Start building a new switch statement.
1105 ///
1106 /// By default, performs semantic analysis to build the new statement.
1107 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001108 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Chris Lattner57ad3782011-02-17 20:34:02 +00001109 Expr *Cond, VarDecl *CondVar) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001110 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCalld226f652010-08-21 09:40:31 +00001111 CondVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00001112 }
Mike Stump1eb44332009-09-09 15:08:12 +00001113
Douglas Gregor43959a92009-08-20 07:17:43 +00001114 /// \brief Attach the body to the switch statement.
1115 ///
1116 /// By default, performs semantic analysis to build the new statement.
1117 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001118 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattner57ad3782011-02-17 20:34:02 +00001119 Stmt *Switch, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001120 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001121 }
1122
1123 /// \brief Build a new while statement.
1124 ///
1125 /// By default, performs semantic analysis to build the new statement.
1126 /// Subclasses may override this routine to provide different behavior.
Chris Lattner57ad3782011-02-17 20:34:02 +00001127 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1128 VarDecl *CondVar, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001129 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001130 }
Mike Stump1eb44332009-09-09 15:08:12 +00001131
Douglas Gregor43959a92009-08-20 07:17:43 +00001132 /// \brief Build a new do-while 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 RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001137 SourceLocation WhileLoc, SourceLocation LParenLoc,
1138 Expr *Cond, SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001139 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1140 Cond, RParenLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001141 }
1142
1143 /// \brief Build a new for statement.
1144 ///
1145 /// By default, performs semantic analysis to build the new statement.
1146 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001147 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
Chad Rosier4a9d7952012-08-08 18:46:20 +00001148 Stmt *Init, Sema::FullExprArg Cond,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001149 VarDecl *CondVar, Sema::FullExprArg Inc,
1150 SourceLocation RParenLoc, Stmt *Body) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001151 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001152 CondVar, Inc, RParenLoc, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001153 }
Mike Stump1eb44332009-09-09 15:08:12 +00001154
Douglas Gregor43959a92009-08-20 07:17:43 +00001155 /// \brief Build a new goto statement.
1156 ///
1157 /// By default, performs semantic analysis to build the new statement.
1158 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001159 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1160 LabelDecl *Label) {
Chris Lattner57ad3782011-02-17 20:34:02 +00001161 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregor43959a92009-08-20 07:17:43 +00001162 }
1163
1164 /// \brief Build a new indirect goto statement.
1165 ///
1166 /// By default, performs semantic analysis to build the new statement.
1167 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001168 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001169 SourceLocation StarLoc,
1170 Expr *Target) {
John McCall9ae2f072010-08-23 23:25:46 +00001171 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregor43959a92009-08-20 07:17:43 +00001172 }
Mike Stump1eb44332009-09-09 15:08:12 +00001173
Douglas Gregor43959a92009-08-20 07:17:43 +00001174 /// \brief Build a new return statement.
1175 ///
1176 /// By default, performs semantic analysis to build the new statement.
1177 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001178 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
John McCall9ae2f072010-08-23 23:25:46 +00001179 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregor43959a92009-08-20 07:17:43 +00001180 }
Mike Stump1eb44332009-09-09 15:08:12 +00001181
Douglas Gregor43959a92009-08-20 07:17:43 +00001182 /// \brief Build a new declaration statement.
1183 ///
1184 /// By default, performs semantic analysis to build the new statement.
1185 /// Subclasses may override this routine to provide different behavior.
Rafael Espindola4549d7f2013-07-09 12:05:01 +00001186 StmtResult RebuildDeclStmt(llvm::MutableArrayRef<Decl *> Decls,
1187 SourceLocation StartLoc, SourceLocation EndLoc) {
1188 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls);
Richard Smith406c38e2011-02-23 00:37:57 +00001189 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001190 }
Mike Stump1eb44332009-09-09 15:08:12 +00001191
Anders Carlsson703e3942010-01-24 05:50:09 +00001192 /// \brief Build a new inline asm statement.
1193 ///
1194 /// By default, performs semantic analysis to build the new statement.
1195 /// Subclasses may override this routine to provide different behavior.
Chad Rosierdf5faf52012-08-25 00:11:56 +00001196 StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
1197 bool IsVolatile, unsigned NumOutputs,
1198 unsigned NumInputs, IdentifierInfo **Names,
1199 MultiExprArg Constraints, MultiExprArg Exprs,
1200 Expr *AsmString, MultiExprArg Clobbers,
1201 SourceLocation RParenLoc) {
1202 return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1203 NumInputs, Names, Constraints, Exprs,
1204 AsmString, Clobbers, RParenLoc);
Anders Carlsson703e3942010-01-24 05:50:09 +00001205 }
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001206
Chad Rosier8cd64b42012-06-11 20:47:18 +00001207 /// \brief Build a new MS style inline asm statement.
1208 ///
1209 /// By default, performs semantic analysis to build the new statement.
1210 /// Subclasses may override this routine to provide different behavior.
Chad Rosierdf5faf52012-08-25 00:11:56 +00001211 StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc,
John McCallaeeacf72013-05-03 00:10:13 +00001212 ArrayRef<Token> AsmToks,
1213 StringRef AsmString,
1214 unsigned NumOutputs, unsigned NumInputs,
1215 ArrayRef<StringRef> Constraints,
1216 ArrayRef<StringRef> Clobbers,
1217 ArrayRef<Expr*> Exprs,
1218 SourceLocation EndLoc) {
1219 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString,
1220 NumOutputs, NumInputs,
1221 Constraints, Clobbers, Exprs, EndLoc);
Chad Rosier8cd64b42012-06-11 20:47:18 +00001222 }
1223
James Dennett699c9042012-06-15 07:13:21 +00001224 /// \brief Build a new Objective-C \@try statement.
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001225 ///
1226 /// By default, performs semantic analysis to build the new statement.
1227 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001228 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001229 Stmt *TryBody,
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00001230 MultiStmtArg CatchStmts,
John McCall9ae2f072010-08-23 23:25:46 +00001231 Stmt *Finally) {
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001232 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
John McCall9ae2f072010-08-23 23:25:46 +00001233 Finally);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001234 }
1235
Douglas Gregorbe270a02010-04-26 17:57:08 +00001236 /// \brief Rebuild an Objective-C exception declaration.
1237 ///
1238 /// By default, performs semantic analysis to build the new declaration.
1239 /// Subclasses may override this routine to provide different behavior.
1240 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1241 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001242 return getSema().BuildObjCExceptionDecl(TInfo, T,
1243 ExceptionDecl->getInnerLocStart(),
1244 ExceptionDecl->getLocation(),
1245 ExceptionDecl->getIdentifier());
Douglas Gregorbe270a02010-04-26 17:57:08 +00001246 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001247
James Dennett699c9042012-06-15 07:13:21 +00001248 /// \brief Build a new Objective-C \@catch statement.
Douglas Gregorbe270a02010-04-26 17:57:08 +00001249 ///
1250 /// By default, performs semantic analysis to build the new statement.
1251 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001252 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorbe270a02010-04-26 17:57:08 +00001253 SourceLocation RParenLoc,
1254 VarDecl *Var,
John McCall9ae2f072010-08-23 23:25:46 +00001255 Stmt *Body) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00001256 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001257 Var, Body);
Douglas Gregorbe270a02010-04-26 17:57:08 +00001258 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001259
James Dennett699c9042012-06-15 07:13:21 +00001260 /// \brief Build a new Objective-C \@finally statement.
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001261 ///
1262 /// By default, performs semantic analysis to build the new statement.
1263 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001264 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001265 Stmt *Body) {
1266 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001267 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001268
James Dennett699c9042012-06-15 07:13:21 +00001269 /// \brief Build a new Objective-C \@throw statement.
Douglas Gregord1377b22010-04-22 21:44:01 +00001270 ///
1271 /// By default, performs semantic analysis to build the new statement.
1272 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001273 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001274 Expr *Operand) {
1275 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregord1377b22010-04-22 21:44:01 +00001276 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001277
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00001278 /// \brief Build a new OpenMP parallel directive.
1279 ///
1280 /// By default, performs semantic analysis to build the new statement.
1281 /// Subclasses may override this routine to provide different behavior.
1282 StmtResult RebuildOMPParallelDirective(ArrayRef<OMPClause *> Clauses,
1283 Stmt *AStmt,
1284 SourceLocation StartLoc,
1285 SourceLocation EndLoc) {
1286 return getSema().ActOnOpenMPParallelDirective(Clauses, AStmt,
1287 StartLoc, EndLoc);
1288 }
1289
1290 /// \brief Build a new OpenMP 'default' clause.
1291 ///
1292 /// By default, performs semantic analysis to build the new statement.
1293 /// Subclasses may override this routine to provide different behavior.
1294 OMPClause *RebuildOMPDefaultClause(OpenMPDefaultClauseKind Kind,
1295 SourceLocation KindKwLoc,
1296 SourceLocation StartLoc,
1297 SourceLocation LParenLoc,
1298 SourceLocation EndLoc) {
1299 return getSema().ActOnOpenMPDefaultClause(Kind, KindKwLoc,
1300 StartLoc, LParenLoc, EndLoc);
1301 }
1302
1303 /// \brief Build a new OpenMP 'private' clause.
1304 ///
1305 /// By default, performs semantic analysis to build the new statement.
1306 /// Subclasses may override this routine to provide different behavior.
1307 OMPClause *RebuildOMPPrivateClause(ArrayRef<Expr *> VarList,
1308 SourceLocation StartLoc,
1309 SourceLocation LParenLoc,
1310 SourceLocation EndLoc) {
1311 return getSema().ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc,
1312 EndLoc);
1313 }
1314
Alexey Bataevd195bc32013-10-01 05:32:34 +00001315 /// \brief Build a new OpenMP 'firstprivate' clause.
1316 ///
1317 /// By default, performs semantic analysis to build the new statement.
1318 /// Subclasses may override this routine to provide different behavior.
1319 OMPClause *RebuildOMPFirstprivateClause(ArrayRef<Expr *> VarList,
1320 SourceLocation StartLoc,
1321 SourceLocation LParenLoc,
1322 SourceLocation EndLoc) {
1323 return getSema().ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc,
1324 EndLoc);
1325 }
1326
Alexey Bataev0c018352013-09-06 18:03:48 +00001327 OMPClause *RebuildOMPSharedClause(ArrayRef<Expr *> VarList,
1328 SourceLocation StartLoc,
1329 SourceLocation LParenLoc,
1330 SourceLocation EndLoc) {
1331 return getSema().ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc,
1332 EndLoc);
1333 }
1334
James Dennett699c9042012-06-15 07:13:21 +00001335 /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
John McCall07524032011-07-27 21:50:02 +00001336 ///
1337 /// By default, performs semantic analysis to build the new statement.
1338 /// Subclasses may override this routine to provide different behavior.
1339 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1340 Expr *object) {
1341 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1342 }
1343
James Dennett699c9042012-06-15 07:13:21 +00001344 /// \brief Build a new Objective-C \@synchronized statement.
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001345 ///
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001346 /// By default, performs semantic analysis to build the new statement.
1347 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001348 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCall07524032011-07-27 21:50:02 +00001349 Expr *Object, Stmt *Body) {
1350 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001351 }
Douglas Gregorc3203e72010-04-22 23:10:45 +00001352
James Dennett699c9042012-06-15 07:13:21 +00001353 /// \brief Build a new Objective-C \@autoreleasepool statement.
John McCallf85e1932011-06-15 23:02:42 +00001354 ///
1355 /// By default, performs semantic analysis to build the new statement.
1356 /// Subclasses may override this routine to provide different behavior.
1357 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1358 Stmt *Body) {
1359 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1360 }
John McCall990567c2011-07-27 01:07:15 +00001361
Douglas Gregorc3203e72010-04-22 23:10:45 +00001362 /// \brief Build a new Objective-C fast enumeration statement.
1363 ///
1364 /// By default, performs semantic analysis to build the new statement.
1365 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001366 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001367 Stmt *Element,
1368 Expr *Collection,
1369 SourceLocation RParenLoc,
1370 Stmt *Body) {
Sam Panzerbc20bbb2012-08-16 21:47:25 +00001371 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
Fariborz Jahaniana1eec4b2012-07-03 22:00:52 +00001372 Element,
John McCall9ae2f072010-08-23 23:25:46 +00001373 Collection,
Fariborz Jahaniana1eec4b2012-07-03 22:00:52 +00001374 RParenLoc);
1375 if (ForEachStmt.isInvalid())
1376 return StmtError();
1377
1378 return getSema().FinishObjCForCollectionStmt(ForEachStmt.take(), Body);
Douglas Gregorc3203e72010-04-22 23:10:45 +00001379 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001380
Douglas Gregor43959a92009-08-20 07:17:43 +00001381 /// \brief Build a new C++ exception declaration.
1382 ///
1383 /// By default, performs semantic analysis to build the new decaration.
1384 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001385 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCalla93c9342009-12-07 02:54:59 +00001386 TypeSourceInfo *Declarator,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001387 SourceLocation StartLoc,
1388 SourceLocation IdLoc,
1389 IdentifierInfo *Id) {
Douglas Gregorefdf9882011-04-14 22:32:28 +00001390 VarDecl *Var = getSema().BuildExceptionDeclaration(0, Declarator,
1391 StartLoc, IdLoc, Id);
1392 if (Var)
1393 getSema().CurContext->addDecl(Var);
1394 return Var;
Douglas Gregor43959a92009-08-20 07:17:43 +00001395 }
1396
1397 /// \brief Build a new C++ catch statement.
1398 ///
1399 /// By default, performs semantic analysis to build the new statement.
1400 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001401 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001402 VarDecl *ExceptionDecl,
1403 Stmt *Handler) {
John McCall9ae2f072010-08-23 23:25:46 +00001404 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1405 Handler));
Douglas Gregor43959a92009-08-20 07:17:43 +00001406 }
Mike Stump1eb44332009-09-09 15:08:12 +00001407
Douglas Gregor43959a92009-08-20 07:17:43 +00001408 /// \brief Build a new C++ try statement.
1409 ///
1410 /// By default, performs semantic analysis to build the new statement.
1411 /// Subclasses may override this routine to provide different behavior.
Robert Wilhelm21adb0c2013-08-22 09:20:03 +00001412 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock,
1413 ArrayRef<Stmt *> Handlers) {
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001414 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
Douglas Gregor43959a92009-08-20 07:17:43 +00001415 }
Mike Stump1eb44332009-09-09 15:08:12 +00001416
Richard Smithad762fc2011-04-14 22:09:26 +00001417 /// \brief Build a new C++0x range-based for statement.
1418 ///
1419 /// By default, performs semantic analysis to build the new statement.
1420 /// Subclasses may override this routine to provide different behavior.
1421 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1422 SourceLocation ColonLoc,
1423 Stmt *Range, Stmt *BeginEnd,
1424 Expr *Cond, Expr *Inc,
1425 Stmt *LoopVar,
1426 SourceLocation RParenLoc) {
Douglas Gregor6f96f4b2013-04-08 18:40:13 +00001427 // If we've just learned that the range is actually an Objective-C
1428 // collection, treat this as an Objective-C fast enumeration loop.
1429 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
1430 if (RangeStmt->isSingleDecl()) {
1431 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
Douglas Gregor39b60dc2013-05-02 18:35:56 +00001432 if (RangeVar->isInvalidDecl())
1433 return StmtError();
1434
Douglas Gregor6f96f4b2013-04-08 18:40:13 +00001435 Expr *RangeExpr = RangeVar->getInit();
1436 if (!RangeExpr->isTypeDependent() &&
1437 RangeExpr->getType()->isObjCObjectPointerType())
1438 return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, RangeExpr,
1439 RParenLoc);
1440 }
1441 }
1442 }
1443
Richard Smithad762fc2011-04-14 22:09:26 +00001444 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
Richard Smith8b533d92012-09-20 21:52:32 +00001445 Cond, Inc, LoopVar, RParenLoc,
1446 Sema::BFRK_Rebuild);
Richard Smithad762fc2011-04-14 22:09:26 +00001447 }
Douglas Gregorba0513d2011-10-25 01:33:02 +00001448
1449 /// \brief Build a new C++0x range-based for statement.
1450 ///
1451 /// By default, performs semantic analysis to build the new statement.
1452 /// Subclasses may override this routine to provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +00001453 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
Douglas Gregorba0513d2011-10-25 01:33:02 +00001454 bool IsIfExists,
1455 NestedNameSpecifierLoc QualifierLoc,
1456 DeclarationNameInfo NameInfo,
1457 Stmt *Nested) {
1458 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1459 QualifierLoc, NameInfo, Nested);
1460 }
1461
Richard Smithad762fc2011-04-14 22:09:26 +00001462 /// \brief Attach body to a C++0x range-based for statement.
1463 ///
1464 /// By default, performs semantic analysis to finish the new statement.
1465 /// Subclasses may override this routine to provide different behavior.
1466 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1467 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1468 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001469
David Majnemerfc210492013-10-15 09:33:02 +00001470 StmtResult RebuildSEHTryStmt(bool IsCXXTry, SourceLocation TryLoc,
1471 Stmt *TryBlock, Stmt *Handler) {
1472 return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler);
John Wiegley28bbe4b2011-04-28 01:08:34 +00001473 }
1474
David Majnemerfc210492013-10-15 09:33:02 +00001475 StmtResult RebuildSEHExceptStmt(SourceLocation Loc, Expr *FilterExpr,
John Wiegley28bbe4b2011-04-28 01:08:34 +00001476 Stmt *Block) {
David Majnemerfc210492013-10-15 09:33:02 +00001477 return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block);
John Wiegley28bbe4b2011-04-28 01:08:34 +00001478 }
1479
David Majnemerfc210492013-10-15 09:33:02 +00001480 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, Stmt *Block) {
1481 return getSema().ActOnSEHFinallyBlock(Loc, Block);
John Wiegley28bbe4b2011-04-28 01:08:34 +00001482 }
1483
Douglas Gregorb98b1992009-08-11 05:31:07 +00001484 /// \brief Build a new expression that references a declaration.
1485 ///
1486 /// By default, performs semantic analysis to build the new expression.
1487 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001488 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallf312b1e2010-08-26 23:41:50 +00001489 LookupResult &R,
1490 bool RequiresADL) {
John McCallf7a1a742009-11-24 19:00:30 +00001491 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1492 }
1493
1494
1495 /// \brief Build a new expression that references a declaration.
1496 ///
1497 /// By default, performs semantic analysis to build the new expression.
1498 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001499 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001500 ValueDecl *VD,
1501 const DeclarationNameInfo &NameInfo,
1502 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00001503 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001504 SS.Adopt(QualifierLoc);
John McCalldbd872f2009-12-08 09:08:17 +00001505
1506 // FIXME: loses template args.
Abramo Bagnara25777432010-08-11 22:01:17 +00001507
1508 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001509 }
Mike Stump1eb44332009-09-09 15:08:12 +00001510
Douglas Gregorb98b1992009-08-11 05:31:07 +00001511 /// \brief Build a new expression in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001512 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001513 /// By default, performs semantic analysis to build the new expression.
1514 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001515 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001516 SourceLocation RParen) {
John McCall9ae2f072010-08-23 23:25:46 +00001517 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001518 }
1519
Douglas Gregora71d8192009-09-04 17:36:40 +00001520 /// \brief Build a new pseudo-destructor expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001521 ///
Douglas Gregora71d8192009-09-04 17:36:40 +00001522 /// By default, performs semantic analysis to build the new expression.
1523 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001524 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00001525 SourceLocation OperatorLoc,
1526 bool isArrow,
1527 CXXScopeSpec &SS,
1528 TypeSourceInfo *ScopeType,
1529 SourceLocation CCLoc,
1530 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00001531 PseudoDestructorTypeStorage Destroyed);
Mike Stump1eb44332009-09-09 15:08:12 +00001532
Douglas Gregorb98b1992009-08-11 05:31:07 +00001533 /// \brief Build a new unary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001534 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001535 /// By default, performs semantic analysis to build the new expression.
1536 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001537 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001538 UnaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001539 Expr *SubExpr) {
1540 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001541 }
Mike Stump1eb44332009-09-09 15:08:12 +00001542
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001543 /// \brief Build a new builtin offsetof expression.
1544 ///
1545 /// By default, performs semantic analysis to build the new expression.
1546 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001547 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001548 TypeSourceInfo *Type,
John McCallf312b1e2010-08-26 23:41:50 +00001549 Sema::OffsetOfComponent *Components,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001550 unsigned NumComponents,
1551 SourceLocation RParenLoc) {
1552 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1553 NumComponents, RParenLoc);
1554 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001555
1556 /// \brief Build a new sizeof, alignof or vec_step expression with a
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001557 /// type argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001558 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001559 /// By default, performs semantic analysis to build the new expression.
1560 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001561 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1562 SourceLocation OpLoc,
1563 UnaryExprOrTypeTrait ExprKind,
1564 SourceRange R) {
1565 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001566 }
1567
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001568 /// \brief Build a new sizeof, alignof or vec step expression with an
1569 /// expression argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001570 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001571 /// By default, performs semantic analysis to build the new expression.
1572 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001573 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1574 UnaryExprOrTypeTrait ExprKind,
1575 SourceRange R) {
John McCall60d7b3a2010-08-24 06:29:42 +00001576 ExprResult Result
Chandler Carruthe72c55b2011-05-29 07:32:14 +00001577 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001578 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001579 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001580
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001581 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00001582 }
Mike Stump1eb44332009-09-09 15:08:12 +00001583
Douglas Gregorb98b1992009-08-11 05:31:07 +00001584 /// \brief Build a new array subscript expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001585 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001586 /// By default, performs semantic analysis to build the new expression.
1587 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001588 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001589 SourceLocation LBracketLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001590 Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001591 SourceLocation RBracketLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001592 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1593 LBracketLoc, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001594 RBracketLoc);
1595 }
1596
1597 /// \brief Build a new call expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001598 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001599 /// By default, performs semantic analysis to build the new expression.
1600 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001601 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001602 MultiExprArg Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00001603 SourceLocation RParenLoc,
1604 Expr *ExecConfig = 0) {
John McCall9ae2f072010-08-23 23:25:46 +00001605 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001606 Args, RParenLoc, ExecConfig);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001607 }
1608
1609 /// \brief Build a new member access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001610 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001611 /// By default, performs semantic analysis to build the new expression.
1612 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001613 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001614 bool isArrow,
Douglas Gregor40d96a62011-02-28 21:54:11 +00001615 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001616 SourceLocation TemplateKWLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001617 const DeclarationNameInfo &MemberNameInfo,
1618 ValueDecl *Member,
1619 NamedDecl *FoundDecl,
John McCalld5532b62009-11-23 01:53:49 +00001620 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCallf89e55a2010-11-18 06:31:45 +00001621 NamedDecl *FirstQualifierInScope) {
Richard Smith9138b4e2011-10-26 19:06:56 +00001622 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
1623 isArrow);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001624 if (!Member->getDeclName()) {
John McCallf89e55a2010-11-18 06:31:45 +00001625 // We have a reference to an unnamed field. This is always the
1626 // base of an anonymous struct/union member access, i.e. the
1627 // field is always of record type.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001628 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCallf89e55a2010-11-18 06:31:45 +00001629 assert(Member->getType()->isRecordType() &&
1630 "unnamed member not of record type?");
Mike Stump1eb44332009-09-09 15:08:12 +00001631
Richard Smith9138b4e2011-10-26 19:06:56 +00001632 BaseResult =
1633 getSema().PerformObjectMemberConversion(BaseResult.take(),
John Wiegley429bb272011-04-08 18:41:53 +00001634 QualifierLoc.getNestedNameSpecifier(),
1635 FoundDecl, Member);
1636 if (BaseResult.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001637 return ExprError();
John Wiegley429bb272011-04-08 18:41:53 +00001638 Base = BaseResult.take();
John McCallf89e55a2010-11-18 06:31:45 +00001639 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump1eb44332009-09-09 15:08:12 +00001640 MemberExpr *ME =
John McCall9ae2f072010-08-23 23:25:46 +00001641 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnara25777432010-08-11 22:01:17 +00001642 Member, MemberNameInfo,
John McCallf89e55a2010-11-18 06:31:45 +00001643 cast<FieldDecl>(Member)->getType(),
1644 VK, OK_Ordinary);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001645 return getSema().Owned(ME);
1646 }
Mike Stump1eb44332009-09-09 15:08:12 +00001647
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001648 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001649 SS.Adopt(QualifierLoc);
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001650
John Wiegley429bb272011-04-08 18:41:53 +00001651 Base = BaseResult.take();
John McCall9ae2f072010-08-23 23:25:46 +00001652 QualType BaseType = Base->getType();
John McCallaa81e162009-12-01 22:10:20 +00001653
John McCall6bb80172010-03-30 21:47:33 +00001654 // FIXME: this involves duplicating earlier analysis in a lot of
1655 // cases; we should avoid this when possible.
Abramo Bagnara25777432010-08-11 22:01:17 +00001656 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall6bb80172010-03-30 21:47:33 +00001657 R.addDecl(FoundDecl);
John McCallc2233c52010-01-15 08:34:02 +00001658 R.resolveKind();
1659
John McCall9ae2f072010-08-23 23:25:46 +00001660 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001661 SS, TemplateKWLoc,
1662 FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00001663 R, ExplicitTemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001664 }
Mike Stump1eb44332009-09-09 15:08:12 +00001665
Douglas Gregorb98b1992009-08-11 05:31:07 +00001666 /// \brief Build a new binary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001667 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001668 /// By default, performs semantic analysis to build the new expression.
1669 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001670 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001671 BinaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001672 Expr *LHS, Expr *RHS) {
1673 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001674 }
1675
1676 /// \brief Build a new conditional operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001677 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001678 /// By default, performs semantic analysis to build the new expression.
1679 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001680 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCall56ca35d2011-02-17 10:25:35 +00001681 SourceLocation QuestionLoc,
1682 Expr *LHS,
1683 SourceLocation ColonLoc,
1684 Expr *RHS) {
John McCall9ae2f072010-08-23 23:25:46 +00001685 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1686 LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001687 }
1688
Douglas Gregorb98b1992009-08-11 05:31:07 +00001689 /// \brief Build a new C-style cast expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001690 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001691 /// By default, performs semantic analysis to build the new expression.
1692 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001693 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall9d125032010-01-15 18:39:57 +00001694 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001695 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001696 Expr *SubExpr) {
John McCallb042fdf2010-01-15 18:56:44 +00001697 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001698 SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001699 }
Mike Stump1eb44332009-09-09 15:08:12 +00001700
Douglas Gregorb98b1992009-08-11 05:31:07 +00001701 /// \brief Build a new compound literal expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001702 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001703 /// By default, performs semantic analysis to build the new expression.
1704 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001705 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCall42f56b52010-01-18 19:35:47 +00001706 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001707 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001708 Expr *Init) {
John McCall42f56b52010-01-18 19:35:47 +00001709 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001710 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001711 }
Mike Stump1eb44332009-09-09 15:08:12 +00001712
Douglas Gregorb98b1992009-08-11 05:31:07 +00001713 /// \brief Build a new extended vector element access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001714 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001715 /// By default, performs semantic analysis to build the new expression.
1716 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001717 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001718 SourceLocation OpLoc,
1719 SourceLocation AccessorLoc,
1720 IdentifierInfo &Accessor) {
John McCallaa81e162009-12-01 22:10:20 +00001721
John McCall129e2df2009-11-30 22:42:35 +00001722 CXXScopeSpec SS;
Abramo Bagnara25777432010-08-11 22:01:17 +00001723 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCall9ae2f072010-08-23 23:25:46 +00001724 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall129e2df2009-11-30 22:42:35 +00001725 OpLoc, /*IsArrow*/ false,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001726 SS, SourceLocation(),
1727 /*FirstQualifierInScope*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00001728 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00001729 /* TemplateArgs */ 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001730 }
Mike Stump1eb44332009-09-09 15:08:12 +00001731
Douglas Gregorb98b1992009-08-11 05:31:07 +00001732 /// \brief Build a new initializer list expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001733 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001734 /// By default, performs semantic analysis to build the new expression.
1735 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001736 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCallc8fc90a2011-07-06 07:30:07 +00001737 MultiExprArg Inits,
1738 SourceLocation RBraceLoc,
1739 QualType ResultTy) {
John McCall60d7b3a2010-08-24 06:29:42 +00001740 ExprResult Result
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001741 = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
Douglas Gregore48319a2009-11-09 17:16:50 +00001742 if (Result.isInvalid() || ResultTy->isDependentType())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001743 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00001744
Douglas Gregore48319a2009-11-09 17:16:50 +00001745 // Patch in the result type we were given, which may have been computed
1746 // when the initial InitListExpr was built.
1747 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1748 ILE->setType(ResultTy);
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001749 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00001750 }
Mike Stump1eb44332009-09-09 15:08:12 +00001751
Douglas Gregorb98b1992009-08-11 05:31:07 +00001752 /// \brief Build a new designated initializer expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001753 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001754 /// By default, performs semantic analysis to build the new expression.
1755 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001756 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001757 MultiExprArg ArrayExprs,
1758 SourceLocation EqualOrColonLoc,
1759 bool GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001760 Expr *Init) {
John McCall60d7b3a2010-08-24 06:29:42 +00001761 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00001762 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001763 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001764 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001765 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001766
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001767 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00001768 }
Mike Stump1eb44332009-09-09 15:08:12 +00001769
Douglas Gregorb98b1992009-08-11 05:31:07 +00001770 /// \brief Build a new value-initialized expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001771 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001772 /// By default, builds the implicit value initialization without performing
1773 /// any semantic analysis. Subclasses may override this routine to provide
1774 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001775 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001776 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1777 }
Mike Stump1eb44332009-09-09 15:08:12 +00001778
Douglas Gregorb98b1992009-08-11 05:31:07 +00001779 /// \brief Build a new \c va_arg expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001780 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001781 /// By default, performs semantic analysis to build the new expression.
1782 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001783 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001784 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001785 SourceLocation RParenLoc) {
1786 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001787 SubExpr, TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001788 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001789 }
1790
1791 /// \brief Build a new expression list in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001792 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001793 /// By default, performs semantic analysis to build the new expression.
1794 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001795 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redl5b9cc5d2012-02-11 23:51:47 +00001796 MultiExprArg SubExprs,
1797 SourceLocation RParenLoc) {
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001798 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001799 }
Mike Stump1eb44332009-09-09 15:08:12 +00001800
Douglas Gregorb98b1992009-08-11 05:31:07 +00001801 /// \brief Build a new address-of-label expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001802 ///
1803 /// By default, performs semantic analysis, using the name of the label
Douglas Gregorb98b1992009-08-11 05:31:07 +00001804 /// rather than attempting to map the label statement itself.
1805 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001806 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001807 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattner57ad3782011-02-17 20:34:02 +00001808 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001809 }
Mike Stump1eb44332009-09-09 15:08:12 +00001810
Douglas Gregorb98b1992009-08-11 05:31:07 +00001811 /// \brief Build a new GNU statement expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001812 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001813 /// By default, performs semantic analysis to build the new expression.
1814 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001815 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001816 Stmt *SubStmt,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001817 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001818 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001819 }
Mike Stump1eb44332009-09-09 15:08:12 +00001820
Douglas Gregorb98b1992009-08-11 05:31:07 +00001821 /// \brief Build a new __builtin_choose_expr expression.
1822 ///
1823 /// By default, performs semantic analysis to build the new expression.
1824 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001825 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001826 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001827 SourceLocation RParenLoc) {
1828 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001829 Cond, LHS, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001830 RParenLoc);
1831 }
Mike Stump1eb44332009-09-09 15:08:12 +00001832
Peter Collingbournef111d932011-04-15 00:35:48 +00001833 /// \brief Build a new generic selection expression.
1834 ///
1835 /// By default, performs semantic analysis to build the new expression.
1836 /// Subclasses may override this routine to provide different behavior.
1837 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
1838 SourceLocation DefaultLoc,
1839 SourceLocation RParenLoc,
1840 Expr *ControllingExpr,
Dmitri Gribenko80613222013-05-10 13:06:58 +00001841 ArrayRef<TypeSourceInfo *> Types,
1842 ArrayRef<Expr *> Exprs) {
Peter Collingbournef111d932011-04-15 00:35:48 +00001843 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
Dmitri Gribenko80613222013-05-10 13:06:58 +00001844 ControllingExpr, Types, Exprs);
Peter Collingbournef111d932011-04-15 00:35:48 +00001845 }
1846
Douglas Gregorb98b1992009-08-11 05:31:07 +00001847 /// \brief Build a new overloaded operator call expression.
1848 ///
1849 /// By default, performs semantic analysis to build the new expression.
1850 /// The semantic analysis provides the behavior of template instantiation,
1851 /// copying with transformations that turn what looks like an overloaded
Mike Stump1eb44332009-09-09 15:08:12 +00001852 /// operator call into a use of a builtin operator, performing
Douglas Gregorb98b1992009-08-11 05:31:07 +00001853 /// argument-dependent lookup, etc. Subclasses may override this routine to
1854 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001855 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001856 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001857 Expr *Callee,
1858 Expr *First,
1859 Expr *Second);
Mike Stump1eb44332009-09-09 15:08:12 +00001860
1861 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregorb98b1992009-08-11 05:31:07 +00001862 /// reinterpret_cast.
1863 ///
1864 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump1eb44332009-09-09 15:08:12 +00001865 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregorb98b1992009-08-11 05:31:07 +00001866 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001867 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001868 Stmt::StmtClass Class,
1869 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001870 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001871 SourceLocation RAngleLoc,
1872 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001873 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001874 SourceLocation RParenLoc) {
1875 switch (Class) {
1876 case Stmt::CXXStaticCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001877 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001878 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001879 SubExpr, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001880
1881 case Stmt::CXXDynamicCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001882 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001883 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001884 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001885
Douglas Gregorb98b1992009-08-11 05:31:07 +00001886 case Stmt::CXXReinterpretCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001887 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001888 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001889 SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001890 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001891
Douglas Gregorb98b1992009-08-11 05:31:07 +00001892 case Stmt::CXXConstCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001893 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001894 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001895 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001896
Douglas Gregorb98b1992009-08-11 05:31:07 +00001897 default:
David Blaikieb219cfc2011-09-23 05:06:16 +00001898 llvm_unreachable("Invalid C++ named cast");
Douglas Gregorb98b1992009-08-11 05:31:07 +00001899 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00001900 }
Mike Stump1eb44332009-09-09 15:08:12 +00001901
Douglas Gregorb98b1992009-08-11 05:31:07 +00001902 /// \brief Build a new C++ static_cast expression.
1903 ///
1904 /// By default, performs semantic analysis to build the new expression.
1905 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001906 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001907 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001908 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001909 SourceLocation RAngleLoc,
1910 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001911 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001912 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001913 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001914 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001915 SourceRange(LAngleLoc, RAngleLoc),
1916 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001917 }
1918
1919 /// \brief Build a new C++ dynamic_cast expression.
1920 ///
1921 /// By default, performs semantic analysis to build the new expression.
1922 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001923 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001924 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001925 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001926 SourceLocation RAngleLoc,
1927 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001928 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001929 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001930 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001931 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001932 SourceRange(LAngleLoc, RAngleLoc),
1933 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001934 }
1935
1936 /// \brief Build a new C++ reinterpret_cast expression.
1937 ///
1938 /// By default, performs semantic analysis to build the new expression.
1939 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001940 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001941 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001942 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001943 SourceLocation RAngleLoc,
1944 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001945 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001946 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001947 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001948 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001949 SourceRange(LAngleLoc, RAngleLoc),
1950 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001951 }
1952
1953 /// \brief Build a new C++ const_cast expression.
1954 ///
1955 /// By default, performs semantic analysis to build the new expression.
1956 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001957 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001958 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001959 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001960 SourceLocation RAngleLoc,
1961 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001962 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001963 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001964 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001965 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001966 SourceRange(LAngleLoc, RAngleLoc),
1967 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001968 }
Mike Stump1eb44332009-09-09 15:08:12 +00001969
Douglas Gregorb98b1992009-08-11 05:31:07 +00001970 /// \brief Build a new C++ functional-style cast expression.
1971 ///
1972 /// By default, performs semantic analysis to build the new expression.
1973 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001974 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1975 SourceLocation LParenLoc,
1976 Expr *Sub,
1977 SourceLocation RParenLoc) {
1978 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001979 MultiExprArg(&Sub, 1),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001980 RParenLoc);
1981 }
Mike Stump1eb44332009-09-09 15:08:12 +00001982
Douglas Gregorb98b1992009-08-11 05:31:07 +00001983 /// \brief Build a new C++ typeid(type) expression.
1984 ///
1985 /// By default, performs semantic analysis to build the new expression.
1986 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001987 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001988 SourceLocation TypeidLoc,
1989 TypeSourceInfo *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001990 SourceLocation RParenLoc) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001991 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001992 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001993 }
Mike Stump1eb44332009-09-09 15:08:12 +00001994
Francois Pichet01b7c302010-09-08 12:20:18 +00001995
Douglas Gregorb98b1992009-08-11 05:31:07 +00001996 /// \brief Build a new C++ typeid(expr) expression.
1997 ///
1998 /// By default, performs semantic analysis to build the new expression.
1999 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002000 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00002001 SourceLocation TypeidLoc,
John McCall9ae2f072010-08-23 23:25:46 +00002002 Expr *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002003 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00002004 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00002005 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002006 }
2007
Francois Pichet01b7c302010-09-08 12:20:18 +00002008 /// \brief Build a new C++ __uuidof(type) expression.
2009 ///
2010 /// By default, performs semantic analysis to build the new expression.
2011 /// Subclasses may override this routine to provide different behavior.
2012 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2013 SourceLocation TypeidLoc,
2014 TypeSourceInfo *Operand,
2015 SourceLocation RParenLoc) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002016 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
Francois Pichet01b7c302010-09-08 12:20:18 +00002017 RParenLoc);
2018 }
2019
2020 /// \brief Build a new C++ __uuidof(expr) expression.
2021 ///
2022 /// By default, performs semantic analysis to build the new expression.
2023 /// Subclasses may override this routine to provide different behavior.
2024 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2025 SourceLocation TypeidLoc,
2026 Expr *Operand,
2027 SourceLocation RParenLoc) {
2028 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
2029 RParenLoc);
2030 }
2031
Douglas Gregorb98b1992009-08-11 05:31:07 +00002032 /// \brief Build a new C++ "this" expression.
2033 ///
2034 /// By default, builds a new "this" expression without performing any
Mike Stump1eb44332009-09-09 15:08:12 +00002035 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregorb98b1992009-08-11 05:31:07 +00002036 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002037 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00002038 QualType ThisType,
2039 bool isImplicit) {
Eli Friedmanb69b42c2012-01-11 02:36:31 +00002040 getSema().CheckCXXThisCapture(ThisLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002041 return getSema().Owned(
Douglas Gregor828a1972010-01-07 23:12:05 +00002042 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
2043 isImplicit));
Douglas Gregorb98b1992009-08-11 05:31:07 +00002044 }
2045
2046 /// \brief Build a new C++ throw expression.
2047 ///
2048 /// By default, performs semantic analysis to build the new expression.
2049 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorbca01b42011-07-06 22:04:06 +00002050 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
2051 bool IsThrownVariableInScope) {
2052 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002053 }
2054
2055 /// \brief Build a new C++ default-argument expression.
2056 ///
2057 /// By default, builds a new default-argument expression, which does not
2058 /// require any semantic analysis. Subclasses may override this routine to
2059 /// provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002060 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor036aed12009-12-23 23:03:06 +00002061 ParmVarDecl *Param) {
2062 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
2063 Param));
Douglas Gregorb98b1992009-08-11 05:31:07 +00002064 }
2065
Richard Smithc3bf52c2013-04-20 22:23:05 +00002066 /// \brief Build a new C++11 default-initialization expression.
2067 ///
2068 /// By default, builds a new default field initialization expression, which
2069 /// does not require any semantic analysis. Subclasses may override this
2070 /// routine to provide different behavior.
2071 ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc,
2072 FieldDecl *Field) {
2073 return getSema().Owned(CXXDefaultInitExpr::Create(getSema().Context, Loc,
2074 Field));
2075 }
2076
Douglas Gregorb98b1992009-08-11 05:31:07 +00002077 /// \brief Build a new C++ zero-initialization expression.
2078 ///
2079 /// By default, performs semantic analysis to build the new expression.
2080 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002081 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
2082 SourceLocation LParenLoc,
2083 SourceLocation RParenLoc) {
2084 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Dmitri Gribenko62ed8892013-05-05 20:40:26 +00002085 None, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002086 }
Mike Stump1eb44332009-09-09 15:08:12 +00002087
Douglas Gregorb98b1992009-08-11 05:31:07 +00002088 /// \brief Build a new C++ "new" expression.
2089 ///
2090 /// By default, performs semantic analysis to build the new expression.
2091 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002092 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00002093 bool UseGlobal,
2094 SourceLocation PlacementLParen,
2095 MultiExprArg PlacementArgs,
2096 SourceLocation PlacementRParen,
2097 SourceRange TypeIdParens,
2098 QualType AllocatedType,
2099 TypeSourceInfo *AllocatedTypeInfo,
2100 Expr *ArraySize,
Sebastian Redl2aed8b82012-02-16 12:22:20 +00002101 SourceRange DirectInitRange,
2102 Expr *Initializer) {
Mike Stump1eb44332009-09-09 15:08:12 +00002103 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002104 PlacementLParen,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002105 PlacementArgs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002106 PlacementRParen,
Douglas Gregor4bd40312010-07-13 15:54:32 +00002107 TypeIdParens,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00002108 AllocatedType,
2109 AllocatedTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00002110 ArraySize,
Sebastian Redl2aed8b82012-02-16 12:22:20 +00002111 DirectInitRange,
2112 Initializer);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002113 }
Mike Stump1eb44332009-09-09 15:08:12 +00002114
Douglas Gregorb98b1992009-08-11 05:31:07 +00002115 /// \brief Build a new C++ "delete" expression.
2116 ///
2117 /// By default, performs semantic analysis to build the new expression.
2118 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002119 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002120 bool IsGlobalDelete,
2121 bool IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00002122 Expr *Operand) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002123 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00002124 Operand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002125 }
Mike Stump1eb44332009-09-09 15:08:12 +00002126
Douglas Gregorb98b1992009-08-11 05:31:07 +00002127 /// \brief Build a new unary type trait expression.
2128 ///
2129 /// By default, performs semantic analysis to build the new expression.
2130 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002131 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00002132 SourceLocation StartLoc,
2133 TypeSourceInfo *T,
2134 SourceLocation RParenLoc) {
2135 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002136 }
2137
Francois Pichet6ad6f282010-12-07 00:08:36 +00002138 /// \brief Build a new binary type trait expression.
2139 ///
2140 /// By default, performs semantic analysis to build the new expression.
2141 /// Subclasses may override this routine to provide different behavior.
2142 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
2143 SourceLocation StartLoc,
2144 TypeSourceInfo *LhsT,
2145 TypeSourceInfo *RhsT,
2146 SourceLocation RParenLoc) {
2147 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
2148 }
2149
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00002150 /// \brief Build a new type trait expression.
2151 ///
2152 /// By default, performs semantic analysis to build the new expression.
2153 /// Subclasses may override this routine to provide different behavior.
2154 ExprResult RebuildTypeTrait(TypeTrait Trait,
2155 SourceLocation StartLoc,
2156 ArrayRef<TypeSourceInfo *> Args,
2157 SourceLocation RParenLoc) {
2158 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2159 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002160
John Wiegley21ff2e52011-04-28 00:16:57 +00002161 /// \brief Build a new array type trait expression.
2162 ///
2163 /// By default, performs semantic analysis to build the new expression.
2164 /// Subclasses may override this routine to provide different behavior.
2165 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2166 SourceLocation StartLoc,
2167 TypeSourceInfo *TSInfo,
2168 Expr *DimExpr,
2169 SourceLocation RParenLoc) {
2170 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2171 }
2172
John Wiegley55262202011-04-25 06:54:41 +00002173 /// \brief Build a new expression trait expression.
2174 ///
2175 /// By default, performs semantic analysis to build the new expression.
2176 /// Subclasses may override this routine to provide different behavior.
2177 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2178 SourceLocation StartLoc,
2179 Expr *Queried,
2180 SourceLocation RParenLoc) {
2181 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2182 }
2183
Mike Stump1eb44332009-09-09 15:08:12 +00002184 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregorb98b1992009-08-11 05:31:07 +00002185 /// expression.
2186 ///
2187 /// By default, performs semantic analysis to build the new expression.
2188 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00002189 ExprResult RebuildDependentScopeDeclRefExpr(
2190 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002191 SourceLocation TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00002192 const DeclarationNameInfo &NameInfo,
Richard Smithefeeccf2012-10-21 03:28:35 +00002193 const TemplateArgumentListInfo *TemplateArgs,
2194 bool IsAddressOfOperand) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002195 CXXScopeSpec SS;
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00002196 SS.Adopt(QualifierLoc);
John McCallf7a1a742009-11-24 19:00:30 +00002197
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002198 if (TemplateArgs || TemplateKWLoc.isValid())
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002199 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002200 NameInfo, TemplateArgs);
John McCallf7a1a742009-11-24 19:00:30 +00002201
Richard Smithefeeccf2012-10-21 03:28:35 +00002202 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo,
2203 IsAddressOfOperand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002204 }
2205
2206 /// \brief Build a new template-id expression.
2207 ///
2208 /// By default, performs semantic analysis to build the new expression.
2209 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002210 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002211 SourceLocation TemplateKWLoc,
2212 LookupResult &R,
2213 bool RequiresADL,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002214 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002215 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2216 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002217 }
2218
2219 /// \brief Build a new object-construction expression.
2220 ///
2221 /// By default, performs semantic analysis to build the new expression.
2222 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002223 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002224 SourceLocation Loc,
2225 CXXConstructorDecl *Constructor,
2226 bool IsElidable,
2227 MultiExprArg Args,
2228 bool HadMultipleCandidates,
Richard Smithc83c2302012-12-19 01:39:02 +00002229 bool ListInitialization,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002230 bool RequiresZeroInit,
Chandler Carruth428edaf2010-10-25 08:47:36 +00002231 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002232 SourceRange ParenRange) {
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00002233 SmallVector<Expr*, 8> ConvertedArgs;
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002234 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002235 ConvertedArgs))
John McCallf312b1e2010-08-26 23:41:50 +00002236 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002237
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002238 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002239 ConvertedArgs,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002240 HadMultipleCandidates,
Richard Smithc83c2302012-12-19 01:39:02 +00002241 ListInitialization,
Chandler Carruth428edaf2010-10-25 08:47:36 +00002242 RequiresZeroInit, ConstructKind,
2243 ParenRange);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002244 }
2245
2246 /// \brief Build a new object-construction expression.
2247 ///
2248 /// By default, performs semantic analysis to build the new expression.
2249 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002250 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2251 SourceLocation LParenLoc,
2252 MultiExprArg Args,
2253 SourceLocation RParenLoc) {
2254 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002255 LParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002256 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002257 RParenLoc);
2258 }
2259
2260 /// \brief Build a new object-construction expression.
2261 ///
2262 /// By default, performs semantic analysis to build the new expression.
2263 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002264 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2265 SourceLocation LParenLoc,
2266 MultiExprArg Args,
2267 SourceLocation RParenLoc) {
2268 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002269 LParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002270 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002271 RParenLoc);
2272 }
Mike Stump1eb44332009-09-09 15:08:12 +00002273
Douglas Gregorb98b1992009-08-11 05:31:07 +00002274 /// \brief Build a new member reference expression.
2275 ///
2276 /// By default, performs semantic analysis to build the new expression.
2277 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002278 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002279 QualType BaseType,
2280 bool IsArrow,
2281 SourceLocation OperatorLoc,
2282 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002283 SourceLocation TemplateKWLoc,
John McCall129e2df2009-11-30 22:42:35 +00002284 NamedDecl *FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002285 const DeclarationNameInfo &MemberNameInfo,
John McCall129e2df2009-11-30 22:42:35 +00002286 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002287 CXXScopeSpec SS;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002288 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002289
John McCall9ae2f072010-08-23 23:25:46 +00002290 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002291 OperatorLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002292 SS, TemplateKWLoc,
2293 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002294 MemberNameInfo,
2295 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002296 }
2297
John McCall129e2df2009-11-30 22:42:35 +00002298 /// \brief Build a new member reference expression.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002299 ///
2300 /// By default, performs semantic analysis to build the new expression.
2301 /// Subclasses may override this routine to provide different behavior.
Richard Smith9138b4e2011-10-26 19:06:56 +00002302 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2303 SourceLocation OperatorLoc,
2304 bool IsArrow,
2305 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002306 SourceLocation TemplateKWLoc,
Richard Smith9138b4e2011-10-26 19:06:56 +00002307 NamedDecl *FirstQualifierInScope,
2308 LookupResult &R,
John McCall129e2df2009-11-30 22:42:35 +00002309 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002310 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00002311 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002312
John McCall9ae2f072010-08-23 23:25:46 +00002313 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002314 OperatorLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002315 SS, TemplateKWLoc,
2316 FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00002317 R, TemplateArgs);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002318 }
Mike Stump1eb44332009-09-09 15:08:12 +00002319
Sebastian Redl2e156222010-09-10 20:55:43 +00002320 /// \brief Build a new noexcept expression.
2321 ///
2322 /// By default, performs semantic analysis to build the new expression.
2323 /// Subclasses may override this routine to provide different behavior.
2324 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2325 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2326 }
2327
Douglas Gregoree8aff02011-01-04 17:33:58 +00002328 /// \brief Build a new expression to compute the length of a parameter pack.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002329 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2330 SourceLocation PackLoc,
Douglas Gregoree8aff02011-01-04 17:33:58 +00002331 SourceLocation RParenLoc,
David Blaikiedc84cd52013-02-20 22:23:23 +00002332 Optional<unsigned> Length) {
Douglas Gregor089e8932011-10-10 18:59:29 +00002333 if (Length)
Chad Rosier4a9d7952012-08-08 18:46:20 +00002334 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2335 OperatorLoc, Pack, PackLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002336 RParenLoc, *Length);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002337
2338 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2339 OperatorLoc, Pack, PackLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002340 RParenLoc);
Douglas Gregoree8aff02011-01-04 17:33:58 +00002341 }
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002342
Patrick Beardeb382ec2012-04-19 00:25:12 +00002343 /// \brief Build a new Objective-C boxed expression.
2344 ///
2345 /// By default, performs semantic analysis to build the new expression.
2346 /// Subclasses may override this routine to provide different behavior.
2347 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2348 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2349 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002350
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002351 /// \brief Build a new Objective-C array literal.
2352 ///
2353 /// By default, performs semantic analysis to build the new expression.
2354 /// Subclasses may override this routine to provide different behavior.
2355 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2356 Expr **Elements, unsigned NumElements) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002357 return getSema().BuildObjCArrayLiteral(Range,
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002358 MultiExprArg(Elements, NumElements));
2359 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002360
2361 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002362 Expr *Base, Expr *Key,
2363 ObjCMethodDecl *getterMethod,
2364 ObjCMethodDecl *setterMethod) {
2365 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2366 getterMethod, setterMethod);
2367 }
2368
2369 /// \brief Build a new Objective-C dictionary literal.
2370 ///
2371 /// By default, performs semantic analysis to build the new expression.
2372 /// Subclasses may override this routine to provide different behavior.
2373 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
2374 ObjCDictionaryElement *Elements,
2375 unsigned NumElements) {
2376 return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements);
2377 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002378
James Dennett699c9042012-06-15 07:13:21 +00002379 /// \brief Build a new Objective-C \@encode expression.
Douglas Gregorb98b1992009-08-11 05:31:07 +00002380 ///
2381 /// By default, performs semantic analysis to build the new expression.
2382 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002383 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregor81d34662010-04-20 15:39:42 +00002384 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002385 SourceLocation RParenLoc) {
Douglas Gregor81d34662010-04-20 15:39:42 +00002386 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002387 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002388 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00002389
Douglas Gregor92e986e2010-04-22 16:44:27 +00002390 /// \brief Build a new Objective-C class message.
John McCall60d7b3a2010-08-24 06:29:42 +00002391 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002392 Selector Sel,
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002393 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002394 ObjCMethodDecl *Method,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002395 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002396 MultiExprArg Args,
2397 SourceLocation RBracLoc) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00002398 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2399 ReceiverTypeInfo->getType(),
2400 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002401 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002402 RBracLoc, Args);
Douglas Gregor92e986e2010-04-22 16:44:27 +00002403 }
2404
2405 /// \brief Build a new Objective-C instance message.
John McCall60d7b3a2010-08-24 06:29:42 +00002406 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002407 Selector Sel,
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002408 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002409 ObjCMethodDecl *Method,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002410 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002411 MultiExprArg Args,
2412 SourceLocation RBracLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00002413 return SemaRef.BuildInstanceMessage(Receiver,
2414 Receiver->getType(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00002415 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002416 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002417 RBracLoc, Args);
Douglas Gregor92e986e2010-04-22 16:44:27 +00002418 }
2419
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002420 /// \brief Build a new Objective-C ivar reference expression.
2421 ///
2422 /// By default, performs semantic analysis to build the new expression.
2423 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002424 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002425 SourceLocation IvarLoc,
2426 bool IsArrow, bool IsFreeIvar) {
2427 // FIXME: We lose track of the IsFreeIvar bit.
2428 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002429 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002430 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2431 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002432 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002433 /*FIME:*/IvarLoc,
John McCalld226f652010-08-21 09:40:31 +00002434 SS, 0,
John McCallad00b772010-06-16 08:42:20 +00002435 false);
John Wiegley429bb272011-04-08 18:41:53 +00002436 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002437 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002438
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002439 if (Result.get())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002440 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002441
John Wiegley429bb272011-04-08 18:41:53 +00002442 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002443 /*FIXME:*/IvarLoc, IsArrow,
2444 SS, SourceLocation(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002445 /*FirstQualifierInScope=*/0,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002446 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002447 /*TemplateArgs=*/0);
2448 }
Douglas Gregore3303542010-04-26 20:47:02 +00002449
2450 /// \brief Build a new Objective-C property reference expression.
2451 ///
2452 /// By default, performs semantic analysis to build the new expression.
2453 /// Subclasses may override this routine to provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002454 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall3c3b7f92011-10-25 17:37:35 +00002455 ObjCPropertyDecl *Property,
2456 SourceLocation PropertyLoc) {
Douglas Gregore3303542010-04-26 20:47:02 +00002457 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002458 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregore3303542010-04-26 20:47:02 +00002459 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2460 Sema::LookupMemberName);
2461 bool IsArrow = false;
John McCall60d7b3a2010-08-24 06:29:42 +00002462 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregore3303542010-04-26 20:47:02 +00002463 /*FIME:*/PropertyLoc,
John McCalld226f652010-08-21 09:40:31 +00002464 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002465 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002466 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002467
Douglas Gregore3303542010-04-26 20:47:02 +00002468 if (Result.get())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002469 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002470
John Wiegley429bb272011-04-08 18:41:53 +00002471 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002472 /*FIXME:*/PropertyLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002473 SS, SourceLocation(),
Douglas Gregore3303542010-04-26 20:47:02 +00002474 /*FirstQualifierInScope=*/0,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002475 R,
Douglas Gregore3303542010-04-26 20:47:02 +00002476 /*TemplateArgs=*/0);
2477 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002478
John McCall12f78a62010-12-02 01:19:52 +00002479 /// \brief Build a new Objective-C property reference expression.
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002480 ///
2481 /// By default, performs semantic analysis to build the new expression.
John McCall12f78a62010-12-02 01:19:52 +00002482 /// Subclasses may override this routine to provide different behavior.
2483 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2484 ObjCMethodDecl *Getter,
2485 ObjCMethodDecl *Setter,
2486 SourceLocation PropertyLoc) {
2487 // Since these expressions can only be value-dependent, we do not
2488 // need to perform semantic analysis again.
2489 return Owned(
2490 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2491 VK_LValue, OK_ObjCProperty,
2492 PropertyLoc, Base));
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002493 }
2494
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002495 /// \brief Build a new Objective-C "isa" expression.
2496 ///
2497 /// By default, performs semantic analysis to build the new expression.
2498 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002499 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Fariborz Jahanianec8deba2013-03-28 19:50:55 +00002500 SourceLocation OpLoc,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002501 bool IsArrow) {
2502 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002503 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002504 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2505 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002506 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Fariborz Jahanianec8deba2013-03-28 19:50:55 +00002507 OpLoc,
John McCalld226f652010-08-21 09:40:31 +00002508 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002509 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002510 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002511
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002512 if (Result.get())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002513 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002514
John Wiegley429bb272011-04-08 18:41:53 +00002515 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Fariborz Jahanianec8deba2013-03-28 19:50:55 +00002516 OpLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002517 SS, SourceLocation(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002518 /*FirstQualifierInScope=*/0,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002519 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002520 /*TemplateArgs=*/0);
2521 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002522
Douglas Gregorb98b1992009-08-11 05:31:07 +00002523 /// \brief Build a new shuffle vector expression.
2524 ///
2525 /// By default, performs semantic analysis to build the new expression.
2526 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002527 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCallf89e55a2010-11-18 06:31:45 +00002528 MultiExprArg SubExprs,
2529 SourceLocation RParenLoc) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002530 // Find the declaration for __builtin_shufflevector
Mike Stump1eb44332009-09-09 15:08:12 +00002531 const IdentifierInfo &Name
Douglas Gregorb98b1992009-08-11 05:31:07 +00002532 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2533 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2534 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
David Blaikie3bc93e32012-12-19 00:45:41 +00002535 assert(!Lookup.empty() && "No __builtin_shufflevector?");
Mike Stump1eb44332009-09-09 15:08:12 +00002536
Douglas Gregorb98b1992009-08-11 05:31:07 +00002537 // Build a reference to the __builtin_shufflevector builtin
David Blaikie3bc93e32012-12-19 00:45:41 +00002538 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
Eli Friedmana6c66ce2012-08-31 00:14:07 +00002539 Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false,
2540 SemaRef.Context.BuiltinFnTy,
2541 VK_RValue, BuiltinLoc);
2542 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
2543 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
2544 CK_BuiltinFnToFnPtr).take();
Mike Stump1eb44332009-09-09 15:08:12 +00002545
2546 // Build the CallExpr
John Wiegley429bb272011-04-08 18:41:53 +00002547 ExprResult TheCall = SemaRef.Owned(
Eli Friedmana6c66ce2012-08-31 00:14:07 +00002548 new (SemaRef.Context) CallExpr(SemaRef.Context, Callee, SubExprs,
Benjamin Kramer3b6bef92012-08-24 11:54:20 +00002549 Builtin->getCallResultType(),
John McCallf89e55a2010-11-18 06:31:45 +00002550 Expr::getValueKindForType(Builtin->getResultType()),
John Wiegley429bb272011-04-08 18:41:53 +00002551 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002552
Douglas Gregorb98b1992009-08-11 05:31:07 +00002553 // Type-check the __builtin_shufflevector expression.
John Wiegley429bb272011-04-08 18:41:53 +00002554 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.take()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00002555 }
John McCall43fed0d2010-11-12 08:19:04 +00002556
Hal Finkel414a1bd2013-09-18 03:29:45 +00002557 /// \brief Build a new convert vector expression.
2558 ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc,
2559 Expr *SrcExpr, TypeSourceInfo *DstTInfo,
2560 SourceLocation RParenLoc) {
2561 return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo,
2562 BuiltinLoc, RParenLoc);
2563 }
2564
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002565 /// \brief Build a new template argument pack expansion.
2566 ///
2567 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier4a9d7952012-08-08 18:46:20 +00002568 /// for a template argument. Subclasses may override this routine to provide
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002569 /// different behavior.
2570 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregorcded4f62011-01-14 17:04:44 +00002571 SourceLocation EllipsisLoc,
David Blaikiedc84cd52013-02-20 22:23:23 +00002572 Optional<unsigned> NumExpansions) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002573 switch (Pattern.getArgument().getKind()) {
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002574 case TemplateArgument::Expression: {
2575 ExprResult Result
Douglas Gregor67fd1252011-01-14 21:20:45 +00002576 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2577 EllipsisLoc, NumExpansions);
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002578 if (Result.isInvalid())
2579 return TemplateArgumentLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002580
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002581 return TemplateArgumentLoc(Result.get(), Result.get());
2582 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002583
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002584 case TemplateArgument::Template:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002585 return TemplateArgumentLoc(TemplateArgument(
2586 Pattern.getArgument().getAsTemplate(),
Douglas Gregor2be29f42011-01-14 23:41:42 +00002587 NumExpansions),
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002588 Pattern.getTemplateQualifierLoc(),
Douglas Gregora7fc9012011-01-05 18:58:31 +00002589 Pattern.getTemplateNameLoc(),
2590 EllipsisLoc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002591
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002592 case TemplateArgument::Null:
2593 case TemplateArgument::Integral:
2594 case TemplateArgument::Declaration:
2595 case TemplateArgument::Pack:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002596 case TemplateArgument::TemplateExpansion:
Eli Friedmand7a6b162012-09-26 02:36:12 +00002597 case TemplateArgument::NullPtr:
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002598 llvm_unreachable("Pack expansion pattern has no parameter packs");
Chad Rosier4a9d7952012-08-08 18:46:20 +00002599
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002600 case TemplateArgument::Type:
Chad Rosier4a9d7952012-08-08 18:46:20 +00002601 if (TypeSourceInfo *Expansion
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002602 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00002603 EllipsisLoc,
2604 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002605 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2606 Expansion);
2607 break;
2608 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002609
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002610 return TemplateArgumentLoc();
2611 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002612
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002613 /// \brief Build a new expression pack expansion.
2614 ///
2615 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier4a9d7952012-08-08 18:46:20 +00002616 /// for an expression. Subclasses may override this routine to provide
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002617 /// different behavior.
Douglas Gregor67fd1252011-01-14 21:20:45 +00002618 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
David Blaikiedc84cd52013-02-20 22:23:23 +00002619 Optional<unsigned> NumExpansions) {
Douglas Gregor67fd1252011-01-14 21:20:45 +00002620 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002621 }
Eli Friedmandfa64ba2011-10-14 22:48:56 +00002622
2623 /// \brief Build a new atomic operation expression.
2624 ///
2625 /// By default, performs semantic analysis to build the new expression.
2626 /// Subclasses may override this routine to provide different behavior.
2627 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2628 MultiExprArg SubExprs,
2629 QualType RetTy,
2630 AtomicExpr::AtomicOp Op,
2631 SourceLocation RParenLoc) {
2632 // Just create the expression; there is not any interesting semantic
2633 // analysis here because we can't actually build an AtomicExpr until
2634 // we are sure it is semantically sound.
Benjamin Kramer3b6bef92012-08-24 11:54:20 +00002635 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
Eli Friedmandfa64ba2011-10-14 22:48:56 +00002636 RParenLoc);
2637 }
2638
John McCall43fed0d2010-11-12 08:19:04 +00002639private:
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002640 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2641 QualType ObjectType,
2642 NamedDecl *FirstQualifierInScope,
2643 CXXScopeSpec &SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00002644
2645 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2646 QualType ObjectType,
2647 NamedDecl *FirstQualifierInScope,
2648 CXXScopeSpec &SS);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002649};
Douglas Gregorb98b1992009-08-11 05:31:07 +00002650
Douglas Gregor43959a92009-08-20 07:17:43 +00002651template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002652StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00002653 if (!S)
2654 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00002655
Douglas Gregor43959a92009-08-20 07:17:43 +00002656 switch (S->getStmtClass()) {
2657 case Stmt::NoStmtClass: break;
Mike Stump1eb44332009-09-09 15:08:12 +00002658
Douglas Gregor43959a92009-08-20 07:17:43 +00002659 // Transform individual statement nodes
2660#define STMT(Node, Parent) \
2661 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCall63c00d72011-02-09 08:16:59 +00002662#define ABSTRACT_STMT(Node)
Douglas Gregor43959a92009-08-20 07:17:43 +00002663#define EXPR(Node, Parent)
Sean Hunt4bfe1962010-05-05 15:24:00 +00002664#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002665
Douglas Gregor43959a92009-08-20 07:17:43 +00002666 // Transform expressions by calling TransformExpr.
2667#define STMT(Node, Parent)
Sean Hunt7381d5c2010-05-18 06:22:21 +00002668#define ABSTRACT_STMT(Stmt)
Douglas Gregor43959a92009-08-20 07:17:43 +00002669#define EXPR(Node, Parent) case Stmt::Node##Class:
Sean Hunt4bfe1962010-05-05 15:24:00 +00002670#include "clang/AST/StmtNodes.inc"
Douglas Gregor43959a92009-08-20 07:17:43 +00002671 {
John McCall60d7b3a2010-08-24 06:29:42 +00002672 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregor43959a92009-08-20 07:17:43 +00002673 if (E.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002674 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00002675
Richard Smith41956372013-01-14 22:39:08 +00002676 return getSema().ActOnExprStmt(E);
Douglas Gregor43959a92009-08-20 07:17:43 +00002677 }
Mike Stump1eb44332009-09-09 15:08:12 +00002678 }
2679
John McCall3fa5cae2010-10-26 07:05:15 +00002680 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00002681}
Mike Stump1eb44332009-09-09 15:08:12 +00002682
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00002683template<typename Derived>
2684OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) {
2685 if (!S)
2686 return S;
2687
2688 switch (S->getClauseKind()) {
2689 default: break;
2690 // Transform individual clause nodes
2691#define OPENMP_CLAUSE(Name, Class) \
2692 case OMPC_ ## Name : \
2693 return getDerived().Transform ## Class(cast<Class>(S));
2694#include "clang/Basic/OpenMPKinds.def"
2695 }
2696
2697 return S;
2698}
2699
Mike Stump1eb44332009-09-09 15:08:12 +00002700
Douglas Gregor670444e2009-08-04 22:27:00 +00002701template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002702ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002703 if (!E)
2704 return SemaRef.Owned(E);
2705
2706 switch (E->getStmtClass()) {
2707 case Stmt::NoStmtClass: break;
2708#define STMT(Node, Parent) case Stmt::Node##Class: break;
Sean Hunt7381d5c2010-05-18 06:22:21 +00002709#define ABSTRACT_STMT(Stmt)
Douglas Gregorb98b1992009-08-11 05:31:07 +00002710#define EXPR(Node, Parent) \
John McCall454feb92009-12-08 09:21:05 +00002711 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Sean Hunt4bfe1962010-05-05 15:24:00 +00002712#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002713 }
2714
John McCall3fa5cae2010-10-26 07:05:15 +00002715 return SemaRef.Owned(E);
Douglas Gregor657c1ac2009-08-06 22:17:10 +00002716}
2717
2718template<typename Derived>
Richard Smithc83c2302012-12-19 01:39:02 +00002719ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
2720 bool CXXDirectInit) {
2721 // Initializers are instantiated like expressions, except that various outer
2722 // layers are stripped.
2723 if (!Init)
2724 return SemaRef.Owned(Init);
2725
2726 if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init))
2727 Init = ExprTemp->getSubExpr();
2728
Richard Smith858c2c32013-05-30 22:40:16 +00002729 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
2730 Init = MTE->GetTemporaryExpr();
2731
Richard Smithc83c2302012-12-19 01:39:02 +00002732 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
2733 Init = Binder->getSubExpr();
2734
2735 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
2736 Init = ICE->getSubExprAsWritten();
2737
Richard Smith7c3e6152013-06-12 22:31:48 +00002738 if (CXXStdInitializerListExpr *ILE =
2739 dyn_cast<CXXStdInitializerListExpr>(Init))
2740 return TransformInitializer(ILE->getSubExpr(), CXXDirectInit);
2741
Richard Smith5cf15892012-12-21 08:13:35 +00002742 // If this is not a direct-initializer, we only need to reconstruct
2743 // InitListExprs. Other forms of copy-initialization will be a no-op if
2744 // the initializer is already the right type.
2745 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
2746 if (!CXXDirectInit && !(Construct && Construct->isListInitialization()))
2747 return getDerived().TransformExpr(Init);
2748
2749 // Revert value-initialization back to empty parens.
2750 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
2751 SourceRange Parens = VIE->getSourceRange();
Dmitri Gribenko62ed8892013-05-05 20:40:26 +00002752 return getDerived().RebuildParenListExpr(Parens.getBegin(), None,
Richard Smith5cf15892012-12-21 08:13:35 +00002753 Parens.getEnd());
2754 }
2755
2756 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
2757 if (isa<ImplicitValueInitExpr>(Init))
Dmitri Gribenko62ed8892013-05-05 20:40:26 +00002758 return getDerived().RebuildParenListExpr(SourceLocation(), None,
Richard Smith5cf15892012-12-21 08:13:35 +00002759 SourceLocation());
2760
2761 // Revert initialization by constructor back to a parenthesized or braced list
2762 // of expressions. Any other form of initializer can just be reused directly.
2763 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
Richard Smithc83c2302012-12-19 01:39:02 +00002764 return getDerived().TransformExpr(Init);
2765
2766 SmallVector<Expr*, 8> NewArgs;
2767 bool ArgChanged = false;
2768 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
2769 /*IsCall*/true, NewArgs, &ArgChanged))
2770 return ExprError();
2771
2772 // If this was list initialization, revert to list form.
2773 if (Construct->isListInitialization())
2774 return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs,
2775 Construct->getLocEnd(),
2776 Construct->getType());
2777
Richard Smithc83c2302012-12-19 01:39:02 +00002778 // Build a ParenListExpr to represent anything else.
Enea Zaffanella1245a542013-09-07 05:49:53 +00002779 SourceRange Parens = Construct->getParenOrBraceRange();
Richard Smithc83c2302012-12-19 01:39:02 +00002780 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
2781 Parens.getEnd());
2782}
2783
2784template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00002785bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2786 unsigned NumInputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +00002787 bool IsCall,
Chris Lattner686775d2011-07-20 06:58:45 +00002788 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +00002789 bool *ArgChanged) {
2790 for (unsigned I = 0; I != NumInputs; ++I) {
2791 // If requested, drop call arguments that need to be dropped.
2792 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2793 if (ArgChanged)
2794 *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002795
Douglas Gregoraa165f82011-01-03 19:04:46 +00002796 break;
2797 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002798
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002799 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2800 Expr *Pattern = Expansion->getPattern();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002801
Chris Lattner686775d2011-07-20 06:58:45 +00002802 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002803 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2804 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier4a9d7952012-08-08 18:46:20 +00002805
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002806 // Determine whether the set of unexpanded parameter packs can and should
2807 // be expanded.
2808 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00002809 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00002810 Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
2811 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002812 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2813 Pattern->getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00002814 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00002815 Expand, RetainExpansion,
2816 NumExpansions))
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002817 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002818
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002819 if (!Expand) {
2820 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00002821 // transformation on the pack expansion, producing another pack
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002822 // expansion.
2823 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2824 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2825 if (OutPattern.isInvalid())
2826 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002827
2828 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregor67fd1252011-01-14 21:20:45 +00002829 Expansion->getEllipsisLoc(),
2830 NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002831 if (Out.isInvalid())
2832 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002833
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002834 if (ArgChanged)
2835 *ArgChanged = true;
2836 Outputs.push_back(Out.get());
2837 continue;
2838 }
John McCallc8fc90a2011-07-06 07:30:07 +00002839
2840 // Record right away that the argument was changed. This needs
2841 // to happen even if the array expands to nothing.
2842 if (ArgChanged) *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002843
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002844 // The transform has determined that we should perform an elementwise
2845 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00002846 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002847 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2848 ExprResult Out = getDerived().TransformExpr(Pattern);
2849 if (Out.isInvalid())
2850 return true;
2851
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002852 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregor67fd1252011-01-14 21:20:45 +00002853 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2854 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002855 if (Out.isInvalid())
2856 return true;
2857 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002858
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002859 Outputs.push_back(Out.get());
2860 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002861
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002862 continue;
2863 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002864
Richard Smithc83c2302012-12-19 01:39:02 +00002865 ExprResult Result =
2866 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
2867 : getDerived().TransformExpr(Inputs[I]);
Douglas Gregoraa165f82011-01-03 19:04:46 +00002868 if (Result.isInvalid())
2869 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002870
Douglas Gregoraa165f82011-01-03 19:04:46 +00002871 if (Result.get() != Inputs[I] && ArgChanged)
2872 *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002873
2874 Outputs.push_back(Result.get());
Douglas Gregoraa165f82011-01-03 19:04:46 +00002875 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002876
Douglas Gregoraa165f82011-01-03 19:04:46 +00002877 return false;
2878}
2879
2880template<typename Derived>
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002881NestedNameSpecifierLoc
2882TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2883 NestedNameSpecifierLoc NNS,
2884 QualType ObjectType,
2885 NamedDecl *FirstQualifierInScope) {
Chris Lattner686775d2011-07-20 06:58:45 +00002886 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002887 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002888 Qualifier = Qualifier.getPrefix())
2889 Qualifiers.push_back(Qualifier);
2890
2891 CXXScopeSpec SS;
2892 while (!Qualifiers.empty()) {
2893 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2894 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002895
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002896 switch (QNNS->getKind()) {
2897 case NestedNameSpecifier::Identifier:
Chad Rosier4a9d7952012-08-08 18:46:20 +00002898 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002899 *QNNS->getAsIdentifier(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002900 Q.getLocalBeginLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002901 Q.getLocalEndLoc(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002902 ObjectType, false, SS,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002903 FirstQualifierInScope, false))
2904 return NestedNameSpecifierLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002905
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002906 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002907
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002908 case NestedNameSpecifier::Namespace: {
2909 NamespaceDecl *NS
2910 = cast_or_null<NamespaceDecl>(
2911 getDerived().TransformDecl(
2912 Q.getLocalBeginLoc(),
2913 QNNS->getAsNamespace()));
2914 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2915 break;
2916 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002917
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002918 case NestedNameSpecifier::NamespaceAlias: {
2919 NamespaceAliasDecl *Alias
2920 = cast_or_null<NamespaceAliasDecl>(
2921 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2922 QNNS->getAsNamespaceAlias()));
Chad Rosier4a9d7952012-08-08 18:46:20 +00002923 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002924 Q.getLocalEndLoc());
2925 break;
2926 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002927
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002928 case NestedNameSpecifier::Global:
2929 // There is no meaningful transformation that one could perform on the
2930 // global scope.
2931 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2932 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002933
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002934 case NestedNameSpecifier::TypeSpecWithTemplate:
2935 case NestedNameSpecifier::TypeSpec: {
2936 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2937 FirstQualifierInScope, SS);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002938
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002939 if (!TL)
2940 return NestedNameSpecifierLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002941
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002942 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Richard Smith80ad52f2013-01-02 11:42:31 +00002943 (SemaRef.getLangOpts().CPlusPlus11 &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002944 TL.getType()->isEnumeralType())) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002945 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002946 "Can't get cv-qualifiers here");
Richard Smith95aafb22011-10-20 03:28:47 +00002947 if (TL.getType()->isEnumeralType())
2948 SemaRef.Diag(TL.getBeginLoc(),
2949 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002950 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2951 Q.getLocalEndLoc());
2952 break;
2953 }
Richard Trieu00c93a12011-05-07 01:36:37 +00002954 // If the nested-name-specifier is an invalid type def, don't emit an
2955 // error because a previous error should have already been emitted.
David Blaikie39e6ab42013-02-18 22:06:02 +00002956 TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
2957 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002958 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieu00c93a12011-05-07 01:36:37 +00002959 << TL.getType() << SS.getRange();
2960 }
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002961 return NestedNameSpecifierLoc();
2962 }
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002963 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002964
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002965 // The qualifier-in-scope and object type only apply to the leftmost entity.
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002966 FirstQualifierInScope = 0;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002967 ObjectType = QualType();
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002968 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002969
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002970 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002971 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002972 !getDerived().AlwaysRebuild())
2973 return NNS;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002974
2975 // If we can re-use the source-location data from the original
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002976 // nested-name-specifier, do so.
2977 if (SS.location_size() == NNS.getDataLength() &&
2978 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2979 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
2980
2981 // Allocate new nested-name-specifier location information.
2982 return SS.getWithLocInContext(SemaRef.Context);
2983}
2984
2985template<typename Derived>
Abramo Bagnara25777432010-08-11 22:01:17 +00002986DeclarationNameInfo
2987TreeTransform<Derived>
John McCall43fed0d2010-11-12 08:19:04 +00002988::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnara25777432010-08-11 22:01:17 +00002989 DeclarationName Name = NameInfo.getName();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002990 if (!Name)
Abramo Bagnara25777432010-08-11 22:01:17 +00002991 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002992
2993 switch (Name.getNameKind()) {
2994 case DeclarationName::Identifier:
2995 case DeclarationName::ObjCZeroArgSelector:
2996 case DeclarationName::ObjCOneArgSelector:
2997 case DeclarationName::ObjCMultiArgSelector:
2998 case DeclarationName::CXXOperatorName:
Sean Hunt3e518bd2009-11-29 07:34:05 +00002999 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregor81499bb2009-09-03 22:13:48 +00003000 case DeclarationName::CXXUsingDirective:
Abramo Bagnara25777432010-08-11 22:01:17 +00003001 return NameInfo;
Mike Stump1eb44332009-09-09 15:08:12 +00003002
Douglas Gregor81499bb2009-09-03 22:13:48 +00003003 case DeclarationName::CXXConstructorName:
3004 case DeclarationName::CXXDestructorName:
3005 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnara25777432010-08-11 22:01:17 +00003006 TypeSourceInfo *NewTInfo;
3007 CanQualType NewCanTy;
3008 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00003009 NewTInfo = getDerived().TransformType(OldTInfo);
3010 if (!NewTInfo)
3011 return DeclarationNameInfo();
3012 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnara25777432010-08-11 22:01:17 +00003013 }
3014 else {
3015 NewTInfo = 0;
3016 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall43fed0d2010-11-12 08:19:04 +00003017 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnara25777432010-08-11 22:01:17 +00003018 if (NewT.isNull())
3019 return DeclarationNameInfo();
3020 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
3021 }
Mike Stump1eb44332009-09-09 15:08:12 +00003022
Abramo Bagnara25777432010-08-11 22:01:17 +00003023 DeclarationName NewName
3024 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
3025 NewCanTy);
3026 DeclarationNameInfo NewNameInfo(NameInfo);
3027 NewNameInfo.setName(NewName);
3028 NewNameInfo.setNamedTypeInfo(NewTInfo);
3029 return NewNameInfo;
Douglas Gregor81499bb2009-09-03 22:13:48 +00003030 }
Mike Stump1eb44332009-09-09 15:08:12 +00003031 }
3032
David Blaikieb219cfc2011-09-23 05:06:16 +00003033 llvm_unreachable("Unknown name kind.");
Douglas Gregor81499bb2009-09-03 22:13:48 +00003034}
3035
3036template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003037TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003038TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
3039 TemplateName Name,
3040 SourceLocation NameLoc,
3041 QualType ObjectType,
3042 NamedDecl *FirstQualifierInScope) {
3043 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
3044 TemplateDecl *Template = QTN->getTemplateDecl();
3045 assert(Template && "qualified template name must refer to a template");
Chad Rosier4a9d7952012-08-08 18:46:20 +00003046
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003047 TemplateDecl *TransTemplate
Chad Rosier4a9d7952012-08-08 18:46:20 +00003048 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003049 Template));
3050 if (!TransTemplate)
3051 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003052
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003053 if (!getDerived().AlwaysRebuild() &&
3054 SS.getScopeRep() == QTN->getQualifier() &&
3055 TransTemplate == Template)
3056 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003057
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003058 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
3059 TransTemplate);
3060 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003061
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003062 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
3063 if (SS.getScopeRep()) {
3064 // These apply to the scope specifier, not the template.
3065 ObjectType = QualType();
3066 FirstQualifierInScope = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003067 }
3068
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003069 if (!getDerived().AlwaysRebuild() &&
3070 SS.getScopeRep() == DTN->getQualifier() &&
3071 ObjectType.isNull())
3072 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003073
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003074 if (DTN->isIdentifier()) {
3075 return getDerived().RebuildTemplateName(SS,
Chad Rosier4a9d7952012-08-08 18:46:20 +00003076 *DTN->getIdentifier(),
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003077 NameLoc,
3078 ObjectType,
3079 FirstQualifierInScope);
3080 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003081
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003082 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
3083 ObjectType);
3084 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003085
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003086 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
3087 TemplateDecl *TransTemplate
Chad Rosier4a9d7952012-08-08 18:46:20 +00003088 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003089 Template));
3090 if (!TransTemplate)
3091 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003092
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003093 if (!getDerived().AlwaysRebuild() &&
3094 TransTemplate == Template)
3095 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003096
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003097 return TemplateName(TransTemplate);
3098 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003099
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003100 if (SubstTemplateTemplateParmPackStorage *SubstPack
3101 = Name.getAsSubstTemplateTemplateParmPack()) {
3102 TemplateTemplateParmDecl *TransParam
3103 = cast_or_null<TemplateTemplateParmDecl>(
3104 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
3105 if (!TransParam)
3106 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003107
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003108 if (!getDerived().AlwaysRebuild() &&
3109 TransParam == SubstPack->getParameterPack())
3110 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003111
3112 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003113 SubstPack->getArgumentPack());
3114 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003115
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003116 // These should be getting filtered out before they reach the AST.
3117 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003118}
3119
3120template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00003121void TreeTransform<Derived>::InventTemplateArgumentLoc(
3122 const TemplateArgument &Arg,
3123 TemplateArgumentLoc &Output) {
3124 SourceLocation Loc = getDerived().getBaseLocation();
3125 switch (Arg.getKind()) {
3126 case TemplateArgument::Null:
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00003127 llvm_unreachable("null template argument in TreeTransform");
John McCall833ca992009-10-29 08:12:44 +00003128 break;
3129
3130 case TemplateArgument::Type:
3131 Output = TemplateArgumentLoc(Arg,
John McCalla93c9342009-12-07 02:54:59 +00003132 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier4a9d7952012-08-08 18:46:20 +00003133
John McCall833ca992009-10-29 08:12:44 +00003134 break;
3135
Douglas Gregor788cd062009-11-11 01:00:40 +00003136 case TemplateArgument::Template:
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003137 case TemplateArgument::TemplateExpansion: {
3138 NestedNameSpecifierLocBuilder Builder;
3139 TemplateName Template = Arg.getAsTemplate();
3140 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3141 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3142 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3143 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003144
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003145 if (Arg.getKind() == TemplateArgument::Template)
Chad Rosier4a9d7952012-08-08 18:46:20 +00003146 Output = TemplateArgumentLoc(Arg,
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003147 Builder.getWithLocInContext(SemaRef.Context),
3148 Loc);
3149 else
Chad Rosier4a9d7952012-08-08 18:46:20 +00003150 Output = TemplateArgumentLoc(Arg,
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003151 Builder.getWithLocInContext(SemaRef.Context),
3152 Loc, Loc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003153
Douglas Gregor788cd062009-11-11 01:00:40 +00003154 break;
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003155 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00003156
John McCall833ca992009-10-29 08:12:44 +00003157 case TemplateArgument::Expression:
3158 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3159 break;
3160
3161 case TemplateArgument::Declaration:
3162 case TemplateArgument::Integral:
3163 case TemplateArgument::Pack:
Eli Friedmand7a6b162012-09-26 02:36:12 +00003164 case TemplateArgument::NullPtr:
John McCall828bff22009-10-29 18:45:58 +00003165 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall833ca992009-10-29 08:12:44 +00003166 break;
3167 }
3168}
3169
3170template<typename Derived>
3171bool TreeTransform<Derived>::TransformTemplateArgument(
3172 const TemplateArgumentLoc &Input,
3173 TemplateArgumentLoc &Output) {
3174 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregor670444e2009-08-04 22:27:00 +00003175 switch (Arg.getKind()) {
3176 case TemplateArgument::Null:
3177 case TemplateArgument::Integral:
Eli Friedman511e3ae2012-09-25 01:02:42 +00003178 case TemplateArgument::Pack:
3179 case TemplateArgument::Declaration:
Eli Friedmand7a6b162012-09-26 02:36:12 +00003180 case TemplateArgument::NullPtr:
3181 llvm_unreachable("Unexpected TemplateArgument");
Mike Stump1eb44332009-09-09 15:08:12 +00003182
Douglas Gregor670444e2009-08-04 22:27:00 +00003183 case TemplateArgument::Type: {
John McCalla93c9342009-12-07 02:54:59 +00003184 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall833ca992009-10-29 08:12:44 +00003185 if (DI == NULL)
John McCalla93c9342009-12-07 02:54:59 +00003186 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall833ca992009-10-29 08:12:44 +00003187
3188 DI = getDerived().TransformType(DI);
3189 if (!DI) return true;
3190
3191 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3192 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00003193 }
Mike Stump1eb44332009-09-09 15:08:12 +00003194
Douglas Gregor788cd062009-11-11 01:00:40 +00003195 case TemplateArgument::Template: {
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003196 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3197 if (QualifierLoc) {
3198 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3199 if (!QualifierLoc)
3200 return true;
3201 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003202
Douglas Gregor1d752d72011-03-02 18:46:51 +00003203 CXXScopeSpec SS;
3204 SS.Adopt(QualifierLoc);
Douglas Gregor788cd062009-11-11 01:00:40 +00003205 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00003206 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3207 Input.getTemplateNameLoc());
Douglas Gregor788cd062009-11-11 01:00:40 +00003208 if (Template.isNull())
3209 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003210
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003211 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor788cd062009-11-11 01:00:40 +00003212 Input.getTemplateNameLoc());
3213 return false;
3214 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00003215
3216 case TemplateArgument::TemplateExpansion:
3217 llvm_unreachable("Caller should expand pack expansions");
3218
Douglas Gregor670444e2009-08-04 22:27:00 +00003219 case TemplateArgument::Expression: {
Richard Smithf6702a32011-12-20 02:08:33 +00003220 // Template argument expressions are constant expressions.
Mike Stump1eb44332009-09-09 15:08:12 +00003221 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smithf6702a32011-12-20 02:08:33 +00003222 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003223
John McCall833ca992009-10-29 08:12:44 +00003224 Expr *InputExpr = Input.getSourceExpression();
3225 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3226
Chris Lattner223de242011-04-25 20:37:58 +00003227 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanac626012012-02-29 03:16:56 +00003228 E = SemaRef.ActOnConstantExpression(E);
John McCall833ca992009-10-29 08:12:44 +00003229 if (E.isInvalid()) return true;
John McCall9ae2f072010-08-23 23:25:46 +00003230 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall833ca992009-10-29 08:12:44 +00003231 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00003232 }
Douglas Gregor670444e2009-08-04 22:27:00 +00003233 }
Mike Stump1eb44332009-09-09 15:08:12 +00003234
Douglas Gregor670444e2009-08-04 22:27:00 +00003235 // Work around bogus GCC warning
John McCall833ca992009-10-29 08:12:44 +00003236 return true;
Douglas Gregor670444e2009-08-04 22:27:00 +00003237}
3238
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003239/// \brief Iterator adaptor that invents template argument location information
3240/// for each of the template arguments in its underlying iterator.
3241template<typename Derived, typename InputIterator>
3242class TemplateArgumentLocInventIterator {
3243 TreeTransform<Derived> &Self;
3244 InputIterator Iter;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003245
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003246public:
3247 typedef TemplateArgumentLoc value_type;
3248 typedef TemplateArgumentLoc reference;
3249 typedef typename std::iterator_traits<InputIterator>::difference_type
3250 difference_type;
3251 typedef std::input_iterator_tag iterator_category;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003252
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003253 class pointer {
3254 TemplateArgumentLoc Arg;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003255
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003256 public:
3257 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003258
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003259 const TemplateArgumentLoc *operator->() const { return &Arg; }
3260 };
Chad Rosier4a9d7952012-08-08 18:46:20 +00003261
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003262 TemplateArgumentLocInventIterator() { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003263
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003264 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3265 InputIterator Iter)
3266 : Self(Self), Iter(Iter) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003267
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003268 TemplateArgumentLocInventIterator &operator++() {
3269 ++Iter;
3270 return *this;
Douglas Gregorfcc12532010-12-20 17:31:10 +00003271 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003272
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003273 TemplateArgumentLocInventIterator operator++(int) {
3274 TemplateArgumentLocInventIterator Old(*this);
3275 ++(*this);
3276 return Old;
3277 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003278
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003279 reference operator*() const {
3280 TemplateArgumentLoc Result;
3281 Self.InventTemplateArgumentLoc(*Iter, Result);
3282 return Result;
3283 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003284
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003285 pointer operator->() const { return pointer(**this); }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003286
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003287 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3288 const TemplateArgumentLocInventIterator &Y) {
3289 return X.Iter == Y.Iter;
3290 }
Douglas Gregorfcc12532010-12-20 17:31:10 +00003291
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003292 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3293 const TemplateArgumentLocInventIterator &Y) {
3294 return X.Iter != Y.Iter;
3295 }
3296};
Chad Rosier4a9d7952012-08-08 18:46:20 +00003297
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003298template<typename Derived>
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003299template<typename InputIterator>
3300bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3301 InputIterator Last,
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003302 TemplateArgumentListInfo &Outputs) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003303 for (; First != Last; ++First) {
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003304 TemplateArgumentLoc Out;
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003305 TemplateArgumentLoc In = *First;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003306
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003307 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3308 // Unpack argument packs, which we translate them into separate
3309 // arguments.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003310 // FIXME: We could do much better if we could guarantee that the
3311 // TemplateArgumentLocInfo for the pack expansion would be usable for
3312 // all of the template arguments in the argument pack.
Chad Rosier4a9d7952012-08-08 18:46:20 +00003313 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003314 TemplateArgument::pack_iterator>
3315 PackLocIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003316 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003317 In.getArgument().pack_begin()),
3318 PackLocIterator(*this,
3319 In.getArgument().pack_end()),
3320 Outputs))
3321 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003322
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003323 continue;
3324 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003325
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003326 if (In.getArgument().isPackExpansion()) {
3327 // We have a pack expansion, for which we will be substituting into
3328 // the pattern.
3329 SourceLocation Ellipsis;
David Blaikiedc84cd52013-02-20 22:23:23 +00003330 Optional<unsigned> OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003331 TemplateArgumentLoc Pattern
Eli Friedman850cf512013-06-20 04:11:21 +00003332 = getSema().getTemplateArgumentPackExpansionPattern(
3333 In, Ellipsis, OrigNumExpansions);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003334
Chris Lattner686775d2011-07-20 06:58:45 +00003335 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003336 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3337 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier4a9d7952012-08-08 18:46:20 +00003338
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003339 // Determine whether the set of unexpanded parameter packs can and should
3340 // be expanded.
3341 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00003342 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00003343 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003344 if (getDerived().TryExpandParameterPacks(Ellipsis,
3345 Pattern.getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00003346 Unexpanded,
Chad Rosier4a9d7952012-08-08 18:46:20 +00003347 Expand,
Douglas Gregord3731192011-01-10 07:32:04 +00003348 RetainExpansion,
3349 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003350 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003351
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003352 if (!Expand) {
3353 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00003354 // transformation on the pack expansion, producing another pack
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003355 // expansion.
3356 TemplateArgumentLoc OutPattern;
3357 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3358 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3359 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003360
Douglas Gregorcded4f62011-01-14 17:04:44 +00003361 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3362 NumExpansions);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003363 if (Out.getArgument().isNull())
3364 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003365
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003366 Outputs.addArgument(Out);
3367 continue;
3368 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003369
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003370 // The transform has determined that we should perform an elementwise
3371 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00003372 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003373 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3374
3375 if (getDerived().TransformTemplateArgument(Pattern, Out))
3376 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003377
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003378 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregorcded4f62011-01-14 17:04:44 +00003379 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3380 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003381 if (Out.getArgument().isNull())
3382 return true;
3383 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003384
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003385 Outputs.addArgument(Out);
3386 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003387
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003388 // If we're supposed to retain a pack expansion, do so by temporarily
3389 // forgetting the partially-substituted parameter pack.
3390 if (RetainExpansion) {
3391 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003392
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003393 if (getDerived().TransformTemplateArgument(Pattern, Out))
3394 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003395
Douglas Gregorcded4f62011-01-14 17:04:44 +00003396 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3397 OrigNumExpansions);
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003398 if (Out.getArgument().isNull())
3399 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003400
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003401 Outputs.addArgument(Out);
3402 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003403
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003404 continue;
3405 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003406
3407 // The simple case:
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003408 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003409 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003410
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003411 Outputs.addArgument(Out);
3412 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003413
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003414 return false;
3415
3416}
3417
Douglas Gregor577f75a2009-08-04 16:50:30 +00003418//===----------------------------------------------------------------------===//
3419// Type transformation
3420//===----------------------------------------------------------------------===//
3421
3422template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003423QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00003424 if (getDerived().AlreadyTransformed(T))
3425 return T;
Mike Stump1eb44332009-09-09 15:08:12 +00003426
John McCalla2becad2009-10-21 00:40:46 +00003427 // Temporary workaround. All of these transformations should
3428 // eventually turn into transformations on TypeLocs.
Douglas Gregorc21c7e92011-01-25 19:13:18 +00003429 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3430 getDerived().getBaseLocation());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003431
John McCall43fed0d2010-11-12 08:19:04 +00003432 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall0953e762009-09-24 19:53:00 +00003433
John McCalla2becad2009-10-21 00:40:46 +00003434 if (!NewDI)
3435 return QualType();
3436
3437 return NewDI->getType();
3438}
3439
3440template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003441TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smithf6702a32011-12-20 02:08:33 +00003442 // Refine the base location to the type's location.
3443 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3444 getDerived().getBaseEntity());
John McCalla2becad2009-10-21 00:40:46 +00003445 if (getDerived().AlreadyTransformed(DI->getType()))
3446 return DI;
3447
3448 TypeLocBuilder TLB;
3449
3450 TypeLoc TL = DI->getTypeLoc();
3451 TLB.reserve(TL.getFullDataSize());
3452
John McCall43fed0d2010-11-12 08:19:04 +00003453 QualType Result = getDerived().TransformType(TLB, TL);
John McCalla2becad2009-10-21 00:40:46 +00003454 if (Result.isNull())
3455 return 0;
3456
John McCalla93c9342009-12-07 02:54:59 +00003457 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCalla2becad2009-10-21 00:40:46 +00003458}
3459
3460template<typename Derived>
3461QualType
John McCall43fed0d2010-11-12 08:19:04 +00003462TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003463 switch (T.getTypeLocClass()) {
3464#define ABSTRACT_TYPELOC(CLASS, PARENT)
David Blaikie39e6ab42013-02-18 22:06:02 +00003465#define TYPELOC(CLASS, PARENT) \
3466 case TypeLoc::CLASS: \
3467 return getDerived().Transform##CLASS##Type(TLB, \
3468 T.castAs<CLASS##TypeLoc>());
John McCalla2becad2009-10-21 00:40:46 +00003469#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +00003470 }
Mike Stump1eb44332009-09-09 15:08:12 +00003471
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00003472 llvm_unreachable("unhandled type loc!");
John McCalla2becad2009-10-21 00:40:46 +00003473}
3474
3475/// FIXME: By default, this routine adds type qualifiers only to types
3476/// that can have qualifiers, and silently suppresses those qualifiers
3477/// that are not permitted (e.g., qualifiers on reference or function
3478/// types). This is the right thing for template instantiation, but
3479/// probably not for other clients.
3480template<typename Derived>
3481QualType
3482TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003483 QualifiedTypeLoc T) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00003484 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCalla2becad2009-10-21 00:40:46 +00003485
John McCall43fed0d2010-11-12 08:19:04 +00003486 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCalla2becad2009-10-21 00:40:46 +00003487 if (Result.isNull())
3488 return QualType();
3489
3490 // Silently suppress qualifiers if the result type can't be qualified.
3491 // FIXME: this is the right thing for template instantiation, but
3492 // probably not for other clients.
3493 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregor577f75a2009-08-04 16:50:30 +00003494 return Result;
Mike Stump1eb44332009-09-09 15:08:12 +00003495
John McCallf85e1932011-06-15 23:02:42 +00003496 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore559ca12011-06-17 22:11:49 +00003497 // resulting type.
3498 if (Quals.hasObjCLifetime()) {
3499 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3500 Quals.removeObjCLifetime();
Douglas Gregor4020cae2011-06-17 23:16:24 +00003501 else if (Result.getObjCLifetime()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00003502 // Objective-C ARC:
Douglas Gregore559ca12011-06-17 22:11:49 +00003503 // A lifetime qualifier applied to a substituted template parameter
3504 // overrides the lifetime qualifier from the template argument.
Douglas Gregor92d13872013-01-17 23:59:28 +00003505 const AutoType *AutoTy;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003506 if (const SubstTemplateTypeParmType *SubstTypeParam
Douglas Gregore559ca12011-06-17 22:11:49 +00003507 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3508 QualType Replacement = SubstTypeParam->getReplacementType();
3509 Qualifiers Qs = Replacement.getQualifiers();
3510 Qs.removeObjCLifetime();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003511 Replacement
Douglas Gregore559ca12011-06-17 22:11:49 +00003512 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3513 Qs);
3514 Result = SemaRef.Context.getSubstTemplateTypeParmType(
Chad Rosier4a9d7952012-08-08 18:46:20 +00003515 SubstTypeParam->getReplacedParameter(),
Douglas Gregore559ca12011-06-17 22:11:49 +00003516 Replacement);
3517 TLB.TypeWasModifiedSafely(Result);
Douglas Gregor92d13872013-01-17 23:59:28 +00003518 } else if ((AutoTy = dyn_cast<AutoType>(Result)) && AutoTy->isDeduced()) {
3519 // 'auto' types behave the same way as template parameters.
3520 QualType Deduced = AutoTy->getDeducedType();
3521 Qualifiers Qs = Deduced.getQualifiers();
3522 Qs.removeObjCLifetime();
3523 Deduced = SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(),
3524 Qs);
Faisal Valifad9e132013-09-26 19:54:12 +00003525 Result = SemaRef.Context.getAutoType(Deduced, AutoTy->isDecltypeAuto(),
3526 AutoTy->isDependentType());
Douglas Gregor92d13872013-01-17 23:59:28 +00003527 TLB.TypeWasModifiedSafely(Result);
Douglas Gregore559ca12011-06-17 22:11:49 +00003528 } else {
Douglas Gregor4020cae2011-06-17 23:16:24 +00003529 // Otherwise, complain about the addition of a qualifier to an
3530 // already-qualified type.
Eli Friedman44ee0a72013-06-07 20:31:48 +00003531 SourceRange R = T.getUnqualifiedLoc().getSourceRange();
Argyrios Kyrtzidisb8b03132011-06-24 00:08:59 +00003532 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregor4020cae2011-06-17 23:16:24 +00003533 << Result << R;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003534
Douglas Gregore559ca12011-06-17 22:11:49 +00003535 Quals.removeObjCLifetime();
3536 }
3537 }
3538 }
John McCall28654742010-06-05 06:41:15 +00003539 if (!Quals.empty()) {
3540 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
Richard Smith9807a2e2013-03-27 23:36:39 +00003541 // BuildQualifiedType might not add qualifiers if they are invalid.
3542 if (Result.hasLocalQualifiers())
3543 TLB.push<QualifiedTypeLoc>(Result);
John McCall28654742010-06-05 06:41:15 +00003544 // No location information to preserve.
3545 }
John McCalla2becad2009-10-21 00:40:46 +00003546
3547 return Result;
3548}
3549
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003550template<typename Derived>
3551TypeLoc
3552TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3553 QualType ObjectType,
3554 NamedDecl *UnqualLookup,
3555 CXXScopeSpec &SS) {
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003556 QualType T = TL.getType();
3557 if (getDerived().AlreadyTransformed(T))
3558 return TL;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003559
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003560 TypeLocBuilder TLB;
3561 QualType Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003562
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003563 if (isa<TemplateSpecializationType>(T)) {
David Blaikie39e6ab42013-02-18 22:06:02 +00003564 TemplateSpecializationTypeLoc SpecTL =
3565 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003566
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003567 TemplateName Template =
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003568 getDerived().TransformTemplateName(SS,
3569 SpecTL.getTypePtr()->getTemplateName(),
3570 SpecTL.getTemplateNameLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003571 ObjectType, UnqualLookup);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003572 if (Template.isNull())
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003573 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003574
3575 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003576 Template);
3577 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie39e6ab42013-02-18 22:06:02 +00003578 DependentTemplateSpecializationTypeLoc SpecTL =
3579 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003580
Douglas Gregora88f09f2011-02-28 17:23:35 +00003581 TemplateName Template
Chad Rosier4a9d7952012-08-08 18:46:20 +00003582 = getDerived().RebuildTemplateName(SS,
3583 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00003584 SpecTL.getTemplateNameLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00003585 ObjectType, UnqualLookup);
Douglas Gregora88f09f2011-02-28 17:23:35 +00003586 if (Template.isNull())
3587 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003588
3589 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregora88f09f2011-02-28 17:23:35 +00003590 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003591 Template,
3592 SS);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003593 } else {
3594 // Nothing special needs to be done for these.
3595 Result = getDerived().TransformType(TLB, TL);
3596 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003597
3598 if (Result.isNull())
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003599 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003600
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003601 return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc();
3602}
3603
Douglas Gregorb71d8212011-03-02 18:32:08 +00003604template<typename Derived>
3605TypeSourceInfo *
3606TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3607 QualType ObjectType,
3608 NamedDecl *UnqualLookup,
3609 CXXScopeSpec &SS) {
3610 // FIXME: Painfully copy-paste from the above!
Chad Rosier4a9d7952012-08-08 18:46:20 +00003611
Douglas Gregorb71d8212011-03-02 18:32:08 +00003612 QualType T = TSInfo->getType();
3613 if (getDerived().AlreadyTransformed(T))
3614 return TSInfo;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003615
Douglas Gregorb71d8212011-03-02 18:32:08 +00003616 TypeLocBuilder TLB;
3617 QualType Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003618
Douglas Gregorb71d8212011-03-02 18:32:08 +00003619 TypeLoc TL = TSInfo->getTypeLoc();
3620 if (isa<TemplateSpecializationType>(T)) {
David Blaikie39e6ab42013-02-18 22:06:02 +00003621 TemplateSpecializationTypeLoc SpecTL =
3622 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003623
Douglas Gregorb71d8212011-03-02 18:32:08 +00003624 TemplateName Template
3625 = getDerived().TransformTemplateName(SS,
3626 SpecTL.getTypePtr()->getTemplateName(),
3627 SpecTL.getTemplateNameLoc(),
3628 ObjectType, UnqualLookup);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003629 if (Template.isNull())
Douglas Gregorb71d8212011-03-02 18:32:08 +00003630 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003631
3632 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregorb71d8212011-03-02 18:32:08 +00003633 Template);
3634 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie39e6ab42013-02-18 22:06:02 +00003635 DependentTemplateSpecializationTypeLoc SpecTL =
3636 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003637
Douglas Gregorb71d8212011-03-02 18:32:08 +00003638 TemplateName Template
Chad Rosier4a9d7952012-08-08 18:46:20 +00003639 = getDerived().RebuildTemplateName(SS,
3640 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00003641 SpecTL.getTemplateNameLoc(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00003642 ObjectType, UnqualLookup);
3643 if (Template.isNull())
3644 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003645
3646 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregorb71d8212011-03-02 18:32:08 +00003647 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003648 Template,
3649 SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00003650 } else {
3651 // Nothing special needs to be done for these.
3652 Result = getDerived().TransformType(TLB, TL);
3653 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003654
3655 if (Result.isNull())
Douglas Gregorb71d8212011-03-02 18:32:08 +00003656 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003657
Douglas Gregorb71d8212011-03-02 18:32:08 +00003658 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3659}
3660
John McCalla2becad2009-10-21 00:40:46 +00003661template <class TyLoc> static inline
3662QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3663 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3664 NewT.setNameLoc(T.getNameLoc());
3665 return T.getType();
3666}
3667
John McCalla2becad2009-10-21 00:40:46 +00003668template<typename Derived>
3669QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003670 BuiltinTypeLoc T) {
Douglas Gregorddf889a2010-01-18 18:04:31 +00003671 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3672 NewT.setBuiltinLoc(T.getBuiltinLoc());
3673 if (T.needsExtraLocalData())
3674 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3675 return T.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003676}
Mike Stump1eb44332009-09-09 15:08:12 +00003677
Douglas Gregor577f75a2009-08-04 16:50:30 +00003678template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003679QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003680 ComplexTypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003681 // FIXME: recurse?
3682 return TransformTypeSpecType(TLB, T);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003683}
Mike Stump1eb44332009-09-09 15:08:12 +00003684
Douglas Gregor577f75a2009-08-04 16:50:30 +00003685template<typename Derived>
Reid Kleckner12df2462013-06-24 17:51:48 +00003686QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
3687 DecayedTypeLoc TL) {
3688 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
3689 if (OriginalType.isNull())
3690 return QualType();
3691
3692 QualType Result = TL.getType();
3693 if (getDerived().AlwaysRebuild() ||
3694 OriginalType != TL.getOriginalLoc().getType())
3695 Result = SemaRef.Context.getDecayedType(OriginalType);
3696 TLB.push<DecayedTypeLoc>(Result);
3697 // Nothing to set for DecayedTypeLoc.
3698 return Result;
3699}
3700
3701template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003702QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003703 PointerTypeLoc TL) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00003704 QualType PointeeType
3705 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003706 if (PointeeType.isNull())
3707 return QualType();
3708
3709 QualType Result = TL.getType();
John McCallc12c5bb2010-05-15 11:32:37 +00003710 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00003711 // A dependent pointer type 'T *' has is being transformed such
3712 // that an Objective-C class type is being replaced for 'T'. The
3713 // resulting pointer type is an ObjCObjectPointerType, not a
3714 // PointerType.
John McCallc12c5bb2010-05-15 11:32:37 +00003715 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003716
John McCallc12c5bb2010-05-15 11:32:37 +00003717 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3718 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003719 return Result;
3720 }
John McCall43fed0d2010-11-12 08:19:04 +00003721
Douglas Gregor92e986e2010-04-22 16:44:27 +00003722 if (getDerived().AlwaysRebuild() ||
3723 PointeeType != TL.getPointeeLoc().getType()) {
3724 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3725 if (Result.isNull())
3726 return QualType();
3727 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003728
John McCallf85e1932011-06-15 23:02:42 +00003729 // Objective-C ARC can add lifetime qualifiers to the type that we're
3730 // pointing to.
3731 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003732
Douglas Gregor92e986e2010-04-22 16:44:27 +00003733 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3734 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003735 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003736}
Mike Stump1eb44332009-09-09 15:08:12 +00003737
3738template<typename Derived>
3739QualType
John McCalla2becad2009-10-21 00:40:46 +00003740TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003741 BlockPointerTypeLoc TL) {
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003742 QualType PointeeType
Chad Rosier4a9d7952012-08-08 18:46:20 +00003743 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3744 if (PointeeType.isNull())
3745 return QualType();
3746
3747 QualType Result = TL.getType();
3748 if (getDerived().AlwaysRebuild() ||
3749 PointeeType != TL.getPointeeLoc().getType()) {
3750 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003751 TL.getSigilLoc());
3752 if (Result.isNull())
3753 return QualType();
3754 }
3755
Douglas Gregor39968ad2010-04-22 16:50:51 +00003756 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003757 NewT.setSigilLoc(TL.getSigilLoc());
3758 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003759}
3760
John McCall85737a72009-10-30 00:06:24 +00003761/// Transforms a reference type. Note that somewhat paradoxically we
3762/// don't care whether the type itself is an l-value type or an r-value
3763/// type; we only care if the type was *written* as an l-value type
3764/// or an r-value type.
3765template<typename Derived>
3766QualType
3767TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003768 ReferenceTypeLoc TL) {
John McCall85737a72009-10-30 00:06:24 +00003769 const ReferenceType *T = TL.getTypePtr();
3770
3771 // Note that this works with the pointee-as-written.
3772 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3773 if (PointeeType.isNull())
3774 return QualType();
3775
3776 QualType Result = TL.getType();
3777 if (getDerived().AlwaysRebuild() ||
3778 PointeeType != T->getPointeeTypeAsWritten()) {
3779 Result = getDerived().RebuildReferenceType(PointeeType,
3780 T->isSpelledAsLValue(),
3781 TL.getSigilLoc());
3782 if (Result.isNull())
3783 return QualType();
3784 }
3785
John McCallf85e1932011-06-15 23:02:42 +00003786 // Objective-C ARC can add lifetime qualifiers to the type that we're
3787 // referring to.
3788 TLB.TypeWasModifiedSafely(
3789 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3790
John McCall85737a72009-10-30 00:06:24 +00003791 // r-value references can be rebuilt as l-value references.
3792 ReferenceTypeLoc NewTL;
3793 if (isa<LValueReferenceType>(Result))
3794 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3795 else
3796 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3797 NewTL.setSigilLoc(TL.getSigilLoc());
3798
3799 return Result;
3800}
3801
Mike Stump1eb44332009-09-09 15:08:12 +00003802template<typename Derived>
3803QualType
John McCalla2becad2009-10-21 00:40:46 +00003804TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003805 LValueReferenceTypeLoc TL) {
3806 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003807}
3808
Mike Stump1eb44332009-09-09 15:08:12 +00003809template<typename Derived>
3810QualType
John McCalla2becad2009-10-21 00:40:46 +00003811TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003812 RValueReferenceTypeLoc TL) {
3813 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003814}
Mike Stump1eb44332009-09-09 15:08:12 +00003815
Douglas Gregor577f75a2009-08-04 16:50:30 +00003816template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003817QualType
John McCalla2becad2009-10-21 00:40:46 +00003818TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003819 MemberPointerTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003820 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003821 if (PointeeType.isNull())
3822 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003823
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003824 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
3825 TypeSourceInfo* NewClsTInfo = 0;
3826 if (OldClsTInfo) {
3827 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3828 if (!NewClsTInfo)
3829 return QualType();
3830 }
3831
3832 const MemberPointerType *T = TL.getTypePtr();
3833 QualType OldClsType = QualType(T->getClass(), 0);
3834 QualType NewClsType;
3835 if (NewClsTInfo)
3836 NewClsType = NewClsTInfo->getType();
3837 else {
3838 NewClsType = getDerived().TransformType(OldClsType);
3839 if (NewClsType.isNull())
3840 return QualType();
3841 }
Mike Stump1eb44332009-09-09 15:08:12 +00003842
John McCalla2becad2009-10-21 00:40:46 +00003843 QualType Result = TL.getType();
3844 if (getDerived().AlwaysRebuild() ||
3845 PointeeType != T->getPointeeType() ||
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003846 NewClsType != OldClsType) {
3847 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall85737a72009-10-30 00:06:24 +00003848 TL.getStarLoc());
John McCalla2becad2009-10-21 00:40:46 +00003849 if (Result.isNull())
3850 return QualType();
3851 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00003852
John McCalla2becad2009-10-21 00:40:46 +00003853 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3854 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003855 NewTL.setClassTInfo(NewClsTInfo);
John McCalla2becad2009-10-21 00:40:46 +00003856
3857 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003858}
3859
Mike Stump1eb44332009-09-09 15:08:12 +00003860template<typename Derived>
3861QualType
John McCalla2becad2009-10-21 00:40:46 +00003862TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003863 ConstantArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003864 const ConstantArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003865 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003866 if (ElementType.isNull())
3867 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003868
John McCalla2becad2009-10-21 00:40:46 +00003869 QualType Result = TL.getType();
3870 if (getDerived().AlwaysRebuild() ||
3871 ElementType != T->getElementType()) {
3872 Result = getDerived().RebuildConstantArrayType(ElementType,
3873 T->getSizeModifier(),
3874 T->getSize(),
John McCall85737a72009-10-30 00:06:24 +00003875 T->getIndexTypeCVRQualifiers(),
3876 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003877 if (Result.isNull())
3878 return QualType();
3879 }
Eli Friedman457a3772012-01-25 22:19:07 +00003880
3881 // We might have either a ConstantArrayType or a VariableArrayType now:
3882 // a ConstantArrayType is allowed to have an element type which is a
3883 // VariableArrayType if the type is dependent. Fortunately, all array
3884 // types have the same location layout.
3885 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCalla2becad2009-10-21 00:40:46 +00003886 NewTL.setLBracketLoc(TL.getLBracketLoc());
3887 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003888
John McCalla2becad2009-10-21 00:40:46 +00003889 Expr *Size = TL.getSizeExpr();
3890 if (Size) {
Richard Smithf6702a32011-12-20 02:08:33 +00003891 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3892 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003893 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
Eli Friedmanac626012012-02-29 03:16:56 +00003894 Size = SemaRef.ActOnConstantExpression(Size).take();
John McCalla2becad2009-10-21 00:40:46 +00003895 }
3896 NewTL.setSizeExpr(Size);
3897
3898 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003899}
Mike Stump1eb44332009-09-09 15:08:12 +00003900
Douglas Gregor577f75a2009-08-04 16:50:30 +00003901template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003902QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCalla2becad2009-10-21 00:40:46 +00003903 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003904 IncompleteArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003905 const IncompleteArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003906 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003907 if (ElementType.isNull())
3908 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003909
John McCalla2becad2009-10-21 00:40:46 +00003910 QualType Result = TL.getType();
3911 if (getDerived().AlwaysRebuild() ||
3912 ElementType != T->getElementType()) {
3913 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00003914 T->getSizeModifier(),
John McCall85737a72009-10-30 00:06:24 +00003915 T->getIndexTypeCVRQualifiers(),
3916 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003917 if (Result.isNull())
3918 return QualType();
3919 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003920
John McCalla2becad2009-10-21 00:40:46 +00003921 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3922 NewTL.setLBracketLoc(TL.getLBracketLoc());
3923 NewTL.setRBracketLoc(TL.getRBracketLoc());
3924 NewTL.setSizeExpr(0);
3925
3926 return Result;
3927}
3928
3929template<typename Derived>
3930QualType
3931TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003932 VariableArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003933 const VariableArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003934 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3935 if (ElementType.isNull())
3936 return QualType();
3937
John McCall60d7b3a2010-08-24 06:29:42 +00003938 ExprResult SizeResult
John McCalla2becad2009-10-21 00:40:46 +00003939 = getDerived().TransformExpr(T->getSizeExpr());
3940 if (SizeResult.isInvalid())
3941 return QualType();
3942
John McCall9ae2f072010-08-23 23:25:46 +00003943 Expr *Size = SizeResult.take();
John McCalla2becad2009-10-21 00:40:46 +00003944
3945 QualType Result = TL.getType();
3946 if (getDerived().AlwaysRebuild() ||
3947 ElementType != T->getElementType() ||
3948 Size != T->getSizeExpr()) {
3949 Result = getDerived().RebuildVariableArrayType(ElementType,
3950 T->getSizeModifier(),
John McCall9ae2f072010-08-23 23:25:46 +00003951 Size,
John McCalla2becad2009-10-21 00:40:46 +00003952 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003953 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003954 if (Result.isNull())
3955 return QualType();
3956 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003957
John McCalla2becad2009-10-21 00:40:46 +00003958 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3959 NewTL.setLBracketLoc(TL.getLBracketLoc());
3960 NewTL.setRBracketLoc(TL.getRBracketLoc());
3961 NewTL.setSizeExpr(Size);
3962
3963 return Result;
3964}
3965
3966template<typename Derived>
3967QualType
3968TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003969 DependentSizedArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003970 const DependentSizedArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003971 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3972 if (ElementType.isNull())
3973 return QualType();
3974
Richard Smithf6702a32011-12-20 02:08:33 +00003975 // Array bounds are constant expressions.
3976 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3977 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003978
John McCall3b657512011-01-19 10:06:00 +00003979 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3980 Expr *origSize = TL.getSizeExpr();
3981 if (!origSize) origSize = T->getSizeExpr();
3982
3983 ExprResult sizeResult
3984 = getDerived().TransformExpr(origSize);
Eli Friedmanac626012012-02-29 03:16:56 +00003985 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall3b657512011-01-19 10:06:00 +00003986 if (sizeResult.isInvalid())
John McCalla2becad2009-10-21 00:40:46 +00003987 return QualType();
3988
John McCall3b657512011-01-19 10:06:00 +00003989 Expr *size = sizeResult.get();
John McCalla2becad2009-10-21 00:40:46 +00003990
3991 QualType Result = TL.getType();
3992 if (getDerived().AlwaysRebuild() ||
3993 ElementType != T->getElementType() ||
John McCall3b657512011-01-19 10:06:00 +00003994 size != origSize) {
John McCalla2becad2009-10-21 00:40:46 +00003995 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3996 T->getSizeModifier(),
John McCall3b657512011-01-19 10:06:00 +00003997 size,
John McCalla2becad2009-10-21 00:40:46 +00003998 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003999 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00004000 if (Result.isNull())
4001 return QualType();
4002 }
John McCalla2becad2009-10-21 00:40:46 +00004003
4004 // We might have any sort of array type now, but fortunately they
4005 // all have the same location layout.
4006 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4007 NewTL.setLBracketLoc(TL.getLBracketLoc());
4008 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall3b657512011-01-19 10:06:00 +00004009 NewTL.setSizeExpr(size);
John McCalla2becad2009-10-21 00:40:46 +00004010
4011 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004012}
Mike Stump1eb44332009-09-09 15:08:12 +00004013
4014template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00004015QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCalla2becad2009-10-21 00:40:46 +00004016 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004017 DependentSizedExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004018 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004019
4020 // FIXME: ext vector locs should be nested
Douglas Gregor577f75a2009-08-04 16:50:30 +00004021 QualType ElementType = getDerived().TransformType(T->getElementType());
4022 if (ElementType.isNull())
4023 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004024
Richard Smithf6702a32011-12-20 02:08:33 +00004025 // Vector sizes are constant expressions.
4026 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4027 Sema::ConstantEvaluated);
Douglas Gregor670444e2009-08-04 22:27:00 +00004028
John McCall60d7b3a2010-08-24 06:29:42 +00004029 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanac626012012-02-29 03:16:56 +00004030 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregor577f75a2009-08-04 16:50:30 +00004031 if (Size.isInvalid())
4032 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004033
John McCalla2becad2009-10-21 00:40:46 +00004034 QualType Result = TL.getType();
4035 if (getDerived().AlwaysRebuild() ||
John McCalleee91c32009-10-23 17:55:45 +00004036 ElementType != T->getElementType() ||
4037 Size.get() != T->getSizeExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00004038 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00004039 Size.take(),
Douglas Gregor577f75a2009-08-04 16:50:30 +00004040 T->getAttributeLoc());
John McCalla2becad2009-10-21 00:40:46 +00004041 if (Result.isNull())
4042 return QualType();
4043 }
John McCalla2becad2009-10-21 00:40:46 +00004044
4045 // Result might be dependent or not.
4046 if (isa<DependentSizedExtVectorType>(Result)) {
4047 DependentSizedExtVectorTypeLoc NewTL
4048 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
4049 NewTL.setNameLoc(TL.getNameLoc());
4050 } else {
4051 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4052 NewTL.setNameLoc(TL.getNameLoc());
4053 }
4054
4055 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004056}
Mike Stump1eb44332009-09-09 15:08:12 +00004057
4058template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004059QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004060 VectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004061 const VectorType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004062 QualType ElementType = getDerived().TransformType(T->getElementType());
4063 if (ElementType.isNull())
4064 return QualType();
4065
John McCalla2becad2009-10-21 00:40:46 +00004066 QualType Result = TL.getType();
4067 if (getDerived().AlwaysRebuild() ||
4068 ElementType != T->getElementType()) {
John Thompson82287d12010-02-05 00:12:22 +00004069 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsone86d78c2010-11-10 21:56:12 +00004070 T->getVectorKind());
John McCalla2becad2009-10-21 00:40:46 +00004071 if (Result.isNull())
4072 return QualType();
4073 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004074
John McCalla2becad2009-10-21 00:40:46 +00004075 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
4076 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00004077
John McCalla2becad2009-10-21 00:40:46 +00004078 return Result;
4079}
4080
4081template<typename Derived>
4082QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004083 ExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004084 const VectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004085 QualType ElementType = getDerived().TransformType(T->getElementType());
4086 if (ElementType.isNull())
4087 return QualType();
4088
4089 QualType Result = TL.getType();
4090 if (getDerived().AlwaysRebuild() ||
4091 ElementType != T->getElementType()) {
4092 Result = getDerived().RebuildExtVectorType(ElementType,
4093 T->getNumElements(),
4094 /*FIXME*/ SourceLocation());
4095 if (Result.isNull())
4096 return QualType();
4097 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004098
John McCalla2becad2009-10-21 00:40:46 +00004099 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4100 NewTL.setNameLoc(TL.getNameLoc());
4101
4102 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004103}
Mike Stump1eb44332009-09-09 15:08:12 +00004104
David Blaikiedc84cd52013-02-20 22:23:23 +00004105template <typename Derived>
4106ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
4107 ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
4108 bool ExpectParameterPack) {
John McCall21ef0fa2010-03-11 09:03:00 +00004109 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004110 TypeSourceInfo *NewDI = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004111
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004112 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004113 // If we're substituting into a pack expansion type and we know the
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004114 // length we want to expand to, just substitute for the pattern.
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004115 TypeLoc OldTL = OldDI->getTypeLoc();
David Blaikie39e6ab42013-02-18 22:06:02 +00004116 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004117
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004118 TypeLocBuilder TLB;
4119 TypeLoc NewTL = OldDI->getTypeLoc();
4120 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier4a9d7952012-08-08 18:46:20 +00004121
4122 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004123 OldExpansionTL.getPatternLoc());
4124 if (Result.isNull())
4125 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004126
4127 Result = RebuildPackExpansionType(Result,
4128 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004129 OldExpansionTL.getEllipsisLoc(),
4130 NumExpansions);
4131 if (Result.isNull())
4132 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004133
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004134 PackExpansionTypeLoc NewExpansionTL
4135 = TLB.push<PackExpansionTypeLoc>(Result);
4136 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
4137 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
4138 } else
4139 NewDI = getDerived().TransformType(OldDI);
John McCall21ef0fa2010-03-11 09:03:00 +00004140 if (!NewDI)
4141 return 0;
4142
John McCallfb44de92011-05-01 22:35:37 +00004143 if (NewDI == OldDI && indexAdjustment == 0)
John McCall21ef0fa2010-03-11 09:03:00 +00004144 return OldParm;
John McCallfb44de92011-05-01 22:35:37 +00004145
4146 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
4147 OldParm->getDeclContext(),
4148 OldParm->getInnerLocStart(),
4149 OldParm->getLocation(),
4150 OldParm->getIdentifier(),
4151 NewDI->getType(),
4152 NewDI,
4153 OldParm->getStorageClass(),
John McCallfb44de92011-05-01 22:35:37 +00004154 /* DefArg */ NULL);
4155 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
4156 OldParm->getFunctionScopeIndex() + indexAdjustment);
4157 return newParm;
John McCall21ef0fa2010-03-11 09:03:00 +00004158}
4159
4160template<typename Derived>
4161bool TreeTransform<Derived>::
Douglas Gregora009b592011-01-07 00:20:55 +00004162 TransformFunctionTypeParams(SourceLocation Loc,
4163 ParmVarDecl **Params, unsigned NumParams,
4164 const QualType *ParamTypes,
Chris Lattner686775d2011-07-20 06:58:45 +00004165 SmallVectorImpl<QualType> &OutParamTypes,
4166 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCallfb44de92011-05-01 22:35:37 +00004167 int indexAdjustment = 0;
4168
Douglas Gregora009b592011-01-07 00:20:55 +00004169 for (unsigned i = 0; i != NumParams; ++i) {
4170 if (ParmVarDecl *OldParm = Params[i]) {
John McCallfb44de92011-05-01 22:35:37 +00004171 assert(OldParm->getFunctionScopeIndex() == i);
4172
David Blaikiedc84cd52013-02-20 22:23:23 +00004173 Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004174 ParmVarDecl *NewParm = 0;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004175 if (OldParm->isParameterPack()) {
4176 // We have a function parameter pack that may need to be expanded.
Chris Lattner686775d2011-07-20 06:58:45 +00004177 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall21ef0fa2010-03-11 09:03:00 +00004178
Douglas Gregor603cfb42011-01-05 23:12:31 +00004179 // Find the parameter packs that could be expanded.
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00004180 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
David Blaikie39e6ab42013-02-18 22:06:02 +00004181 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00004182 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4183 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregor406f98f2011-03-02 02:04:06 +00004184 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4185
Douglas Gregor603cfb42011-01-05 23:12:31 +00004186 // Determine whether we should expand the parameter packs.
4187 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00004188 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00004189 Optional<unsigned> OrigNumExpansions =
4190 ExpansionTL.getTypePtr()->getNumExpansions();
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004191 NumExpansions = OrigNumExpansions;
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00004192 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4193 Pattern.getSourceRange(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004194 Unexpanded,
4195 ShouldExpand,
Douglas Gregord3731192011-01-10 07:32:04 +00004196 RetainExpansion,
4197 NumExpansions)) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004198 return true;
4199 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004200
Douglas Gregor603cfb42011-01-05 23:12:31 +00004201 if (ShouldExpand) {
4202 // Expand the function parameter pack into multiple, separate
4203 // parameters.
Douglas Gregor12c9c002011-01-07 16:43:16 +00004204 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregorcded4f62011-01-14 17:04:44 +00004205 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004206 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004207 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004208 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004209 indexAdjustment++,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004210 OrigNumExpansions,
4211 /*ExpectParameterPack=*/false);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004212 if (!NewParm)
4213 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004214
Douglas Gregora009b592011-01-07 00:20:55 +00004215 OutParamTypes.push_back(NewParm->getType());
4216 if (PVars)
4217 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004218 }
Douglas Gregord3731192011-01-10 07:32:04 +00004219
4220 // If we're supposed to retain a pack expansion, do so by temporarily
4221 // forgetting the partially-substituted parameter pack.
4222 if (RetainExpansion) {
4223 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier4a9d7952012-08-08 18:46:20 +00004224 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004225 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004226 indexAdjustment++,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004227 OrigNumExpansions,
4228 /*ExpectParameterPack=*/false);
Douglas Gregord3731192011-01-10 07:32:04 +00004229 if (!NewParm)
4230 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004231
Douglas Gregord3731192011-01-10 07:32:04 +00004232 OutParamTypes.push_back(NewParm->getType());
4233 if (PVars)
4234 PVars->push_back(NewParm);
4235 }
4236
John McCallfb44de92011-05-01 22:35:37 +00004237 // The next parameter should have the same adjustment as the
4238 // last thing we pushed, but we post-incremented indexAdjustment
4239 // on every push. Also, if we push nothing, the adjustment should
4240 // go down by one.
4241 indexAdjustment--;
4242
Douglas Gregor603cfb42011-01-05 23:12:31 +00004243 // We're done with the pack expansion.
4244 continue;
4245 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004246
4247 // We'll substitute the parameter now without expanding the pack
Douglas Gregor603cfb42011-01-05 23:12:31 +00004248 // expansion.
Douglas Gregor406f98f2011-03-02 02:04:06 +00004249 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4250 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004251 indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004252 NumExpansions,
4253 /*ExpectParameterPack=*/true);
Douglas Gregor406f98f2011-03-02 02:04:06 +00004254 } else {
David Blaikiedc84cd52013-02-20 22:23:23 +00004255 NewParm = getDerived().TransformFunctionTypeParam(
David Blaikie66874fb2013-02-21 01:47:18 +00004256 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004257 }
Douglas Gregor406f98f2011-03-02 02:04:06 +00004258
John McCall21ef0fa2010-03-11 09:03:00 +00004259 if (!NewParm)
4260 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004261
Douglas Gregora009b592011-01-07 00:20:55 +00004262 OutParamTypes.push_back(NewParm->getType());
4263 if (PVars)
4264 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004265 continue;
4266 }
John McCall21ef0fa2010-03-11 09:03:00 +00004267
4268 // Deal with the possibility that we don't have a parameter
4269 // declaration for this parameter.
Douglas Gregora009b592011-01-07 00:20:55 +00004270 QualType OldType = ParamTypes[i];
Douglas Gregor603cfb42011-01-05 23:12:31 +00004271 bool IsPackExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00004272 Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004273 QualType NewType;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004274 if (const PackExpansionType *Expansion
Douglas Gregor603cfb42011-01-05 23:12:31 +00004275 = dyn_cast<PackExpansionType>(OldType)) {
4276 // We have a function parameter pack that may need to be expanded.
4277 QualType Pattern = Expansion->getPattern();
Chris Lattner686775d2011-07-20 06:58:45 +00004278 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004279 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004280
Douglas Gregor603cfb42011-01-05 23:12:31 +00004281 // Determine whether we should expand the parameter packs.
4282 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00004283 bool RetainExpansion = false;
Douglas Gregora009b592011-01-07 00:20:55 +00004284 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004285 Unexpanded,
4286 ShouldExpand,
Douglas Gregord3731192011-01-10 07:32:04 +00004287 RetainExpansion,
4288 NumExpansions)) {
John McCall21ef0fa2010-03-11 09:03:00 +00004289 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004290 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004291
Douglas Gregor603cfb42011-01-05 23:12:31 +00004292 if (ShouldExpand) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004293 // Expand the function parameter pack into multiple, separate
Douglas Gregor603cfb42011-01-05 23:12:31 +00004294 // parameters.
Douglas Gregorcded4f62011-01-14 17:04:44 +00004295 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004296 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4297 QualType NewType = getDerived().TransformType(Pattern);
4298 if (NewType.isNull())
4299 return true;
John McCall21ef0fa2010-03-11 09:03:00 +00004300
Douglas Gregora009b592011-01-07 00:20:55 +00004301 OutParamTypes.push_back(NewType);
4302 if (PVars)
4303 PVars->push_back(0);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004304 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004305
Douglas Gregor603cfb42011-01-05 23:12:31 +00004306 // We're done with the pack expansion.
4307 continue;
4308 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004309
Douglas Gregor3cae5c92011-01-10 20:53:55 +00004310 // If we're supposed to retain a pack expansion, do so by temporarily
4311 // forgetting the partially-substituted parameter pack.
4312 if (RetainExpansion) {
4313 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4314 QualType NewType = getDerived().TransformType(Pattern);
4315 if (NewType.isNull())
4316 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004317
Douglas Gregor3cae5c92011-01-10 20:53:55 +00004318 OutParamTypes.push_back(NewType);
4319 if (PVars)
4320 PVars->push_back(0);
4321 }
Douglas Gregord3731192011-01-10 07:32:04 +00004322
Chad Rosier4a9d7952012-08-08 18:46:20 +00004323 // We'll substitute the parameter now without expanding the pack
Douglas Gregor603cfb42011-01-05 23:12:31 +00004324 // expansion.
4325 OldType = Expansion->getPattern();
4326 IsPackExpansion = true;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004327 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4328 NewType = getDerived().TransformType(OldType);
4329 } else {
4330 NewType = getDerived().TransformType(OldType);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004331 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004332
Douglas Gregor603cfb42011-01-05 23:12:31 +00004333 if (NewType.isNull())
4334 return true;
4335
4336 if (IsPackExpansion)
Douglas Gregorcded4f62011-01-14 17:04:44 +00004337 NewType = getSema().Context.getPackExpansionType(NewType,
4338 NumExpansions);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004339
Douglas Gregora009b592011-01-07 00:20:55 +00004340 OutParamTypes.push_back(NewType);
4341 if (PVars)
4342 PVars->push_back(0);
John McCall21ef0fa2010-03-11 09:03:00 +00004343 }
4344
John McCallfb44de92011-05-01 22:35:37 +00004345#ifndef NDEBUG
4346 if (PVars) {
4347 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4348 if (ParmVarDecl *parm = (*PVars)[i])
4349 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004350 }
John McCallfb44de92011-05-01 22:35:37 +00004351#endif
4352
4353 return false;
4354}
John McCall21ef0fa2010-03-11 09:03:00 +00004355
4356template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004357QualType
John McCalla2becad2009-10-21 00:40:46 +00004358TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004359 FunctionProtoTypeLoc TL) {
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004360 return getDerived().TransformFunctionProtoType(TLB, TL, 0, 0);
4361}
4362
4363template<typename Derived>
4364QualType
4365TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
4366 FunctionProtoTypeLoc TL,
4367 CXXRecordDecl *ThisContext,
4368 unsigned ThisTypeQuals) {
Douglas Gregor7e010a02010-08-31 00:26:14 +00004369 // Transform the parameters and return type.
4370 //
Richard Smithe6975e92012-04-17 00:58:00 +00004371 // We are required to instantiate the params and return type in source order.
Douglas Gregordab60ad2010-10-01 18:44:50 +00004372 // When the function has a trailing return type, we instantiate the
4373 // parameters before the return type, since the return type can then refer
4374 // to the parameters themselves (via decltype, sizeof, etc.).
4375 //
Chris Lattner686775d2011-07-20 06:58:45 +00004376 SmallVector<QualType, 4> ParamTypes;
4377 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCallf4c73712011-01-19 06:33:43 +00004378 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor7e010a02010-08-31 00:26:14 +00004379
Douglas Gregordab60ad2010-10-01 18:44:50 +00004380 QualType ResultType;
4381
Richard Smith9fbf3272012-08-14 22:51:13 +00004382 if (T->hasTrailingReturn()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004383 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
Douglas Gregora009b592011-01-07 00:20:55 +00004384 TL.getParmArray(),
4385 TL.getNumArgs(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004386 TL.getTypePtr()->arg_type_begin(),
Douglas Gregora009b592011-01-07 00:20:55 +00004387 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004388 return QualType();
4389
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004390 {
4391 // C++11 [expr.prim.general]p3:
Chad Rosier4a9d7952012-08-08 18:46:20 +00004392 // If a declaration declares a member function or member function
4393 // template of a class X, the expression this is a prvalue of type
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004394 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier4a9d7952012-08-08 18:46:20 +00004395 // and the end of the function-definition, member-declarator, or
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004396 // declarator.
4397 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004398
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004399 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4400 if (ResultType.isNull())
4401 return QualType();
4402 }
Douglas Gregordab60ad2010-10-01 18:44:50 +00004403 }
4404 else {
4405 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4406 if (ResultType.isNull())
4407 return QualType();
4408
Chad Rosier4a9d7952012-08-08 18:46:20 +00004409 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
Douglas Gregora009b592011-01-07 00:20:55 +00004410 TL.getParmArray(),
4411 TL.getNumArgs(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004412 TL.getTypePtr()->arg_type_begin(),
Douglas Gregora009b592011-01-07 00:20:55 +00004413 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004414 return QualType();
4415 }
4416
Richard Smithe6975e92012-04-17 00:58:00 +00004417 // FIXME: Need to transform the exception-specification too.
4418
John McCalla2becad2009-10-21 00:40:46 +00004419 QualType Result = TL.getType();
4420 if (getDerived().AlwaysRebuild() ||
4421 ResultType != T->getResultType() ||
Douglas Gregorbd5f9f72011-01-07 19:27:47 +00004422 T->getNumArgs() != ParamTypes.size() ||
John McCalla2becad2009-10-21 00:40:46 +00004423 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
Jordan Rosebea522f2013-03-08 21:51:21 +00004424 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes,
Jordan Rose09189892013-03-08 22:25:36 +00004425 T->getExtProtoInfo());
John McCalla2becad2009-10-21 00:40:46 +00004426 if (Result.isNull())
4427 return QualType();
4428 }
Mike Stump1eb44332009-09-09 15:08:12 +00004429
John McCalla2becad2009-10-21 00:40:46 +00004430 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004431 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnara59c0a812012-10-04 21:42:10 +00004432 NewTL.setLParenLoc(TL.getLParenLoc());
4433 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnara796aa442011-03-12 11:17:06 +00004434 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCalla2becad2009-10-21 00:40:46 +00004435 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
4436 NewTL.setArg(i, ParamDecls[i]);
4437
4438 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004439}
Mike Stump1eb44332009-09-09 15:08:12 +00004440
Douglas Gregor577f75a2009-08-04 16:50:30 +00004441template<typename Derived>
4442QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCalla2becad2009-10-21 00:40:46 +00004443 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004444 FunctionNoProtoTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004445 const FunctionNoProtoType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004446 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4447 if (ResultType.isNull())
4448 return QualType();
4449
4450 QualType Result = TL.getType();
4451 if (getDerived().AlwaysRebuild() ||
4452 ResultType != T->getResultType())
4453 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4454
4455 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004456 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnara59c0a812012-10-04 21:42:10 +00004457 NewTL.setLParenLoc(TL.getLParenLoc());
4458 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnara796aa442011-03-12 11:17:06 +00004459 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCalla2becad2009-10-21 00:40:46 +00004460
4461 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004462}
Mike Stump1eb44332009-09-09 15:08:12 +00004463
John McCalled976492009-12-04 22:46:56 +00004464template<typename Derived> QualType
4465TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004466 UnresolvedUsingTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004467 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004468 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCalled976492009-12-04 22:46:56 +00004469 if (!D)
4470 return QualType();
4471
4472 QualType Result = TL.getType();
4473 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4474 Result = getDerived().RebuildUnresolvedUsingType(D);
4475 if (Result.isNull())
4476 return QualType();
4477 }
4478
4479 // We might get an arbitrary type spec type back. We should at
4480 // least always get a type spec type, though.
4481 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4482 NewTL.setNameLoc(TL.getNameLoc());
4483
4484 return Result;
4485}
4486
Douglas Gregor577f75a2009-08-04 16:50:30 +00004487template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004488QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004489 TypedefTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004490 const TypedefType *T = TL.getTypePtr();
Richard Smith162e1c12011-04-15 14:24:37 +00004491 TypedefNameDecl *Typedef
4492 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4493 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004494 if (!Typedef)
4495 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004496
John McCalla2becad2009-10-21 00:40:46 +00004497 QualType Result = TL.getType();
4498 if (getDerived().AlwaysRebuild() ||
4499 Typedef != T->getDecl()) {
4500 Result = getDerived().RebuildTypedefType(Typedef);
4501 if (Result.isNull())
4502 return QualType();
4503 }
Mike Stump1eb44332009-09-09 15:08:12 +00004504
John McCalla2becad2009-10-21 00:40:46 +00004505 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4506 NewTL.setNameLoc(TL.getNameLoc());
4507
4508 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004509}
Mike Stump1eb44332009-09-09 15:08:12 +00004510
Douglas Gregor577f75a2009-08-04 16:50:30 +00004511template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004512QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004513 TypeOfExprTypeLoc TL) {
Douglas Gregor670444e2009-08-04 22:27:00 +00004514 // typeof expressions are not potentially evaluated contexts
Eli Friedman80bfa3d2012-09-26 04:34:21 +00004515 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4516 Sema::ReuseLambdaContextDecl);
Mike Stump1eb44332009-09-09 15:08:12 +00004517
John McCall60d7b3a2010-08-24 06:29:42 +00004518 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004519 if (E.isInvalid())
4520 return QualType();
4521
Eli Friedman72b8b1e2012-02-29 04:03:55 +00004522 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
4523 if (E.isInvalid())
4524 return QualType();
4525
John McCalla2becad2009-10-21 00:40:46 +00004526 QualType Result = TL.getType();
4527 if (getDerived().AlwaysRebuild() ||
John McCallcfb708c2010-01-13 20:03:27 +00004528 E.get() != TL.getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004529 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCalla2becad2009-10-21 00:40:46 +00004530 if (Result.isNull())
4531 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004532 }
John McCalla2becad2009-10-21 00:40:46 +00004533 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004534
John McCalla2becad2009-10-21 00:40:46 +00004535 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004536 NewTL.setTypeofLoc(TL.getTypeofLoc());
4537 NewTL.setLParenLoc(TL.getLParenLoc());
4538 NewTL.setRParenLoc(TL.getRParenLoc());
John McCalla2becad2009-10-21 00:40:46 +00004539
4540 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004541}
Mike Stump1eb44332009-09-09 15:08:12 +00004542
4543template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004544QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004545 TypeOfTypeLoc TL) {
John McCallcfb708c2010-01-13 20:03:27 +00004546 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4547 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4548 if (!New_Under_TI)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004549 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004550
John McCalla2becad2009-10-21 00:40:46 +00004551 QualType Result = TL.getType();
John McCallcfb708c2010-01-13 20:03:27 +00004552 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4553 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCalla2becad2009-10-21 00:40:46 +00004554 if (Result.isNull())
4555 return QualType();
4556 }
Mike Stump1eb44332009-09-09 15:08:12 +00004557
John McCalla2becad2009-10-21 00:40:46 +00004558 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004559 NewTL.setTypeofLoc(TL.getTypeofLoc());
4560 NewTL.setLParenLoc(TL.getLParenLoc());
4561 NewTL.setRParenLoc(TL.getRParenLoc());
4562 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCalla2becad2009-10-21 00:40:46 +00004563
4564 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004565}
Mike Stump1eb44332009-09-09 15:08:12 +00004566
4567template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004568QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004569 DecltypeTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004570 const DecltypeType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004571
Douglas Gregor670444e2009-08-04 22:27:00 +00004572 // decltype expressions are not potentially evaluated contexts
Richard Smith76f3f692012-02-22 02:04:18 +00004573 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, 0,
4574 /*IsDecltype=*/ true);
Mike Stump1eb44332009-09-09 15:08:12 +00004575
John McCall60d7b3a2010-08-24 06:29:42 +00004576 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004577 if (E.isInvalid())
4578 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004579
Richard Smith76f3f692012-02-22 02:04:18 +00004580 E = getSema().ActOnDecltypeExpression(E.take());
4581 if (E.isInvalid())
4582 return QualType();
4583
John McCalla2becad2009-10-21 00:40:46 +00004584 QualType Result = TL.getType();
4585 if (getDerived().AlwaysRebuild() ||
4586 E.get() != T->getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004587 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004588 if (Result.isNull())
4589 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004590 }
John McCalla2becad2009-10-21 00:40:46 +00004591 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004592
John McCalla2becad2009-10-21 00:40:46 +00004593 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4594 NewTL.setNameLoc(TL.getNameLoc());
4595
4596 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004597}
4598
4599template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00004600QualType TreeTransform<Derived>::TransformUnaryTransformType(
4601 TypeLocBuilder &TLB,
4602 UnaryTransformTypeLoc TL) {
4603 QualType Result = TL.getType();
4604 if (Result->isDependentType()) {
4605 const UnaryTransformType *T = TL.getTypePtr();
4606 QualType NewBase =
4607 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4608 Result = getDerived().RebuildUnaryTransformType(NewBase,
4609 T->getUTTKind(),
4610 TL.getKWLoc());
4611 if (Result.isNull())
4612 return QualType();
4613 }
4614
4615 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4616 NewTL.setKWLoc(TL.getKWLoc());
4617 NewTL.setParensRange(TL.getParensRange());
4618 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4619 return Result;
4620}
4621
4622template<typename Derived>
Richard Smith34b41d92011-02-20 03:19:35 +00004623QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4624 AutoTypeLoc TL) {
4625 const AutoType *T = TL.getTypePtr();
4626 QualType OldDeduced = T->getDeducedType();
4627 QualType NewDeduced;
4628 if (!OldDeduced.isNull()) {
4629 NewDeduced = getDerived().TransformType(OldDeduced);
4630 if (NewDeduced.isNull())
4631 return QualType();
4632 }
4633
4634 QualType Result = TL.getType();
Richard Smithdc7a4f52013-04-30 13:56:41 +00004635 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
4636 T->isDependentType()) {
Richard Smitha2c36462013-04-26 16:15:35 +00004637 Result = getDerived().RebuildAutoType(NewDeduced, T->isDecltypeAuto());
Richard Smith34b41d92011-02-20 03:19:35 +00004638 if (Result.isNull())
4639 return QualType();
4640 }
4641
4642 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4643 NewTL.setNameLoc(TL.getNameLoc());
4644
4645 return Result;
4646}
4647
4648template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004649QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004650 RecordTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004651 const RecordType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004652 RecordDecl *Record
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004653 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4654 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004655 if (!Record)
4656 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004657
John McCalla2becad2009-10-21 00:40:46 +00004658 QualType Result = TL.getType();
4659 if (getDerived().AlwaysRebuild() ||
4660 Record != T->getDecl()) {
4661 Result = getDerived().RebuildRecordType(Record);
4662 if (Result.isNull())
4663 return QualType();
4664 }
Mike Stump1eb44332009-09-09 15:08:12 +00004665
John McCalla2becad2009-10-21 00:40:46 +00004666 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4667 NewTL.setNameLoc(TL.getNameLoc());
4668
4669 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004670}
Mike Stump1eb44332009-09-09 15:08:12 +00004671
4672template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004673QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004674 EnumTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004675 const EnumType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004676 EnumDecl *Enum
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004677 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4678 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004679 if (!Enum)
4680 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004681
John McCalla2becad2009-10-21 00:40:46 +00004682 QualType Result = TL.getType();
4683 if (getDerived().AlwaysRebuild() ||
4684 Enum != T->getDecl()) {
4685 Result = getDerived().RebuildEnumType(Enum);
4686 if (Result.isNull())
4687 return QualType();
4688 }
Mike Stump1eb44332009-09-09 15:08:12 +00004689
John McCalla2becad2009-10-21 00:40:46 +00004690 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4691 NewTL.setNameLoc(TL.getNameLoc());
4692
4693 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004694}
John McCall7da24312009-09-05 00:15:47 +00004695
John McCall3cb0ebd2010-03-10 03:28:59 +00004696template<typename Derived>
4697QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4698 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004699 InjectedClassNameTypeLoc TL) {
John McCall3cb0ebd2010-03-10 03:28:59 +00004700 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4701 TL.getTypePtr()->getDecl());
4702 if (!D) return QualType();
4703
4704 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4705 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4706 return T;
4707}
4708
Douglas Gregor577f75a2009-08-04 16:50:30 +00004709template<typename Derived>
4710QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004711 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004712 TemplateTypeParmTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00004713 return TransformTypeSpecType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00004714}
4715
Mike Stump1eb44332009-09-09 15:08:12 +00004716template<typename Derived>
John McCall49a832b2009-10-18 09:09:24 +00004717QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004718 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004719 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004720 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004721
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004722 // Substitute into the replacement type, which itself might involve something
4723 // that needs to be transformed. This only tends to occur with default
4724 // template arguments of template template parameters.
4725 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4726 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4727 if (Replacement.isNull())
4728 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004729
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004730 // Always canonicalize the replacement type.
4731 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4732 QualType Result
Chad Rosier4a9d7952012-08-08 18:46:20 +00004733 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004734 Replacement);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004735
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004736 // Propagate type-source information.
4737 SubstTemplateTypeParmTypeLoc NewTL
4738 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4739 NewTL.setNameLoc(TL.getNameLoc());
4740 return Result;
4741
John McCall49a832b2009-10-18 09:09:24 +00004742}
4743
4744template<typename Derived>
Douglas Gregorc3069d62011-01-14 02:55:32 +00004745QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4746 TypeLocBuilder &TLB,
4747 SubstTemplateTypeParmPackTypeLoc TL) {
4748 return TransformTypeSpecType(TLB, TL);
4749}
4750
4751template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00004752QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00004753 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004754 TemplateSpecializationTypeLoc TL) {
John McCall833ca992009-10-29 08:12:44 +00004755 const TemplateSpecializationType *T = TL.getTypePtr();
4756
Douglas Gregor1d752d72011-03-02 18:46:51 +00004757 // The nested-name-specifier never matters in a TemplateSpecializationType,
4758 // because we can't have a dependent nested-name-specifier anyway.
4759 CXXScopeSpec SS;
Mike Stump1eb44332009-09-09 15:08:12 +00004760 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00004761 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4762 TL.getTemplateNameLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004763 if (Template.isNull())
4764 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004765
John McCall43fed0d2010-11-12 08:19:04 +00004766 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4767}
4768
Eli Friedmanb001de72011-10-06 23:00:33 +00004769template<typename Derived>
4770QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
4771 AtomicTypeLoc TL) {
4772 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
4773 if (ValueType.isNull())
4774 return QualType();
4775
4776 QualType Result = TL.getType();
4777 if (getDerived().AlwaysRebuild() ||
4778 ValueType != TL.getValueLoc().getType()) {
4779 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
4780 if (Result.isNull())
4781 return QualType();
4782 }
4783
4784 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
4785 NewTL.setKWLoc(TL.getKWLoc());
4786 NewTL.setLParenLoc(TL.getLParenLoc());
4787 NewTL.setRParenLoc(TL.getRParenLoc());
4788
4789 return Result;
4790}
4791
Chad Rosier4a9d7952012-08-08 18:46:20 +00004792 /// \brief Simple iterator that traverses the template arguments in a
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004793 /// container that provides a \c getArgLoc() member function.
4794 ///
4795 /// This iterator is intended to be used with the iterator form of
4796 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4797 template<typename ArgLocContainer>
4798 class TemplateArgumentLocContainerIterator {
4799 ArgLocContainer *Container;
4800 unsigned Index;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004801
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004802 public:
4803 typedef TemplateArgumentLoc value_type;
4804 typedef TemplateArgumentLoc reference;
4805 typedef int difference_type;
4806 typedef std::input_iterator_tag iterator_category;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004807
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004808 class pointer {
4809 TemplateArgumentLoc Arg;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004810
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004811 public:
4812 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004813
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004814 const TemplateArgumentLoc *operator->() const {
4815 return &Arg;
4816 }
4817 };
Chad Rosier4a9d7952012-08-08 18:46:20 +00004818
4819
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004820 TemplateArgumentLocContainerIterator() {}
Chad Rosier4a9d7952012-08-08 18:46:20 +00004821
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004822 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4823 unsigned Index)
4824 : Container(&Container), Index(Index) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004825
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004826 TemplateArgumentLocContainerIterator &operator++() {
4827 ++Index;
4828 return *this;
4829 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004830
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004831 TemplateArgumentLocContainerIterator operator++(int) {
4832 TemplateArgumentLocContainerIterator Old(*this);
4833 ++(*this);
4834 return Old;
4835 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004836
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004837 TemplateArgumentLoc operator*() const {
4838 return Container->getArgLoc(Index);
4839 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004840
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004841 pointer operator->() const {
4842 return pointer(Container->getArgLoc(Index));
4843 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004844
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004845 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004846 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004847 return X.Container == Y.Container && X.Index == Y.Index;
4848 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004849
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004850 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004851 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004852 return !(X == Y);
4853 }
4854 };
Chad Rosier4a9d7952012-08-08 18:46:20 +00004855
4856
John McCall43fed0d2010-11-12 08:19:04 +00004857template <typename Derived>
4858QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4859 TypeLocBuilder &TLB,
4860 TemplateSpecializationTypeLoc TL,
4861 TemplateName Template) {
John McCalld5532b62009-11-23 01:53:49 +00004862 TemplateArgumentListInfo NewTemplateArgs;
4863 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4864 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004865 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4866 ArgIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004867 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004868 ArgIterator(TL, TL.getNumArgs()),
4869 NewTemplateArgs))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00004870 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004871
John McCall833ca992009-10-29 08:12:44 +00004872 // FIXME: maybe don't rebuild if all the template arguments are the same.
4873
4874 QualType Result =
4875 getDerived().RebuildTemplateSpecializationType(Template,
4876 TL.getTemplateNameLoc(),
John McCalld5532b62009-11-23 01:53:49 +00004877 NewTemplateArgs);
John McCall833ca992009-10-29 08:12:44 +00004878
4879 if (!Result.isNull()) {
Richard Smith3e4c6c42011-05-05 21:57:07 +00004880 // Specializations of template template parameters are represented as
4881 // TemplateSpecializationTypes, and substitution of type alias templates
4882 // within a dependent context can transform them into
4883 // DependentTemplateSpecializationTypes.
4884 if (isa<DependentTemplateSpecializationType>(Result)) {
4885 DependentTemplateSpecializationTypeLoc NewTL
4886 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004887 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3e4c6c42011-05-05 21:57:07 +00004888 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnara66581d42012-02-06 22:45:07 +00004889 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004890 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3e4c6c42011-05-05 21:57:07 +00004891 NewTL.setLAngleLoc(TL.getLAngleLoc());
4892 NewTL.setRAngleLoc(TL.getRAngleLoc());
4893 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4894 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4895 return Result;
4896 }
4897
John McCall833ca992009-10-29 08:12:44 +00004898 TemplateSpecializationTypeLoc NewTL
4899 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004900 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall833ca992009-10-29 08:12:44 +00004901 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4902 NewTL.setLAngleLoc(TL.getLAngleLoc());
4903 NewTL.setRAngleLoc(TL.getRAngleLoc());
4904 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4905 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004906 }
Mike Stump1eb44332009-09-09 15:08:12 +00004907
John McCall833ca992009-10-29 08:12:44 +00004908 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004909}
Mike Stump1eb44332009-09-09 15:08:12 +00004910
Douglas Gregora88f09f2011-02-28 17:23:35 +00004911template <typename Derived>
4912QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4913 TypeLocBuilder &TLB,
4914 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00004915 TemplateName Template,
4916 CXXScopeSpec &SS) {
Douglas Gregora88f09f2011-02-28 17:23:35 +00004917 TemplateArgumentListInfo NewTemplateArgs;
4918 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4919 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4920 typedef TemplateArgumentLocContainerIterator<
4921 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004922 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregora88f09f2011-02-28 17:23:35 +00004923 ArgIterator(TL, TL.getNumArgs()),
4924 NewTemplateArgs))
4925 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004926
Douglas Gregora88f09f2011-02-28 17:23:35 +00004927 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier4a9d7952012-08-08 18:46:20 +00004928
Douglas Gregora88f09f2011-02-28 17:23:35 +00004929 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4930 QualType Result
4931 = getSema().Context.getDependentTemplateSpecializationType(
4932 TL.getTypePtr()->getKeyword(),
4933 DTN->getQualifier(),
4934 DTN->getIdentifier(),
4935 NewTemplateArgs);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004936
Douglas Gregora88f09f2011-02-28 17:23:35 +00004937 DependentTemplateSpecializationTypeLoc NewTL
4938 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004939 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004940 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnara66581d42012-02-06 22:45:07 +00004941 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004942 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora88f09f2011-02-28 17:23:35 +00004943 NewTL.setLAngleLoc(TL.getLAngleLoc());
4944 NewTL.setRAngleLoc(TL.getRAngleLoc());
4945 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4946 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4947 return Result;
4948 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004949
4950 QualType Result
Douglas Gregora88f09f2011-02-28 17:23:35 +00004951 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004952 TL.getTemplateNameLoc(),
Douglas Gregora88f09f2011-02-28 17:23:35 +00004953 NewTemplateArgs);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004954
Douglas Gregora88f09f2011-02-28 17:23:35 +00004955 if (!Result.isNull()) {
4956 /// FIXME: Wrap this in an elaborated-type-specifier?
4957 TemplateSpecializationTypeLoc NewTL
4958 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara66581d42012-02-06 22:45:07 +00004959 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004960 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora88f09f2011-02-28 17:23:35 +00004961 NewTL.setLAngleLoc(TL.getLAngleLoc());
4962 NewTL.setRAngleLoc(TL.getRAngleLoc());
4963 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4964 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4965 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004966
Douglas Gregora88f09f2011-02-28 17:23:35 +00004967 return Result;
4968}
4969
Mike Stump1eb44332009-09-09 15:08:12 +00004970template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004971QualType
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004972TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004973 ElaboratedTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004974 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004975
Douglas Gregor9e876872011-03-01 18:12:44 +00004976 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004977 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor9e876872011-03-01 18:12:44 +00004978 if (TL.getQualifierLoc()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004979 QualifierLoc
Douglas Gregor9e876872011-03-01 18:12:44 +00004980 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4981 if (!QualifierLoc)
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004982 return QualType();
4983 }
Mike Stump1eb44332009-09-09 15:08:12 +00004984
John McCall43fed0d2010-11-12 08:19:04 +00004985 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4986 if (NamedT.isNull())
4987 return QualType();
Daniel Dunbara63db842010-05-14 16:34:09 +00004988
Richard Smith3e4c6c42011-05-05 21:57:07 +00004989 // C++0x [dcl.type.elab]p2:
4990 // If the identifier resolves to a typedef-name or the simple-template-id
4991 // resolves to an alias template specialization, the
4992 // elaborated-type-specifier is ill-formed.
Richard Smith18041742011-05-14 15:04:18 +00004993 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
4994 if (const TemplateSpecializationType *TST =
4995 NamedT->getAs<TemplateSpecializationType>()) {
4996 TemplateName Template = TST->getTemplateName();
4997 if (TypeAliasTemplateDecl *TAT =
4998 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
4999 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
5000 diag::err_tag_reference_non_tag) << 4;
5001 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
5002 }
Richard Smith3e4c6c42011-05-05 21:57:07 +00005003 }
5004 }
5005
John McCalla2becad2009-10-21 00:40:46 +00005006 QualType Result = TL.getType();
5007 if (getDerived().AlwaysRebuild() ||
Douglas Gregor9e876872011-03-01 18:12:44 +00005008 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00005009 NamedT != T->getNamedType()) {
Abramo Bagnara38a42912012-02-06 19:09:27 +00005010 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00005011 T->getKeyword(),
Douglas Gregor9e876872011-03-01 18:12:44 +00005012 QualifierLoc, NamedT);
John McCalla2becad2009-10-21 00:40:46 +00005013 if (Result.isNull())
5014 return QualType();
5015 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00005016
Abramo Bagnara465d41b2010-05-11 21:36:43 +00005017 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00005018 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00005019 NewTL.setQualifierLoc(QualifierLoc);
John McCalla2becad2009-10-21 00:40:46 +00005020 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00005021}
Mike Stump1eb44332009-09-09 15:08:12 +00005022
5023template<typename Derived>
John McCall9d156a72011-01-06 01:58:22 +00005024QualType TreeTransform<Derived>::TransformAttributedType(
5025 TypeLocBuilder &TLB,
5026 AttributedTypeLoc TL) {
5027 const AttributedType *oldType = TL.getTypePtr();
5028 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
5029 if (modifiedType.isNull())
5030 return QualType();
5031
5032 QualType result = TL.getType();
5033
5034 // FIXME: dependent operand expressions?
5035 if (getDerived().AlwaysRebuild() ||
5036 modifiedType != oldType->getModifiedType()) {
5037 // TODO: this is really lame; we should really be rebuilding the
5038 // equivalent type from first principles.
5039 QualType equivalentType
5040 = getDerived().TransformType(oldType->getEquivalentType());
5041 if (equivalentType.isNull())
5042 return QualType();
5043 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
5044 modifiedType,
5045 equivalentType);
5046 }
5047
5048 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
5049 newTL.setAttrNameLoc(TL.getAttrNameLoc());
5050 if (TL.hasAttrOperand())
5051 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5052 if (TL.hasAttrExprOperand())
5053 newTL.setAttrExprOperand(TL.getAttrExprOperand());
5054 else if (TL.hasAttrEnumOperand())
5055 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
5056
5057 return result;
5058}
5059
5060template<typename Derived>
Abramo Bagnara075f8f12010-12-10 16:29:40 +00005061QualType
5062TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
5063 ParenTypeLoc TL) {
5064 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
5065 if (Inner.isNull())
5066 return QualType();
5067
5068 QualType Result = TL.getType();
5069 if (getDerived().AlwaysRebuild() ||
5070 Inner != TL.getInnerLoc().getType()) {
5071 Result = getDerived().RebuildParenType(Inner);
5072 if (Result.isNull())
5073 return QualType();
5074 }
5075
5076 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
5077 NewTL.setLParenLoc(TL.getLParenLoc());
5078 NewTL.setRParenLoc(TL.getRParenLoc());
5079 return Result;
5080}
5081
5082template<typename Derived>
Douglas Gregor4714c122010-03-31 17:34:00 +00005083QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005084 DependentNameTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00005085 const DependentNameType *T = TL.getTypePtr();
John McCall833ca992009-10-29 08:12:44 +00005086
Douglas Gregor2494dd02011-03-01 01:34:45 +00005087 NestedNameSpecifierLoc QualifierLoc
5088 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5089 if (!QualifierLoc)
Douglas Gregor577f75a2009-08-04 16:50:30 +00005090 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00005091
John McCall33500952010-06-11 00:33:02 +00005092 QualType Result
Douglas Gregor2494dd02011-03-01 01:34:45 +00005093 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara38a42912012-02-06 19:09:27 +00005094 TL.getElaboratedKeywordLoc(),
Douglas Gregor2494dd02011-03-01 01:34:45 +00005095 QualifierLoc,
5096 T->getIdentifier(),
John McCall33500952010-06-11 00:33:02 +00005097 TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00005098 if (Result.isNull())
5099 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00005100
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00005101 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
5102 QualType NamedT = ElabT->getNamedType();
John McCall33500952010-06-11 00:33:02 +00005103 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
5104
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00005105 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00005106 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00005107 NewTL.setQualifierLoc(QualifierLoc);
John McCall33500952010-06-11 00:33:02 +00005108 } else {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00005109 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00005110 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor2494dd02011-03-01 01:34:45 +00005111 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00005112 NewTL.setNameLoc(TL.getNameLoc());
5113 }
John McCalla2becad2009-10-21 00:40:46 +00005114 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00005115}
Mike Stump1eb44332009-09-09 15:08:12 +00005116
Douglas Gregor577f75a2009-08-04 16:50:30 +00005117template<typename Derived>
John McCall33500952010-06-11 00:33:02 +00005118QualType TreeTransform<Derived>::
5119 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005120 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005121 NestedNameSpecifierLoc QualifierLoc;
5122 if (TL.getQualifierLoc()) {
5123 QualifierLoc
5124 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5125 if (!QualifierLoc)
Douglas Gregora88f09f2011-02-28 17:23:35 +00005126 return QualType();
5127 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005128
John McCall43fed0d2010-11-12 08:19:04 +00005129 return getDerived()
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005130 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall43fed0d2010-11-12 08:19:04 +00005131}
5132
5133template<typename Derived>
5134QualType TreeTransform<Derived>::
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005135TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
5136 DependentTemplateSpecializationTypeLoc TL,
5137 NestedNameSpecifierLoc QualifierLoc) {
5138 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005139
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005140 TemplateArgumentListInfo NewTemplateArgs;
5141 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5142 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005143
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005144 typedef TemplateArgumentLocContainerIterator<
5145 DependentTemplateSpecializationTypeLoc> ArgIterator;
5146 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5147 ArgIterator(TL, TL.getNumArgs()),
5148 NewTemplateArgs))
5149 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005150
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005151 QualType Result
5152 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
5153 QualifierLoc,
5154 T->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005155 TL.getTemplateNameLoc(),
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005156 NewTemplateArgs);
5157 if (Result.isNull())
5158 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005159
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005160 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
5161 QualType NamedT = ElabT->getNamedType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005162
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005163 // Copy information relevant to the template specialization.
5164 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005165 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005166 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005167 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005168 NamedTL.setLAngleLoc(TL.getLAngleLoc());
5169 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005170 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005171 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005172
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005173 // Copy information relevant to the elaborated type.
5174 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00005175 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005176 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005177 } else if (isa<DependentTemplateSpecializationType>(Result)) {
5178 DependentTemplateSpecializationTypeLoc SpecTL
5179 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005180 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005181 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005182 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005183 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005184 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5185 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005186 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005187 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005188 } else {
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005189 TemplateSpecializationTypeLoc SpecTL
5190 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005191 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005192 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005193 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5194 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005195 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005196 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005197 }
5198 return Result;
5199}
5200
5201template<typename Derived>
Douglas Gregor7536dd52010-12-20 02:24:11 +00005202QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5203 PackExpansionTypeLoc TL) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005204 QualType Pattern
5205 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005206 if (Pattern.isNull())
5207 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005208
5209 QualType Result = TL.getType();
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005210 if (getDerived().AlwaysRebuild() ||
5211 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005212 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005213 TL.getPatternLoc().getSourceRange(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00005214 TL.getEllipsisLoc(),
5215 TL.getTypePtr()->getNumExpansions());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005216 if (Result.isNull())
5217 return QualType();
5218 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005219
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005220 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5221 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5222 return Result;
Douglas Gregor7536dd52010-12-20 02:24:11 +00005223}
5224
5225template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00005226QualType
5227TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005228 ObjCInterfaceTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00005229 // ObjCInterfaceType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00005230 TLB.pushFullCopy(TL);
5231 return TL.getType();
5232}
5233
5234template<typename Derived>
5235QualType
5236TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005237 ObjCObjectTypeLoc TL) {
John McCallc12c5bb2010-05-15 11:32:37 +00005238 // ObjCObjectType is never dependent.
5239 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00005240 return TL.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00005241}
Mike Stump1eb44332009-09-09 15:08:12 +00005242
5243template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00005244QualType
5245TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005246 ObjCObjectPointerTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00005247 // ObjCObjectPointerType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00005248 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00005249 return TL.getType();
Argyrios Kyrtzidis24fab412009-09-29 19:42:55 +00005250}
5251
Douglas Gregor577f75a2009-08-04 16:50:30 +00005252//===----------------------------------------------------------------------===//
Douglas Gregor43959a92009-08-20 07:17:43 +00005253// Statement transformation
5254//===----------------------------------------------------------------------===//
5255template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005256StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005257TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005258 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005259}
5260
5261template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005262StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005263TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
5264 return getDerived().TransformCompoundStmt(S, false);
5265}
5266
5267template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005268StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005269TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregor43959a92009-08-20 07:17:43 +00005270 bool IsStmtExpr) {
Dmitri Gribenko625bb562012-02-14 22:14:32 +00005271 Sema::CompoundScopeRAII CompoundScope(getSema());
5272
John McCall7114cba2010-08-27 19:56:05 +00005273 bool SubStmtInvalid = false;
Douglas Gregor43959a92009-08-20 07:17:43 +00005274 bool SubStmtChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005275 SmallVector<Stmt*, 8> Statements;
Douglas Gregor43959a92009-08-20 07:17:43 +00005276 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
5277 B != BEnd; ++B) {
John McCall60d7b3a2010-08-24 06:29:42 +00005278 StmtResult Result = getDerived().TransformStmt(*B);
John McCall7114cba2010-08-27 19:56:05 +00005279 if (Result.isInvalid()) {
5280 // Immediately fail if this was a DeclStmt, since it's very
5281 // likely that this will cause problems for future statements.
5282 if (isa<DeclStmt>(*B))
5283 return StmtError();
5284
5285 // Otherwise, just keep processing substatements and fail later.
5286 SubStmtInvalid = true;
5287 continue;
5288 }
Mike Stump1eb44332009-09-09 15:08:12 +00005289
Douglas Gregor43959a92009-08-20 07:17:43 +00005290 SubStmtChanged = SubStmtChanged || Result.get() != *B;
5291 Statements.push_back(Result.takeAs<Stmt>());
5292 }
Mike Stump1eb44332009-09-09 15:08:12 +00005293
John McCall7114cba2010-08-27 19:56:05 +00005294 if (SubStmtInvalid)
5295 return StmtError();
5296
Douglas Gregor43959a92009-08-20 07:17:43 +00005297 if (!getDerived().AlwaysRebuild() &&
5298 !SubStmtChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005299 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005300
5301 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00005302 Statements,
Douglas Gregor43959a92009-08-20 07:17:43 +00005303 S->getRBracLoc(),
5304 IsStmtExpr);
5305}
Mike Stump1eb44332009-09-09 15:08:12 +00005306
Douglas Gregor43959a92009-08-20 07:17:43 +00005307template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005308StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005309TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005310 ExprResult LHS, RHS;
Eli Friedman264c1f82009-11-19 03:14:00 +00005311 {
Eli Friedman6b3014b2012-01-18 02:54:10 +00005312 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5313 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00005314
Eli Friedman264c1f82009-11-19 03:14:00 +00005315 // Transform the left-hand case value.
5316 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanac626012012-02-29 03:16:56 +00005317 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman264c1f82009-11-19 03:14:00 +00005318 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005319 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005320
Eli Friedman264c1f82009-11-19 03:14:00 +00005321 // Transform the right-hand case value (for the GNU case-range extension).
5322 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanac626012012-02-29 03:16:56 +00005323 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman264c1f82009-11-19 03:14:00 +00005324 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005325 return StmtError();
Eli Friedman264c1f82009-11-19 03:14:00 +00005326 }
Mike Stump1eb44332009-09-09 15:08:12 +00005327
Douglas Gregor43959a92009-08-20 07:17:43 +00005328 // Build the case statement.
5329 // Case statements are always rebuilt so that they will attached to their
5330 // transformed switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005331 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005332 LHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005333 S->getEllipsisLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005334 RHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005335 S->getColonLoc());
5336 if (Case.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005337 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005338
Douglas Gregor43959a92009-08-20 07:17:43 +00005339 // Transform the statement following the case
John McCall60d7b3a2010-08-24 06:29:42 +00005340 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005341 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005342 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005343
Douglas Gregor43959a92009-08-20 07:17:43 +00005344 // Attach the body to the case statement
John McCall9ae2f072010-08-23 23:25:46 +00005345 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005346}
5347
5348template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005349StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005350TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005351 // Transform the statement following the default case
John McCall60d7b3a2010-08-24 06:29:42 +00005352 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005353 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005354 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005355
Douglas Gregor43959a92009-08-20 07:17:43 +00005356 // Default statements are always rebuilt
5357 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005358 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005359}
Mike Stump1eb44332009-09-09 15:08:12 +00005360
Douglas Gregor43959a92009-08-20 07:17:43 +00005361template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005362StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005363TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005364 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005365 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005366 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005367
Chris Lattner57ad3782011-02-17 20:34:02 +00005368 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5369 S->getDecl());
5370 if (!LD)
5371 return StmtError();
Richard Smith534986f2012-04-14 00:33:13 +00005372
5373
Douglas Gregor43959a92009-08-20 07:17:43 +00005374 // FIXME: Pass the real colon location in.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00005375 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005376 cast<LabelDecl>(LD), SourceLocation(),
5377 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005378}
Mike Stump1eb44332009-09-09 15:08:12 +00005379
Douglas Gregor43959a92009-08-20 07:17:43 +00005380template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005381StmtResult
Richard Smith534986f2012-04-14 00:33:13 +00005382TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
5383 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5384 if (SubStmt.isInvalid())
5385 return StmtError();
5386
5387 // TODO: transform attributes
5388 if (SubStmt.get() == S->getSubStmt() /* && attrs are the same */)
5389 return S;
5390
5391 return getDerived().RebuildAttributedStmt(S->getAttrLoc(),
5392 S->getAttrs(),
5393 SubStmt.get());
5394}
5395
5396template<typename Derived>
5397StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005398TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005399 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005400 ExprResult Cond;
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005401 VarDecl *ConditionVar = 0;
5402 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005403 ConditionVar
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005404 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005405 getDerived().TransformDefinition(
5406 S->getConditionVariable()->getLocation(),
5407 S->getConditionVariable()));
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005408 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005409 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005410 } else {
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005411 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005412
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005413 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005414 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005415
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005416 // Convert the condition to a boolean value.
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005417 if (S->getCond()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005418 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005419 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005420 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005421 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005422
John McCall9ae2f072010-08-23 23:25:46 +00005423 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005424 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005425 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005426
John McCall9ae2f072010-08-23 23:25:46 +00005427 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5428 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005429 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005430
Douglas Gregor43959a92009-08-20 07:17:43 +00005431 // Transform the "then" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005432 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregor43959a92009-08-20 07:17:43 +00005433 if (Then.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005434 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005435
Douglas Gregor43959a92009-08-20 07:17:43 +00005436 // Transform the "else" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005437 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregor43959a92009-08-20 07:17:43 +00005438 if (Else.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() &&
John McCall9ae2f072010-08-23 23:25:46 +00005442 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005443 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005444 Then.get() == S->getThen() &&
5445 Else.get() == S->getElse())
John McCall3fa5cae2010-10-26 07:05:15 +00005446 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005447
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005448 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00005449 Then.get(),
John McCall9ae2f072010-08-23 23:25:46 +00005450 S->getElseLoc(), Else.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>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005456 // Transform the condition.
John McCall60d7b3a2010-08-24 06:29:42 +00005457 ExprResult Cond;
Douglas Gregord3d53012009-11-24 17:07:59 +00005458 VarDecl *ConditionVar = 0;
5459 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005460 ConditionVar
Douglas Gregord3d53012009-11-24 17:07:59 +00005461 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005462 getDerived().TransformDefinition(
5463 S->getConditionVariable()->getLocation(),
5464 S->getConditionVariable()));
Douglas Gregord3d53012009-11-24 17:07:59 +00005465 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005466 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005467 } else {
Douglas Gregord3d53012009-11-24 17:07:59 +00005468 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005469
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005470 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005471 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005472 }
Mike Stump1eb44332009-09-09 15:08:12 +00005473
Douglas Gregor43959a92009-08-20 07:17:43 +00005474 // Rebuild the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005475 StmtResult Switch
John McCall9ae2f072010-08-23 23:25:46 +00005476 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregor586596f2010-05-06 17:25:47 +00005477 ConditionVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00005478 if (Switch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005479 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005480
Douglas Gregor43959a92009-08-20 07:17:43 +00005481 // Transform the body of the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005482 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005483 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005484 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005485
Douglas Gregor43959a92009-08-20 07:17:43 +00005486 // Complete the switch statement.
John McCall9ae2f072010-08-23 23:25:46 +00005487 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5488 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005489}
Mike Stump1eb44332009-09-09 15:08:12 +00005490
Douglas Gregor43959a92009-08-20 07:17:43 +00005491template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005492StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005493TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005494 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005495 ExprResult Cond;
Douglas Gregor5656e142009-11-24 21:15:44 +00005496 VarDecl *ConditionVar = 0;
5497 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005498 ConditionVar
Douglas Gregor5656e142009-11-24 21:15:44 +00005499 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005500 getDerived().TransformDefinition(
5501 S->getConditionVariable()->getLocation(),
5502 S->getConditionVariable()));
Douglas Gregor5656e142009-11-24 21:15:44 +00005503 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005504 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005505 } else {
Douglas Gregor5656e142009-11-24 21:15:44 +00005506 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005507
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005508 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005509 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005510
5511 if (S->getCond()) {
5512 // Convert the condition to a boolean value.
Chad Rosier4a9d7952012-08-08 18:46:20 +00005513 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005514 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005515 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005516 return StmtError();
John McCall9ae2f072010-08-23 23:25:46 +00005517 Cond = CondE;
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005518 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005519 }
Mike Stump1eb44332009-09-09 15:08:12 +00005520
John McCall9ae2f072010-08-23 23:25:46 +00005521 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5522 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005523 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005524
Douglas Gregor43959a92009-08-20 07:17:43 +00005525 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005526 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005527 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005528 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005529
Douglas Gregor43959a92009-08-20 07:17:43 +00005530 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005531 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005532 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005533 Body.get() == S->getBody())
John McCall9ae2f072010-08-23 23:25:46 +00005534 return Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005535
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005536 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCall9ae2f072010-08-23 23:25:46 +00005537 ConditionVar, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005538}
Mike Stump1eb44332009-09-09 15:08:12 +00005539
Douglas Gregor43959a92009-08-20 07:17:43 +00005540template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005541StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005542TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005543 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005544 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005545 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005546 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005547
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005548 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005549 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005550 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005551 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005552
Douglas Gregor43959a92009-08-20 07:17:43 +00005553 if (!getDerived().AlwaysRebuild() &&
5554 Cond.get() == S->getCond() &&
5555 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005556 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005557
John McCall9ae2f072010-08-23 23:25:46 +00005558 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5559 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005560 S->getRParenLoc());
5561}
Mike Stump1eb44332009-09-09 15:08:12 +00005562
Douglas Gregor43959a92009-08-20 07:17:43 +00005563template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005564StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005565TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005566 // Transform the initialization statement
John McCall60d7b3a2010-08-24 06:29:42 +00005567 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregor43959a92009-08-20 07:17:43 +00005568 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005569 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005570
Douglas Gregor43959a92009-08-20 07:17:43 +00005571 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005572 ExprResult Cond;
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005573 VarDecl *ConditionVar = 0;
5574 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005575 ConditionVar
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005576 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005577 getDerived().TransformDefinition(
5578 S->getConditionVariable()->getLocation(),
5579 S->getConditionVariable()));
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005580 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005581 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005582 } else {
5583 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005584
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005585 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005586 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005587
5588 if (S->getCond()) {
5589 // Convert the condition to a boolean value.
Chad Rosier4a9d7952012-08-08 18:46:20 +00005590 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005591 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005592 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005593 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005594
John McCall9ae2f072010-08-23 23:25:46 +00005595 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005596 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005597 }
Mike Stump1eb44332009-09-09 15:08:12 +00005598
Chad Rosier4a9d7952012-08-08 18:46:20 +00005599 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
John McCall9ae2f072010-08-23 23:25:46 +00005600 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005601 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005602
Douglas Gregor43959a92009-08-20 07:17:43 +00005603 // Transform the increment
John McCall60d7b3a2010-08-24 06:29:42 +00005604 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005605 if (Inc.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005606 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005607
Richard Smith41956372013-01-14 22:39:08 +00005608 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
John McCall9ae2f072010-08-23 23:25:46 +00005609 if (S->getInc() && !FullInc.get())
John McCallf312b1e2010-08-26 23:41:50 +00005610 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005611
Douglas Gregor43959a92009-08-20 07:17:43 +00005612 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005613 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005614 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005615 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005616
Douglas Gregor43959a92009-08-20 07:17:43 +00005617 if (!getDerived().AlwaysRebuild() &&
5618 Init.get() == S->getInit() &&
John McCall9ae2f072010-08-23 23:25:46 +00005619 FullCond.get() == S->getCond() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005620 Inc.get() == S->getInc() &&
5621 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005622 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005623
Douglas Gregor43959a92009-08-20 07:17:43 +00005624 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005625 Init.get(), FullCond, ConditionVar,
5626 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005627}
5628
5629template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005630StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005631TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattner57ad3782011-02-17 20:34:02 +00005632 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5633 S->getLabel());
5634 if (!LD)
5635 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005636
Douglas Gregor43959a92009-08-20 07:17:43 +00005637 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump1eb44332009-09-09 15:08:12 +00005638 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005639 cast<LabelDecl>(LD));
Douglas Gregor43959a92009-08-20 07:17:43 +00005640}
5641
5642template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005643StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005644TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005645 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregor43959a92009-08-20 07:17:43 +00005646 if (Target.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005647 return StmtError();
Eli Friedmand29975f2012-01-31 22:47:07 +00005648 Target = SemaRef.MaybeCreateExprWithCleanups(Target.take());
Mike Stump1eb44332009-09-09 15:08:12 +00005649
Douglas Gregor43959a92009-08-20 07:17:43 +00005650 if (!getDerived().AlwaysRebuild() &&
5651 Target.get() == S->getTarget())
John McCall3fa5cae2010-10-26 07:05:15 +00005652 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005653
5654 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005655 Target.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005656}
5657
5658template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005659StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005660TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005661 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005662}
Mike Stump1eb44332009-09-09 15:08:12 +00005663
Douglas Gregor43959a92009-08-20 07:17:43 +00005664template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005665StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005666TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005667 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005668}
Mike Stump1eb44332009-09-09 15:08:12 +00005669
Douglas Gregor43959a92009-08-20 07:17:43 +00005670template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005671StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005672TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005673 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregor43959a92009-08-20 07:17:43 +00005674 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005675 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005676
Mike Stump1eb44332009-09-09 15:08:12 +00005677 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregor43959a92009-08-20 07:17:43 +00005678 // to tell whether the return type of the function has changed.
John McCall9ae2f072010-08-23 23:25:46 +00005679 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005680}
Mike Stump1eb44332009-09-09 15:08:12 +00005681
Douglas Gregor43959a92009-08-20 07:17:43 +00005682template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005683StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005684TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005685 bool DeclChanged = false;
Chris Lattner686775d2011-07-20 06:58:45 +00005686 SmallVector<Decl *, 4> Decls;
Douglas Gregor43959a92009-08-20 07:17:43 +00005687 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5688 D != DEnd; ++D) {
Douglas Gregoraac571c2010-03-01 17:25:41 +00005689 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5690 *D);
Douglas Gregor43959a92009-08-20 07:17:43 +00005691 if (!Transformed)
John McCallf312b1e2010-08-26 23:41:50 +00005692 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005693
Douglas Gregor43959a92009-08-20 07:17:43 +00005694 if (Transformed != *D)
5695 DeclChanged = true;
Mike Stump1eb44332009-09-09 15:08:12 +00005696
Douglas Gregor43959a92009-08-20 07:17:43 +00005697 Decls.push_back(Transformed);
5698 }
Mike Stump1eb44332009-09-09 15:08:12 +00005699
Douglas Gregor43959a92009-08-20 07:17:43 +00005700 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005701 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005702
Rafael Espindola4549d7f2013-07-09 12:05:01 +00005703 return getDerived().RebuildDeclStmt(Decls, S->getStartLoc(), S->getEndLoc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005704}
Mike Stump1eb44332009-09-09 15:08:12 +00005705
Douglas Gregor43959a92009-08-20 07:17:43 +00005706template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005707StmtResult
Chad Rosierdf5faf52012-08-25 00:11:56 +00005708TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005709
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005710 SmallVector<Expr*, 8> Constraints;
5711 SmallVector<Expr*, 8> Exprs;
Chris Lattner686775d2011-07-20 06:58:45 +00005712 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlssona5a79f72010-01-30 20:05:21 +00005713
John McCall60d7b3a2010-08-24 06:29:42 +00005714 ExprResult AsmString;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005715 SmallVector<Expr*, 8> Clobbers;
Anders Carlsson703e3942010-01-24 05:50:09 +00005716
5717 bool ExprsChanged = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005718
Anders Carlsson703e3942010-01-24 05:50:09 +00005719 // Go through the outputs.
5720 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005721 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005722
Anders Carlsson703e3942010-01-24 05:50:09 +00005723 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005724 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005725
Anders Carlsson703e3942010-01-24 05:50:09 +00005726 // Transform the output expr.
5727 Expr *OutputExpr = S->getOutputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005728 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005729 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005730 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005731
Anders Carlsson703e3942010-01-24 05:50:09 +00005732 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005733
John McCall9ae2f072010-08-23 23:25:46 +00005734 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005735 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005736
Anders Carlsson703e3942010-01-24 05:50:09 +00005737 // Go through the inputs.
5738 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005739 Names.push_back(S->getInputIdentifier(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005740
Anders Carlsson703e3942010-01-24 05:50:09 +00005741 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005742 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005743
Anders Carlsson703e3942010-01-24 05:50:09 +00005744 // Transform the input expr.
5745 Expr *InputExpr = S->getInputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005746 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005747 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005748 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005749
Anders Carlsson703e3942010-01-24 05:50:09 +00005750 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005751
John McCall9ae2f072010-08-23 23:25:46 +00005752 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005753 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005754
Anders Carlsson703e3942010-01-24 05:50:09 +00005755 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005756 return SemaRef.Owned(S);
Anders Carlsson703e3942010-01-24 05:50:09 +00005757
5758 // Go through the clobbers.
5759 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosier5c7f5942012-08-27 23:28:41 +00005760 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlsson703e3942010-01-24 05:50:09 +00005761
5762 // No need to transform the asm string literal.
5763 AsmString = SemaRef.Owned(S->getAsmString());
Chad Rosierdf5faf52012-08-25 00:11:56 +00005764 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
5765 S->isVolatile(), S->getNumOutputs(),
5766 S->getNumInputs(), Names.data(),
5767 Constraints, Exprs, AsmString.get(),
5768 Clobbers, S->getRParenLoc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005769}
5770
Chad Rosier8cd64b42012-06-11 20:47:18 +00005771template<typename Derived>
5772StmtResult
5773TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier79efe242012-08-07 00:29:06 +00005774 ArrayRef<Token> AsmToks =
5775 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier62f22b82012-08-08 19:48:07 +00005776
John McCallaeeacf72013-05-03 00:10:13 +00005777 bool HadError = false, HadChange = false;
5778
5779 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
5780 SmallVector<Expr*, 8> TransformedExprs;
5781 TransformedExprs.reserve(SrcExprs.size());
5782 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
5783 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
5784 if (!Result.isUsable()) {
5785 HadError = true;
5786 } else {
5787 HadChange |= (Result.get() != SrcExprs[i]);
5788 TransformedExprs.push_back(Result.take());
5789 }
5790 }
5791
5792 if (HadError) return StmtError();
5793 if (!HadChange && !getDerived().AlwaysRebuild())
5794 return Owned(S);
5795
Chad Rosier7bd092b2012-08-15 16:53:30 +00005796 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
John McCallaeeacf72013-05-03 00:10:13 +00005797 AsmToks, S->getAsmString(),
5798 S->getNumOutputs(), S->getNumInputs(),
5799 S->getAllConstraints(), S->getClobbers(),
5800 TransformedExprs, S->getEndLoc());
Chad Rosier8cd64b42012-06-11 20:47:18 +00005801}
Douglas Gregor43959a92009-08-20 07:17:43 +00005802
5803template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005804StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005805TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005806 // Transform the body of the @try.
John McCall60d7b3a2010-08-24 06:29:42 +00005807 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005808 if (TryBody.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005809 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005810
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005811 // Transform the @catch statements (if present).
5812 bool AnyCatchChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005813 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005814 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005815 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005816 if (Catch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005817 return StmtError();
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005818 if (Catch.get() != S->getCatchStmt(I))
5819 AnyCatchChanged = true;
5820 CatchStmts.push_back(Catch.release());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005821 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005822
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005823 // Transform the @finally statement (if present).
John McCall60d7b3a2010-08-24 06:29:42 +00005824 StmtResult Finally;
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005825 if (S->getFinallyStmt()) {
5826 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5827 if (Finally.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005828 return StmtError();
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005829 }
5830
5831 // If nothing changed, just retain this statement.
5832 if (!getDerived().AlwaysRebuild() &&
5833 TryBody.get() == S->getTryBody() &&
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005834 !AnyCatchChanged &&
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005835 Finally.get() == S->getFinallyStmt())
John McCall3fa5cae2010-10-26 07:05:15 +00005836 return SemaRef.Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005837
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005838 // Build a new statement.
John McCall9ae2f072010-08-23 23:25:46 +00005839 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00005840 CatchStmts, Finally.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
Mike Stump1eb44332009-09-09 15:08:12 +00005845TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00005846 // Transform the @catch parameter, if there is one.
5847 VarDecl *Var = 0;
5848 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5849 TypeSourceInfo *TSInfo = 0;
5850 if (FromVar->getTypeSourceInfo()) {
5851 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5852 if (!TSInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005853 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005854 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005855
Douglas Gregorbe270a02010-04-26 17:57:08 +00005856 QualType T;
5857 if (TSInfo)
5858 T = TSInfo->getType();
5859 else {
5860 T = getDerived().TransformType(FromVar->getType());
5861 if (T.isNull())
Chad Rosier4a9d7952012-08-08 18:46:20 +00005862 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005863 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005864
Douglas Gregorbe270a02010-04-26 17:57:08 +00005865 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5866 if (!Var)
John McCallf312b1e2010-08-26 23:41:50 +00005867 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005868 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005869
John McCall60d7b3a2010-08-24 06:29:42 +00005870 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorbe270a02010-04-26 17:57:08 +00005871 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005872 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005873
5874 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorbe270a02010-04-26 17:57:08 +00005875 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005876 Var, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005877}
Mike Stump1eb44332009-09-09 15:08:12 +00005878
Douglas Gregor43959a92009-08-20 07:17:43 +00005879template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005880StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005881TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005882 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005883 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005884 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005885 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005886
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005887 // If nothing changed, just retain this statement.
5888 if (!getDerived().AlwaysRebuild() &&
5889 Body.get() == S->getFinallyBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005890 return SemaRef.Owned(S);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005891
5892 // Build a new statement.
5893 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005894 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005895}
Mike Stump1eb44332009-09-09 15:08:12 +00005896
Douglas Gregor43959a92009-08-20 07:17:43 +00005897template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005898StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005899TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005900 ExprResult Operand;
Douglas Gregord1377b22010-04-22 21:44:01 +00005901 if (S->getThrowExpr()) {
5902 Operand = getDerived().TransformExpr(S->getThrowExpr());
5903 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005904 return StmtError();
Douglas Gregord1377b22010-04-22 21:44:01 +00005905 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005906
Douglas Gregord1377b22010-04-22 21:44:01 +00005907 if (!getDerived().AlwaysRebuild() &&
5908 Operand.get() == S->getThrowExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005909 return getSema().Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005910
John McCall9ae2f072010-08-23 23:25:46 +00005911 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005912}
Mike Stump1eb44332009-09-09 15:08:12 +00005913
Douglas Gregor43959a92009-08-20 07:17:43 +00005914template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005915StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005916TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005917 ObjCAtSynchronizedStmt *S) {
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005918 // Transform the object we are locking.
John McCall60d7b3a2010-08-24 06:29:42 +00005919 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005920 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005921 return StmtError();
John McCall07524032011-07-27 21:50:02 +00005922 Object =
5923 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
5924 Object.get());
5925 if (Object.isInvalid())
5926 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005927
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005928 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005929 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005930 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005931 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005932
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005933 // If nothing change, just retain the current statement.
5934 if (!getDerived().AlwaysRebuild() &&
5935 Object.get() == S->getSynchExpr() &&
5936 Body.get() == S->getSynchBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005937 return SemaRef.Owned(S);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005938
5939 // Build a new statement.
5940 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005941 Object.get(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005942}
5943
5944template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005945StmtResult
John McCallf85e1932011-06-15 23:02:42 +00005946TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
5947 ObjCAutoreleasePoolStmt *S) {
5948 // Transform the body.
5949 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
5950 if (Body.isInvalid())
5951 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005952
John McCallf85e1932011-06-15 23:02:42 +00005953 // If nothing changed, just retain this statement.
5954 if (!getDerived().AlwaysRebuild() &&
5955 Body.get() == S->getSubStmt())
5956 return SemaRef.Owned(S);
5957
5958 // Build a new statement.
5959 return getDerived().RebuildObjCAutoreleasePoolStmt(
5960 S->getAtLoc(), Body.get());
5961}
5962
5963template<typename Derived>
5964StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005965TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005966 ObjCForCollectionStmt *S) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00005967 // Transform the element statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005968 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005969 if (Element.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005970 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005971
Douglas Gregorc3203e72010-04-22 23:10:45 +00005972 // Transform the collection expression.
John McCall60d7b3a2010-08-24 06:29:42 +00005973 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005974 if (Collection.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005975 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005976
Douglas Gregorc3203e72010-04-22 23:10:45 +00005977 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005978 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005979 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005980 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005981
Douglas Gregorc3203e72010-04-22 23:10:45 +00005982 // If nothing changed, just retain this statement.
5983 if (!getDerived().AlwaysRebuild() &&
5984 Element.get() == S->getElement() &&
5985 Collection.get() == S->getCollection() &&
5986 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005987 return SemaRef.Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005988
Douglas Gregorc3203e72010-04-22 23:10:45 +00005989 // Build a new statement.
5990 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005991 Element.get(),
5992 Collection.get(),
Douglas Gregorc3203e72010-04-22 23:10:45 +00005993 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005994 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005995}
5996
David Majnemer2c4a01d2013-10-15 09:50:08 +00005997template <typename Derived>
5998StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005999 // Transform the exception declaration, if any.
6000 VarDecl *Var = 0;
David Majnemer2c4a01d2013-10-15 09:50:08 +00006001 if (VarDecl *ExceptionDecl = S->getExceptionDecl()) {
6002 TypeSourceInfo *T =
6003 getDerived().TransformType(ExceptionDecl->getTypeSourceInfo());
Douglas Gregor83cb9422010-09-09 17:09:21 +00006004 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00006005 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00006006
David Majnemer2c4a01d2013-10-15 09:50:08 +00006007 Var = getDerived().RebuildExceptionDecl(
6008 ExceptionDecl, T, ExceptionDecl->getInnerLocStart(),
6009 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
Douglas Gregorff331c12010-07-25 18:17:45 +00006010 if (!Var || Var->isInvalidDecl())
John McCallf312b1e2010-08-26 23:41:50 +00006011 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00006012 }
Mike Stump1eb44332009-09-09 15:08:12 +00006013
Douglas Gregor43959a92009-08-20 07:17:43 +00006014 // Transform the actual exception handler.
John McCall60d7b3a2010-08-24 06:29:42 +00006015 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorff331c12010-07-25 18:17:45 +00006016 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006017 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00006018
David Majnemer2c4a01d2013-10-15 09:50:08 +00006019 if (!getDerived().AlwaysRebuild() && !Var &&
Douglas Gregor43959a92009-08-20 07:17:43 +00006020 Handler.get() == S->getHandlerBlock())
John McCall3fa5cae2010-10-26 07:05:15 +00006021 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00006022
David Majnemer2c4a01d2013-10-15 09:50:08 +00006023 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00006024}
Mike Stump1eb44332009-09-09 15:08:12 +00006025
David Majnemer2c4a01d2013-10-15 09:50:08 +00006026template <typename Derived>
6027StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00006028 // Transform the try block itself.
David Majnemer2c4a01d2013-10-15 09:50:08 +00006029 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
Douglas Gregor43959a92009-08-20 07:17:43 +00006030 if (TryBlock.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006031 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00006032
Douglas Gregor43959a92009-08-20 07:17:43 +00006033 // Transform the handlers.
6034 bool HandlerChanged = false;
David Majnemer2c4a01d2013-10-15 09:50:08 +00006035 SmallVector<Stmt *, 8> Handlers;
Douglas Gregor43959a92009-08-20 07:17:43 +00006036 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
David Majnemer2c4a01d2013-10-15 09:50:08 +00006037 StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I));
Douglas Gregor43959a92009-08-20 07:17:43 +00006038 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006039 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00006040
Douglas Gregor43959a92009-08-20 07:17:43 +00006041 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
6042 Handlers.push_back(Handler.takeAs<Stmt>());
6043 }
Mike Stump1eb44332009-09-09 15:08:12 +00006044
David Majnemer2c4a01d2013-10-15 09:50:08 +00006045 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00006046 !HandlerChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006047 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00006048
John McCall9ae2f072010-08-23 23:25:46 +00006049 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006050 Handlers);
Douglas Gregor43959a92009-08-20 07:17:43 +00006051}
Mike Stump1eb44332009-09-09 15:08:12 +00006052
Richard Smithad762fc2011-04-14 22:09:26 +00006053template<typename Derived>
6054StmtResult
6055TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
6056 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
6057 if (Range.isInvalid())
6058 return StmtError();
6059
6060 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
6061 if (BeginEnd.isInvalid())
6062 return StmtError();
6063
6064 ExprResult Cond = getDerived().TransformExpr(S->getCond());
6065 if (Cond.isInvalid())
6066 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00006067 if (Cond.get())
6068 Cond = SemaRef.CheckBooleanCondition(Cond.take(), S->getColonLoc());
6069 if (Cond.isInvalid())
6070 return StmtError();
6071 if (Cond.get())
6072 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.take());
Richard Smithad762fc2011-04-14 22:09:26 +00006073
6074 ExprResult Inc = getDerived().TransformExpr(S->getInc());
6075 if (Inc.isInvalid())
6076 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00006077 if (Inc.get())
6078 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.take());
Richard Smithad762fc2011-04-14 22:09:26 +00006079
6080 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
6081 if (LoopVar.isInvalid())
6082 return StmtError();
6083
6084 StmtResult NewStmt = S;
6085 if (getDerived().AlwaysRebuild() ||
6086 Range.get() != S->getRangeStmt() ||
6087 BeginEnd.get() != S->getBeginEndStmt() ||
6088 Cond.get() != S->getCond() ||
6089 Inc.get() != S->getInc() ||
Douglas Gregor39b60dc2013-05-02 18:35:56 +00006090 LoopVar.get() != S->getLoopVarStmt()) {
Richard Smithad762fc2011-04-14 22:09:26 +00006091 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6092 S->getColonLoc(), Range.get(),
6093 BeginEnd.get(), Cond.get(),
6094 Inc.get(), LoopVar.get(),
6095 S->getRParenLoc());
Douglas Gregor39b60dc2013-05-02 18:35:56 +00006096 if (NewStmt.isInvalid())
6097 return StmtError();
6098 }
Richard Smithad762fc2011-04-14 22:09:26 +00006099
6100 StmtResult Body = getDerived().TransformStmt(S->getBody());
6101 if (Body.isInvalid())
6102 return StmtError();
6103
6104 // Body has changed but we didn't rebuild the for-range statement. Rebuild
6105 // it now so we have a new statement to attach the body to.
Douglas Gregor39b60dc2013-05-02 18:35:56 +00006106 if (Body.get() != S->getBody() && NewStmt.get() == S) {
Richard Smithad762fc2011-04-14 22:09:26 +00006107 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6108 S->getColonLoc(), Range.get(),
6109 BeginEnd.get(), Cond.get(),
6110 Inc.get(), LoopVar.get(),
6111 S->getRParenLoc());
Douglas Gregor39b60dc2013-05-02 18:35:56 +00006112 if (NewStmt.isInvalid())
6113 return StmtError();
6114 }
Richard Smithad762fc2011-04-14 22:09:26 +00006115
6116 if (NewStmt.get() == S)
6117 return SemaRef.Owned(S);
6118
6119 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
6120}
6121
John Wiegley28bbe4b2011-04-28 01:08:34 +00006122template<typename Derived>
6123StmtResult
Douglas Gregorba0513d2011-10-25 01:33:02 +00006124TreeTransform<Derived>::TransformMSDependentExistsStmt(
6125 MSDependentExistsStmt *S) {
6126 // Transform the nested-name-specifier, if any.
6127 NestedNameSpecifierLoc QualifierLoc;
6128 if (S->getQualifierLoc()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00006129 QualifierLoc
Douglas Gregorba0513d2011-10-25 01:33:02 +00006130 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
6131 if (!QualifierLoc)
6132 return StmtError();
6133 }
6134
6135 // Transform the declaration name.
6136 DeclarationNameInfo NameInfo = S->getNameInfo();
6137 if (NameInfo.getName()) {
6138 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6139 if (!NameInfo.getName())
6140 return StmtError();
6141 }
6142
6143 // Check whether anything changed.
6144 if (!getDerived().AlwaysRebuild() &&
6145 QualifierLoc == S->getQualifierLoc() &&
6146 NameInfo.getName() == S->getNameInfo().getName())
6147 return S;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006148
Douglas Gregorba0513d2011-10-25 01:33:02 +00006149 // Determine whether this name exists, if we can.
6150 CXXScopeSpec SS;
6151 SS.Adopt(QualifierLoc);
6152 bool Dependent = false;
6153 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/0, SS, NameInfo)) {
6154 case Sema::IER_Exists:
6155 if (S->isIfExists())
6156 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006157
Douglas Gregorba0513d2011-10-25 01:33:02 +00006158 return new (getSema().Context) NullStmt(S->getKeywordLoc());
6159
6160 case Sema::IER_DoesNotExist:
6161 if (S->isIfNotExists())
6162 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006163
Douglas Gregorba0513d2011-10-25 01:33:02 +00006164 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00006165
Douglas Gregorba0513d2011-10-25 01:33:02 +00006166 case Sema::IER_Dependent:
6167 Dependent = true;
6168 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006169
Douglas Gregor65019ac2011-10-25 03:44:56 +00006170 case Sema::IER_Error:
6171 return StmtError();
Douglas Gregorba0513d2011-10-25 01:33:02 +00006172 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006173
Douglas Gregorba0513d2011-10-25 01:33:02 +00006174 // We need to continue with the instantiation, so do so now.
6175 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
6176 if (SubStmt.isInvalid())
6177 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006178
Douglas Gregorba0513d2011-10-25 01:33:02 +00006179 // If we have resolved the name, just transform to the substatement.
6180 if (!Dependent)
6181 return SubStmt;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006182
Douglas Gregorba0513d2011-10-25 01:33:02 +00006183 // The name is still dependent, so build a dependent expression again.
6184 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
6185 S->isIfExists(),
6186 QualifierLoc,
6187 NameInfo,
6188 SubStmt.get());
6189}
6190
6191template<typename Derived>
John McCall76da55d2013-04-16 07:28:30 +00006192ExprResult
6193TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
6194 NestedNameSpecifierLoc QualifierLoc;
6195 if (E->getQualifierLoc()) {
6196 QualifierLoc
6197 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6198 if (!QualifierLoc)
6199 return ExprError();
6200 }
6201
6202 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
6203 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
6204 if (!PD)
6205 return ExprError();
6206
6207 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
6208 if (Base.isInvalid())
6209 return ExprError();
6210
6211 return new (SemaRef.getASTContext())
6212 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
6213 SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
6214 QualifierLoc, E->getMemberLoc());
6215}
6216
David Majnemerfc210492013-10-15 09:33:02 +00006217template <typename Derived>
6218StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
David Majnemer7752a742013-10-15 09:30:14 +00006219 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
David Majnemerfc210492013-10-15 09:33:02 +00006220 if (TryBlock.isInvalid())
6221 return StmtError();
John Wiegley28bbe4b2011-04-28 01:08:34 +00006222
6223 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
David Majnemer7752a742013-10-15 09:30:14 +00006224 if (Handler.isInvalid())
6225 return StmtError();
6226
David Majnemerfc210492013-10-15 09:33:02 +00006227 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
6228 Handler.get() == S->getHandler())
John Wiegley28bbe4b2011-04-28 01:08:34 +00006229 return SemaRef.Owned(S);
6230
David Majnemerfc210492013-10-15 09:33:02 +00006231 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(),
6232 TryBlock.take(), Handler.take());
John Wiegley28bbe4b2011-04-28 01:08:34 +00006233}
6234
David Majnemerfc210492013-10-15 09:33:02 +00006235template <typename Derived>
6236StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
David Majnemer7752a742013-10-15 09:30:14 +00006237 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfc210492013-10-15 09:33:02 +00006238 if (Block.isInvalid())
6239 return StmtError();
John Wiegley28bbe4b2011-04-28 01:08:34 +00006240
David Majnemerfc210492013-10-15 09:33:02 +00006241 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.take());
John Wiegley28bbe4b2011-04-28 01:08:34 +00006242}
6243
David Majnemerfc210492013-10-15 09:33:02 +00006244template <typename Derived>
6245StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
John Wiegley28bbe4b2011-04-28 01:08:34 +00006246 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
David Majnemerfc210492013-10-15 09:33:02 +00006247 if (FilterExpr.isInvalid())
6248 return StmtError();
John Wiegley28bbe4b2011-04-28 01:08:34 +00006249
David Majnemer7752a742013-10-15 09:30:14 +00006250 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfc210492013-10-15 09:33:02 +00006251 if (Block.isInvalid())
6252 return StmtError();
John Wiegley28bbe4b2011-04-28 01:08:34 +00006253
David Majnemerfc210492013-10-15 09:33:02 +00006254 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.take(),
John Wiegley28bbe4b2011-04-28 01:08:34 +00006255 Block.take());
6256}
6257
David Majnemerfc210492013-10-15 09:33:02 +00006258template <typename Derived>
6259StmtResult TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
6260 if (isa<SEHFinallyStmt>(Handler))
John Wiegley28bbe4b2011-04-28 01:08:34 +00006261 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
6262 else
6263 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
6264}
6265
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006266template<typename Derived>
6267StmtResult
6268TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
Alexey Bataev0c018352013-09-06 18:03:48 +00006269 DeclarationNameInfo DirName;
6270 getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, 0);
6271
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006272 // Transform the clauses
Alexey Bataev0c018352013-09-06 18:03:48 +00006273 llvm::SmallVector<OMPClause *, 16> TClauses;
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006274 ArrayRef<OMPClause *> Clauses = D->clauses();
6275 TClauses.reserve(Clauses.size());
6276 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
6277 I != E; ++I) {
6278 if (*I) {
6279 OMPClause *Clause = getDerived().TransformOMPClause(*I);
Alexey Bataev0c018352013-09-06 18:03:48 +00006280 if (!Clause) {
6281 getSema().EndOpenMPDSABlock(0);
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006282 return StmtError();
Alexey Bataev0c018352013-09-06 18:03:48 +00006283 }
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006284 TClauses.push_back(Clause);
6285 }
6286 else {
6287 TClauses.push_back(0);
6288 }
6289 }
Alexey Bataev0c018352013-09-06 18:03:48 +00006290 if (!D->getAssociatedStmt()) {
6291 getSema().EndOpenMPDSABlock(0);
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006292 return StmtError();
Alexey Bataev0c018352013-09-06 18:03:48 +00006293 }
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006294 StmtResult AssociatedStmt =
6295 getDerived().TransformStmt(D->getAssociatedStmt());
Alexey Bataev0c018352013-09-06 18:03:48 +00006296 if (AssociatedStmt.isInvalid()) {
6297 getSema().EndOpenMPDSABlock(0);
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006298 return StmtError();
Alexey Bataev0c018352013-09-06 18:03:48 +00006299 }
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006300
Alexey Bataev0c018352013-09-06 18:03:48 +00006301 StmtResult Res = getDerived().RebuildOMPParallelDirective(TClauses,
6302 AssociatedStmt.take(),
6303 D->getLocStart(),
6304 D->getLocEnd());
6305 getSema().EndOpenMPDSABlock(Res.get());
6306 return Res;
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006307}
6308
6309template<typename Derived>
6310OMPClause *
6311TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
6312 return getDerived().RebuildOMPDefaultClause(C->getDefaultKind(),
6313 C->getDefaultKindKwLoc(),
6314 C->getLocStart(),
6315 C->getLParenLoc(),
6316 C->getLocEnd());
6317}
6318
6319template<typename Derived>
6320OMPClause *
6321TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
Alexey Bataev0c018352013-09-06 18:03:48 +00006322 llvm::SmallVector<Expr *, 16> Vars;
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006323 Vars.reserve(C->varlist_size());
Alexey Bataev543c4ae2013-09-24 03:17:45 +00006324 for (OMPPrivateClause::varlist_iterator I = C->varlist_begin(),
6325 E = C->varlist_end();
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006326 I != E; ++I) {
6327 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(*I));
6328 if (EVar.isInvalid())
6329 return 0;
6330 Vars.push_back(EVar.take());
6331 }
6332 return getDerived().RebuildOMPPrivateClause(Vars,
6333 C->getLocStart(),
6334 C->getLParenLoc(),
6335 C->getLocEnd());
6336}
6337
Alexey Bataev0c018352013-09-06 18:03:48 +00006338template<typename Derived>
6339OMPClause *
Alexey Bataevd195bc32013-10-01 05:32:34 +00006340TreeTransform<Derived>::TransformOMPFirstprivateClause(
6341 OMPFirstprivateClause *C) {
6342 llvm::SmallVector<Expr *, 16> Vars;
6343 Vars.reserve(C->varlist_size());
6344 for (OMPFirstprivateClause::varlist_iterator I = C->varlist_begin(),
6345 E = C->varlist_end();
6346 I != E; ++I) {
6347 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(*I));
6348 if (EVar.isInvalid())
6349 return 0;
6350 Vars.push_back(EVar.take());
6351 }
6352 return getDerived().RebuildOMPFirstprivateClause(Vars,
6353 C->getLocStart(),
6354 C->getLParenLoc(),
6355 C->getLocEnd());
6356}
6357
6358template<typename Derived>
6359OMPClause *
Alexey Bataev0c018352013-09-06 18:03:48 +00006360TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
6361 llvm::SmallVector<Expr *, 16> Vars;
6362 Vars.reserve(C->varlist_size());
Alexey Bataev543c4ae2013-09-24 03:17:45 +00006363 for (OMPSharedClause::varlist_iterator I = C->varlist_begin(),
6364 E = C->varlist_end();
Alexey Bataev0c018352013-09-06 18:03:48 +00006365 I != E; ++I) {
6366 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(*I));
6367 if (EVar.isInvalid())
6368 return 0;
6369 Vars.push_back(EVar.take());
6370 }
6371 return getDerived().RebuildOMPSharedClause(Vars,
6372 C->getLocStart(),
6373 C->getLParenLoc(),
6374 C->getLocEnd());
6375}
6376
Douglas Gregor43959a92009-08-20 07:17:43 +00006377//===----------------------------------------------------------------------===//
Douglas Gregorb98b1992009-08-11 05:31:07 +00006378// Expression transformation
6379//===----------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +00006380template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006381ExprResult
John McCall454feb92009-12-08 09:21:05 +00006382TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006383 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006384}
Mike Stump1eb44332009-09-09 15:08:12 +00006385
6386template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006387ExprResult
John McCall454feb92009-12-08 09:21:05 +00006388TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006389 NestedNameSpecifierLoc QualifierLoc;
6390 if (E->getQualifierLoc()) {
6391 QualifierLoc
6392 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6393 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006394 return ExprError();
Douglas Gregora2813ce2009-10-23 18:54:35 +00006395 }
John McCalldbd872f2009-12-08 09:08:17 +00006396
6397 ValueDecl *ND
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006398 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6399 E->getDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006400 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00006401 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006402
John McCallec8045d2010-08-17 21:27:17 +00006403 DeclarationNameInfo NameInfo = E->getNameInfo();
6404 if (NameInfo.getName()) {
6405 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6406 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00006407 return ExprError();
John McCallec8045d2010-08-17 21:27:17 +00006408 }
Abramo Bagnara25777432010-08-11 22:01:17 +00006409
6410 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006411 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregora2813ce2009-10-23 18:54:35 +00006412 ND == E->getDecl() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00006413 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCall096832c2010-08-19 23:49:38 +00006414 !E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00006415
6416 // Mark it referenced in the new context regardless.
6417 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00006418 SemaRef.MarkDeclRefReferenced(E);
John McCalldbd872f2009-12-08 09:08:17 +00006419
John McCall3fa5cae2010-10-26 07:05:15 +00006420 return SemaRef.Owned(E);
Douglas Gregora2813ce2009-10-23 18:54:35 +00006421 }
John McCalldbd872f2009-12-08 09:08:17 +00006422
6423 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCall096832c2010-08-19 23:49:38 +00006424 if (E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00006425 TemplateArgs = &TransArgs;
6426 TransArgs.setLAngleLoc(E->getLAngleLoc());
6427 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006428 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6429 E->getNumTemplateArgs(),
6430 TransArgs))
6431 return ExprError();
John McCalldbd872f2009-12-08 09:08:17 +00006432 }
6433
Chad Rosier4a9d7952012-08-08 18:46:20 +00006434 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregor40d96a62011-02-28 21:54:11 +00006435 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006436}
Mike Stump1eb44332009-09-09 15:08:12 +00006437
Douglas Gregorb98b1992009-08-11 05:31:07 +00006438template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006439ExprResult
John McCall454feb92009-12-08 09:21:05 +00006440TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006441 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006442}
Mike Stump1eb44332009-09-09 15:08:12 +00006443
Douglas Gregorb98b1992009-08-11 05:31:07 +00006444template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006445ExprResult
John McCall454feb92009-12-08 09:21:05 +00006446TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006447 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006448}
Mike Stump1eb44332009-09-09 15:08:12 +00006449
Douglas Gregorb98b1992009-08-11 05:31:07 +00006450template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006451ExprResult
John McCall454feb92009-12-08 09:21:05 +00006452TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006453 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006454}
Mike Stump1eb44332009-09-09 15:08:12 +00006455
Douglas Gregorb98b1992009-08-11 05:31:07 +00006456template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006457ExprResult
John McCall454feb92009-12-08 09:21:05 +00006458TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006459 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006460}
Mike Stump1eb44332009-09-09 15:08:12 +00006461
Douglas Gregorb98b1992009-08-11 05:31:07 +00006462template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006463ExprResult
John McCall454feb92009-12-08 09:21:05 +00006464TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006465 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006466}
6467
6468template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006469ExprResult
Richard Smith9fcce652012-03-07 08:35:16 +00006470TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
Argyrios Kyrtzidis391ca9f2013-04-09 01:17:02 +00006471 if (FunctionDecl *FD = E->getDirectCallee())
6472 SemaRef.MarkFunctionReferenced(E->getLocStart(), FD);
Richard Smith9fcce652012-03-07 08:35:16 +00006473 return SemaRef.MaybeBindToTemporary(E);
6474}
6475
6476template<typename Derived>
6477ExprResult
Peter Collingbournef111d932011-04-15 00:35:48 +00006478TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
6479 ExprResult ControllingExpr =
6480 getDerived().TransformExpr(E->getControllingExpr());
6481 if (ControllingExpr.isInvalid())
6482 return ExprError();
6483
Chris Lattner686775d2011-07-20 06:58:45 +00006484 SmallVector<Expr *, 4> AssocExprs;
6485 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbournef111d932011-04-15 00:35:48 +00006486 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
6487 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
6488 if (TS) {
6489 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
6490 if (!AssocType)
6491 return ExprError();
6492 AssocTypes.push_back(AssocType);
6493 } else {
6494 AssocTypes.push_back(0);
6495 }
6496
6497 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
6498 if (AssocExpr.isInvalid())
6499 return ExprError();
6500 AssocExprs.push_back(AssocExpr.release());
6501 }
6502
6503 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
6504 E->getDefaultLoc(),
6505 E->getRParenLoc(),
6506 ControllingExpr.release(),
Dmitri Gribenko80613222013-05-10 13:06:58 +00006507 AssocTypes,
6508 AssocExprs);
Peter Collingbournef111d932011-04-15 00:35:48 +00006509}
6510
6511template<typename Derived>
6512ExprResult
John McCall454feb92009-12-08 09:21:05 +00006513TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006514 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006515 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006516 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006517
Douglas Gregorb98b1992009-08-11 05:31:07 +00006518 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006519 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006520
John McCall9ae2f072010-08-23 23:25:46 +00006521 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006522 E->getRParen());
6523}
6524
Richard Smithefeeccf2012-10-21 03:28:35 +00006525/// \brief The operand of a unary address-of operator has special rules: it's
6526/// allowed to refer to a non-static member of a class even if there's no 'this'
6527/// object available.
6528template<typename Derived>
6529ExprResult
6530TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
6531 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
6532 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true);
6533 else
6534 return getDerived().TransformExpr(E);
6535}
6536
Mike Stump1eb44332009-09-09 15:08:12 +00006537template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006538ExprResult
John McCall454feb92009-12-08 09:21:05 +00006539TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smith82b00012013-05-21 23:29:46 +00006540 ExprResult SubExpr;
6541 if (E->getOpcode() == UO_AddrOf)
6542 SubExpr = TransformAddressOfOperand(E->getSubExpr());
6543 else
6544 SubExpr = TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006545 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006546 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006547
Douglas Gregorb98b1992009-08-11 05:31:07 +00006548 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006549 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006550
Douglas Gregorb98b1992009-08-11 05:31:07 +00006551 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
6552 E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006553 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006554}
Mike Stump1eb44332009-09-09 15:08:12 +00006555
Douglas Gregorb98b1992009-08-11 05:31:07 +00006556template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006557ExprResult
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006558TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
6559 // Transform the type.
6560 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
6561 if (!Type)
John McCallf312b1e2010-08-26 23:41:50 +00006562 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006563
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006564 // Transform all of the components into components similar to what the
6565 // parser uses.
Chad Rosier4a9d7952012-08-08 18:46:20 +00006566 // FIXME: It would be slightly more efficient in the non-dependent case to
6567 // just map FieldDecls, rather than requiring the rebuilder to look for
6568 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006569 // template code that we don't care.
6570 bool ExprChanged = false;
John McCallf312b1e2010-08-26 23:41:50 +00006571 typedef Sema::OffsetOfComponent Component;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006572 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner686775d2011-07-20 06:58:45 +00006573 SmallVector<Component, 4> Components;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006574 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
6575 const Node &ON = E->getComponent(I);
6576 Component Comp;
Douglas Gregor72be24f2010-04-30 20:35:01 +00006577 Comp.isBrackets = true;
Abramo Bagnara06dec892011-03-12 09:45:03 +00006578 Comp.LocStart = ON.getSourceRange().getBegin();
6579 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006580 switch (ON.getKind()) {
6581 case Node::Array: {
6582 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCall60d7b3a2010-08-24 06:29:42 +00006583 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006584 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006585 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006586
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006587 ExprChanged = ExprChanged || Index.get() != FromIndex;
6588 Comp.isBrackets = true;
John McCall9ae2f072010-08-23 23:25:46 +00006589 Comp.U.E = Index.get();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006590 break;
6591 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006592
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006593 case Node::Field:
6594 case Node::Identifier:
6595 Comp.isBrackets = false;
6596 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregor29d2fd52010-04-28 22:43:14 +00006597 if (!Comp.U.IdentInfo)
6598 continue;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006599
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006600 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006601
Douglas Gregorcc8a5d52010-04-29 00:18:15 +00006602 case Node::Base:
6603 // Will be recomputed during the rebuild.
6604 continue;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006605 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006606
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006607 Components.push_back(Comp);
6608 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006609
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006610 // If nothing changed, retain the existing expression.
6611 if (!getDerived().AlwaysRebuild() &&
6612 Type == E->getTypeSourceInfo() &&
6613 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006614 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00006615
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006616 // Build a new offsetof expression.
6617 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
6618 Components.data(), Components.size(),
6619 E->getRParenLoc());
6620}
6621
6622template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006623ExprResult
John McCall7cd7d1a2010-11-15 23:31:06 +00006624TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
6625 assert(getDerived().AlreadyTransformed(E->getType()) &&
6626 "opaque value expression requires transformation");
6627 return SemaRef.Owned(E);
6628}
6629
6630template<typename Derived>
6631ExprResult
John McCall4b9c2d22011-11-06 09:01:30 +00006632TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCall01e19be2011-11-30 04:42:31 +00006633 // Rebuild the syntactic form. The original syntactic form has
6634 // opaque-value expressions in it, so strip those away and rebuild
6635 // the result. This is a really awful way of doing this, but the
6636 // better solution (rebuilding the semantic expressions and
6637 // rebinding OVEs as necessary) doesn't work; we'd need
6638 // TreeTransform to not strip away implicit conversions.
6639 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
6640 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCall4b9c2d22011-11-06 09:01:30 +00006641 if (result.isInvalid()) return ExprError();
6642
6643 // If that gives us a pseudo-object result back, the pseudo-object
6644 // expression must have been an lvalue-to-rvalue conversion which we
6645 // should reapply.
6646 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
6647 result = SemaRef.checkPseudoObjectRValue(result.take());
6648
6649 return result;
6650}
6651
6652template<typename Derived>
6653ExprResult
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006654TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
6655 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006656 if (E->isArgumentType()) {
John McCalla93c9342009-12-07 02:54:59 +00006657 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor5557b252009-10-28 00:29:27 +00006658
John McCalla93c9342009-12-07 02:54:59 +00006659 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall5ab75172009-11-04 07:28:41 +00006660 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006661 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006662
John McCall5ab75172009-11-04 07:28:41 +00006663 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCall3fa5cae2010-10-26 07:05:15 +00006664 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006665
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006666 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
6667 E->getKind(),
6668 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006669 }
Mike Stump1eb44332009-09-09 15:08:12 +00006670
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006671 // C++0x [expr.sizeof]p1:
6672 // The operand is either an expression, which is an unevaluated operand
6673 // [...]
Eli Friedman80bfa3d2012-09-26 04:34:21 +00006674 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
6675 Sema::ReuseLambdaContextDecl);
Mike Stump1eb44332009-09-09 15:08:12 +00006676
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006677 ExprResult SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
6678 if (SubExpr.isInvalid())
6679 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006680
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006681 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
6682 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006683
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006684 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
6685 E->getOperatorLoc(),
6686 E->getKind(),
6687 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006688}
Mike Stump1eb44332009-09-09 15:08:12 +00006689
Douglas Gregorb98b1992009-08-11 05:31:07 +00006690template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006691ExprResult
John McCall454feb92009-12-08 09:21:05 +00006692TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006693 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006694 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006695 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006696
John McCall60d7b3a2010-08-24 06:29:42 +00006697 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006698 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006699 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006700
6701
Douglas Gregorb98b1992009-08-11 05:31:07 +00006702 if (!getDerived().AlwaysRebuild() &&
6703 LHS.get() == E->getLHS() &&
6704 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006705 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006706
John McCall9ae2f072010-08-23 23:25:46 +00006707 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006708 /*FIXME:*/E->getLHS()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006709 RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006710 E->getRBracketLoc());
6711}
Mike Stump1eb44332009-09-09 15:08:12 +00006712
6713template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006714ExprResult
John McCall454feb92009-12-08 09:21:05 +00006715TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006716 // Transform the callee.
John McCall60d7b3a2010-08-24 06:29:42 +00006717 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006718 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006719 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006720
6721 // Transform arguments.
6722 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006723 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006724 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00006725 &ArgChanged))
6726 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006727
Douglas Gregorb98b1992009-08-11 05:31:07 +00006728 if (!getDerived().AlwaysRebuild() &&
6729 Callee.get() == E->getCallee() &&
6730 !ArgChanged)
Dmitri Gribenko1ad23d62012-09-10 21:20:09 +00006731 return SemaRef.MaybeBindToTemporary(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006732
Douglas Gregorb98b1992009-08-11 05:31:07 +00006733 // FIXME: Wrong source location information for the '('.
Mike Stump1eb44332009-09-09 15:08:12 +00006734 SourceLocation FakeLParenLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006735 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCall9ae2f072010-08-23 23:25:46 +00006736 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006737 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006738 E->getRParenLoc());
6739}
Mike Stump1eb44332009-09-09 15:08:12 +00006740
6741template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006742ExprResult
John McCall454feb92009-12-08 09:21:05 +00006743TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006744 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006745 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006746 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006747
Douglas Gregor40d96a62011-02-28 21:54:11 +00006748 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006749 if (E->hasQualifier()) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006750 QualifierLoc
6751 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00006752
Douglas Gregor40d96a62011-02-28 21:54:11 +00006753 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006754 return ExprError();
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006755 }
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006756 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00006757
Eli Friedmanf595cc42009-12-04 06:40:45 +00006758 ValueDecl *Member
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006759 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
6760 E->getMemberDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006761 if (!Member)
John McCallf312b1e2010-08-26 23:41:50 +00006762 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006763
John McCall6bb80172010-03-30 21:47:33 +00006764 NamedDecl *FoundDecl = E->getFoundDecl();
6765 if (FoundDecl == E->getMemberDecl()) {
6766 FoundDecl = Member;
6767 } else {
6768 FoundDecl = cast_or_null<NamedDecl>(
6769 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
6770 if (!FoundDecl)
John McCallf312b1e2010-08-26 23:41:50 +00006771 return ExprError();
John McCall6bb80172010-03-30 21:47:33 +00006772 }
6773
Douglas Gregorb98b1992009-08-11 05:31:07 +00006774 if (!getDerived().AlwaysRebuild() &&
6775 Base.get() == E->getBase() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006776 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006777 Member == E->getMemberDecl() &&
John McCall6bb80172010-03-30 21:47:33 +00006778 FoundDecl == E->getFoundDecl() &&
John McCall096832c2010-08-19 23:49:38 +00006779 !E->hasExplicitTemplateArgs()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00006780
Anders Carlsson1f240322009-12-22 05:24:09 +00006781 // Mark it referenced in the new context regardless.
6782 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00006783 SemaRef.MarkMemberReferenced(E);
6784
John McCall3fa5cae2010-10-26 07:05:15 +00006785 return SemaRef.Owned(E);
Anders Carlsson1f240322009-12-22 05:24:09 +00006786 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00006787
John McCalld5532b62009-11-23 01:53:49 +00006788 TemplateArgumentListInfo TransArgs;
John McCall096832c2010-08-19 23:49:38 +00006789 if (E->hasExplicitTemplateArgs()) {
John McCalld5532b62009-11-23 01:53:49 +00006790 TransArgs.setLAngleLoc(E->getLAngleLoc());
6791 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006792 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6793 E->getNumTemplateArgs(),
6794 TransArgs))
6795 return ExprError();
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006796 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006797
Douglas Gregorb98b1992009-08-11 05:31:07 +00006798 // FIXME: Bogus source location for the operator
6799 SourceLocation FakeOperatorLoc
6800 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
6801
John McCallc2233c52010-01-15 08:34:02 +00006802 // FIXME: to do this check properly, we will need to preserve the
6803 // first-qualifier-in-scope here, just in case we had a dependent
6804 // base (and therefore couldn't do the check) and a
6805 // nested-name-qualifier (and therefore could do the lookup).
6806 NamedDecl *FirstQualifierInScope = 0;
6807
John McCall9ae2f072010-08-23 23:25:46 +00006808 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006809 E->isArrow(),
Douglas Gregor40d96a62011-02-28 21:54:11 +00006810 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006811 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00006812 E->getMemberNameInfo(),
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006813 Member,
John McCall6bb80172010-03-30 21:47:33 +00006814 FoundDecl,
John McCall096832c2010-08-19 23:49:38 +00006815 (E->hasExplicitTemplateArgs()
John McCalld5532b62009-11-23 01:53:49 +00006816 ? &TransArgs : 0),
John McCallc2233c52010-01-15 08:34:02 +00006817 FirstQualifierInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006818}
Mike Stump1eb44332009-09-09 15:08:12 +00006819
Douglas Gregorb98b1992009-08-11 05:31:07 +00006820template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006821ExprResult
John McCall454feb92009-12-08 09:21:05 +00006822TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006823 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006824 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006825 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006826
John McCall60d7b3a2010-08-24 06:29:42 +00006827 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006828 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006829 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006830
Douglas Gregorb98b1992009-08-11 05:31:07 +00006831 if (!getDerived().AlwaysRebuild() &&
6832 LHS.get() == E->getLHS() &&
6833 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006834 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006835
Lang Hamesbe9af122012-10-02 04:45:10 +00006836 Sema::FPContractStateRAII FPContractState(getSema());
6837 getSema().FPFeatures.fp_contract = E->isFPContractable();
6838
Douglas Gregorb98b1992009-08-11 05:31:07 +00006839 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006840 LHS.get(), RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006841}
6842
Mike Stump1eb44332009-09-09 15:08:12 +00006843template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006844ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006845TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall454feb92009-12-08 09:21:05 +00006846 CompoundAssignOperator *E) {
6847 return getDerived().TransformBinaryOperator(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006848}
Mike Stump1eb44332009-09-09 15:08:12 +00006849
Douglas Gregorb98b1992009-08-11 05:31:07 +00006850template<typename Derived>
John McCall56ca35d2011-02-17 10:25:35 +00006851ExprResult TreeTransform<Derived>::
6852TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
6853 // Just rebuild the common and RHS expressions and see whether we
6854 // get any changes.
6855
6856 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
6857 if (commonExpr.isInvalid())
6858 return ExprError();
6859
6860 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
6861 if (rhs.isInvalid())
6862 return ExprError();
6863
6864 if (!getDerived().AlwaysRebuild() &&
6865 commonExpr.get() == e->getCommon() &&
6866 rhs.get() == e->getFalseExpr())
6867 return SemaRef.Owned(e);
6868
6869 return getDerived().RebuildConditionalOperator(commonExpr.take(),
6870 e->getQuestionLoc(),
6871 0,
6872 e->getColonLoc(),
6873 rhs.get());
6874}
6875
6876template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006877ExprResult
John McCall454feb92009-12-08 09:21:05 +00006878TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006879 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006880 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006881 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006882
John McCall60d7b3a2010-08-24 06:29:42 +00006883 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006884 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006885 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006886
John McCall60d7b3a2010-08-24 06:29:42 +00006887 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006888 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006889 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006890
Douglas Gregorb98b1992009-08-11 05:31:07 +00006891 if (!getDerived().AlwaysRebuild() &&
6892 Cond.get() == E->getCond() &&
6893 LHS.get() == E->getLHS() &&
6894 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006895 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006896
John McCall9ae2f072010-08-23 23:25:46 +00006897 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006898 E->getQuestionLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006899 LHS.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006900 E->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006901 RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006902}
Mike Stump1eb44332009-09-09 15:08:12 +00006903
6904template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006905ExprResult
John McCall454feb92009-12-08 09:21:05 +00006906TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora88cfbf2009-12-12 18:16:41 +00006907 // Implicit casts are eliminated during transformation, since they
6908 // will be recomputed by semantic analysis after transformation.
Douglas Gregor6eef5192009-12-14 19:27:10 +00006909 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006910}
Mike Stump1eb44332009-09-09 15:08:12 +00006911
Douglas Gregorb98b1992009-08-11 05:31:07 +00006912template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006913ExprResult
John McCall454feb92009-12-08 09:21:05 +00006914TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006915 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6916 if (!Type)
6917 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006918
John McCall60d7b3a2010-08-24 06:29:42 +00006919 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006920 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006921 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006922 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006923
Douglas Gregorb98b1992009-08-11 05:31:07 +00006924 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006925 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006926 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006927 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006928
John McCall9d125032010-01-15 18:39:57 +00006929 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006930 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006931 E->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006932 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006933}
Mike Stump1eb44332009-09-09 15:08:12 +00006934
Douglas Gregorb98b1992009-08-11 05:31:07 +00006935template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006936ExprResult
John McCall454feb92009-12-08 09:21:05 +00006937TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCall42f56b52010-01-18 19:35:47 +00006938 TypeSourceInfo *OldT = E->getTypeSourceInfo();
6939 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
6940 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006941 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006942
John McCall60d7b3a2010-08-24 06:29:42 +00006943 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006944 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006945 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006946
Douglas Gregorb98b1992009-08-11 05:31:07 +00006947 if (!getDerived().AlwaysRebuild() &&
John McCall42f56b52010-01-18 19:35:47 +00006948 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006949 Init.get() == E->getInitializer())
Douglas Gregor92be2a52011-12-10 00:23:21 +00006950 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006951
John McCall1d7d8d62010-01-19 22:33:45 +00006952 // Note: the expression type doesn't necessarily match the
6953 // type-as-written, but that's okay, because it should always be
6954 // derivable from the initializer.
6955
John McCall42f56b52010-01-18 19:35:47 +00006956 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006957 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00006958 Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006959}
Mike Stump1eb44332009-09-09 15:08:12 +00006960
Douglas Gregorb98b1992009-08-11 05:31:07 +00006961template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006962ExprResult
John McCall454feb92009-12-08 09:21:05 +00006963TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006964 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006965 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006966 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006967
Douglas Gregorb98b1992009-08-11 05:31:07 +00006968 if (!getDerived().AlwaysRebuild() &&
6969 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00006970 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006971
Douglas Gregorb98b1992009-08-11 05:31:07 +00006972 // FIXME: Bad source location
Mike Stump1eb44332009-09-09 15:08:12 +00006973 SourceLocation FakeOperatorLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006974 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCall9ae2f072010-08-23 23:25:46 +00006975 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006976 E->getAccessorLoc(),
6977 E->getAccessor());
6978}
Mike Stump1eb44332009-09-09 15:08:12 +00006979
Douglas Gregorb98b1992009-08-11 05:31:07 +00006980template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006981ExprResult
John McCall454feb92009-12-08 09:21:05 +00006982TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006983 bool InitChanged = false;
Mike Stump1eb44332009-09-09 15:08:12 +00006984
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006985 SmallVector<Expr*, 4> Inits;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006986 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregoraa165f82011-01-03 19:04:46 +00006987 Inits, &InitChanged))
6988 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006989
Douglas Gregorb98b1992009-08-11 05:31:07 +00006990 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006991 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006992
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006993 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Douglas Gregore48319a2009-11-09 17:16:50 +00006994 E->getRBraceLoc(), E->getType());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006995}
Mike Stump1eb44332009-09-09 15:08:12 +00006996
Douglas Gregorb98b1992009-08-11 05:31:07 +00006997template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006998ExprResult
John McCall454feb92009-12-08 09:21:05 +00006999TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007000 Designation Desig;
Mike Stump1eb44332009-09-09 15:08:12 +00007001
Douglas Gregor43959a92009-08-20 07:17:43 +00007002 // transform the initializer value
John McCall60d7b3a2010-08-24 06:29:42 +00007003 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007004 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007005 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007006
Douglas Gregor43959a92009-08-20 07:17:43 +00007007 // transform the designators.
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007008 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregorb98b1992009-08-11 05:31:07 +00007009 bool ExprChanged = false;
7010 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
7011 DEnd = E->designators_end();
7012 D != DEnd; ++D) {
7013 if (D->isFieldDesignator()) {
7014 Desig.AddDesignator(Designator::getField(D->getFieldName(),
7015 D->getDotLoc(),
7016 D->getFieldLoc()));
7017 continue;
7018 }
Mike Stump1eb44332009-09-09 15:08:12 +00007019
Douglas Gregorb98b1992009-08-11 05:31:07 +00007020 if (D->isArrayDesignator()) {
John McCall60d7b3a2010-08-24 06:29:42 +00007021 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007022 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007023 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007024
7025 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007026 D->getLBracketLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00007027
Douglas Gregorb98b1992009-08-11 05:31:07 +00007028 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
7029 ArrayExprs.push_back(Index.release());
7030 continue;
7031 }
Mike Stump1eb44332009-09-09 15:08:12 +00007032
Douglas Gregorb98b1992009-08-11 05:31:07 +00007033 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCall60d7b3a2010-08-24 06:29:42 +00007034 ExprResult Start
Douglas Gregorb98b1992009-08-11 05:31:07 +00007035 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
7036 if (Start.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007037 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007038
John McCall60d7b3a2010-08-24 06:29:42 +00007039 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007040 if (End.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007041 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007042
7043 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007044 End.get(),
7045 D->getLBracketLoc(),
7046 D->getEllipsisLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00007047
Douglas Gregorb98b1992009-08-11 05:31:07 +00007048 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
7049 End.get() != E->getArrayRangeEnd(*D);
Mike Stump1eb44332009-09-09 15:08:12 +00007050
Douglas Gregorb98b1992009-08-11 05:31:07 +00007051 ArrayExprs.push_back(Start.release());
7052 ArrayExprs.push_back(End.release());
7053 }
Mike Stump1eb44332009-09-09 15:08:12 +00007054
Douglas Gregorb98b1992009-08-11 05:31:07 +00007055 if (!getDerived().AlwaysRebuild() &&
7056 Init.get() == E->getInit() &&
7057 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00007058 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007059
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007060 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007061 E->getEqualOrColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00007062 E->usesGNUSyntax(), Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007063}
Mike Stump1eb44332009-09-09 15:08:12 +00007064
Douglas Gregorb98b1992009-08-11 05:31:07 +00007065template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007066ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007067TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall454feb92009-12-08 09:21:05 +00007068 ImplicitValueInitExpr *E) {
Douglas Gregor5557b252009-10-28 00:29:27 +00007069 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007070
Douglas Gregor5557b252009-10-28 00:29:27 +00007071 // FIXME: Will we ever have proper type location here? Will we actually
7072 // need to transform the type?
Douglas Gregorb98b1992009-08-11 05:31:07 +00007073 QualType T = getDerived().TransformType(E->getType());
7074 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00007075 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007076
Douglas Gregorb98b1992009-08-11 05:31:07 +00007077 if (!getDerived().AlwaysRebuild() &&
7078 T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00007079 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007080
Douglas Gregorb98b1992009-08-11 05:31:07 +00007081 return getDerived().RebuildImplicitValueInitExpr(T);
7082}
Mike Stump1eb44332009-09-09 15:08:12 +00007083
Douglas Gregorb98b1992009-08-11 05:31:07 +00007084template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007085ExprResult
John McCall454feb92009-12-08 09:21:05 +00007086TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00007087 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
7088 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007089 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007090
John McCall60d7b3a2010-08-24 06:29:42 +00007091 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007092 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007093 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007094
Douglas Gregorb98b1992009-08-11 05:31:07 +00007095 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara2cad9002010-08-10 10:06:15 +00007096 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007097 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007098 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007099
John McCall9ae2f072010-08-23 23:25:46 +00007100 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara2cad9002010-08-10 10:06:15 +00007101 TInfo, E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007102}
7103
7104template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007105ExprResult
John McCall454feb92009-12-08 09:21:05 +00007106TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007107 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007108 SmallVector<Expr*, 4> Inits;
Douglas Gregoraa165f82011-01-03 19:04:46 +00007109 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
7110 &ArgumentChanged))
7111 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007112
Douglas Gregorb98b1992009-08-11 05:31:07 +00007113 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007114 Inits,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007115 E->getRParenLoc());
7116}
Mike Stump1eb44332009-09-09 15:08:12 +00007117
Douglas Gregorb98b1992009-08-11 05:31:07 +00007118/// \brief Transform an address-of-label expression.
7119///
7120/// By default, the transformation of an address-of-label expression always
7121/// rebuilds the expression, so that the label identifier can be resolved to
7122/// the corresponding label statement by semantic analysis.
7123template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007124ExprResult
John McCall454feb92009-12-08 09:21:05 +00007125TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattner57ad3782011-02-17 20:34:02 +00007126 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
7127 E->getLabel());
7128 if (!LD)
7129 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007130
Douglas Gregorb98b1992009-08-11 05:31:07 +00007131 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00007132 cast<LabelDecl>(LD));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007133}
Mike Stump1eb44332009-09-09 15:08:12 +00007134
7135template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00007136ExprResult
John McCall454feb92009-12-08 09:21:05 +00007137TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCall7f39d512012-04-06 18:20:53 +00007138 SemaRef.ActOnStartStmtExpr();
John McCall60d7b3a2010-08-24 06:29:42 +00007139 StmtResult SubStmt
Douglas Gregorb98b1992009-08-11 05:31:07 +00007140 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCall7f39d512012-04-06 18:20:53 +00007141 if (SubStmt.isInvalid()) {
7142 SemaRef.ActOnStmtExprError();
John McCallf312b1e2010-08-26 23:41:50 +00007143 return ExprError();
John McCall7f39d512012-04-06 18:20:53 +00007144 }
Mike Stump1eb44332009-09-09 15:08:12 +00007145
Douglas Gregorb98b1992009-08-11 05:31:07 +00007146 if (!getDerived().AlwaysRebuild() &&
John McCall7f39d512012-04-06 18:20:53 +00007147 SubStmt.get() == E->getSubStmt()) {
7148 // Calling this an 'error' is unintuitive, but it does the right thing.
7149 SemaRef.ActOnStmtExprError();
Douglas Gregor92be2a52011-12-10 00:23:21 +00007150 return SemaRef.MaybeBindToTemporary(E);
John McCall7f39d512012-04-06 18:20:53 +00007151 }
Mike Stump1eb44332009-09-09 15:08:12 +00007152
7153 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00007154 SubStmt.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007155 E->getRParenLoc());
7156}
Mike Stump1eb44332009-09-09 15:08:12 +00007157
Douglas Gregorb98b1992009-08-11 05:31:07 +00007158template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007159ExprResult
John McCall454feb92009-12-08 09:21:05 +00007160TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007161 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007162 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007163 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007164
John McCall60d7b3a2010-08-24 06:29:42 +00007165 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007166 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007167 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007168
John McCall60d7b3a2010-08-24 06:29:42 +00007169 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007170 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007171 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007172
Douglas Gregorb98b1992009-08-11 05:31:07 +00007173 if (!getDerived().AlwaysRebuild() &&
7174 Cond.get() == E->getCond() &&
7175 LHS.get() == E->getLHS() &&
7176 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00007177 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007178
Douglas Gregorb98b1992009-08-11 05:31:07 +00007179 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00007180 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007181 E->getRParenLoc());
7182}
Mike Stump1eb44332009-09-09 15:08:12 +00007183
Douglas Gregorb98b1992009-08-11 05:31:07 +00007184template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007185ExprResult
John McCall454feb92009-12-08 09:21:05 +00007186TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007187 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007188}
7189
7190template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007191ExprResult
John McCall454feb92009-12-08 09:21:05 +00007192TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregor668d6d92009-12-13 20:44:55 +00007193 switch (E->getOperator()) {
7194 case OO_New:
7195 case OO_Delete:
7196 case OO_Array_New:
7197 case OO_Array_Delete:
7198 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier4a9d7952012-08-08 18:46:20 +00007199
Douglas Gregor668d6d92009-12-13 20:44:55 +00007200 case OO_Call: {
7201 // This is a call to an object's operator().
7202 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
7203
7204 // Transform the object itself.
John McCall60d7b3a2010-08-24 06:29:42 +00007205 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregor668d6d92009-12-13 20:44:55 +00007206 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007207 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00007208
7209 // FIXME: Poor location information
7210 SourceLocation FakeLParenLoc
7211 = SemaRef.PP.getLocForEndOfToken(
7212 static_cast<Expr *>(Object.get())->getLocEnd());
7213
7214 // Transform the call arguments.
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007215 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007216 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregoraa165f82011-01-03 19:04:46 +00007217 Args))
7218 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00007219
John McCall9ae2f072010-08-23 23:25:46 +00007220 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007221 Args,
Douglas Gregor668d6d92009-12-13 20:44:55 +00007222 E->getLocEnd());
7223 }
7224
7225#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
7226 case OO_##Name:
7227#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
7228#include "clang/Basic/OperatorKinds.def"
7229 case OO_Subscript:
7230 // Handled below.
7231 break;
7232
7233 case OO_Conditional:
7234 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregor668d6d92009-12-13 20:44:55 +00007235
7236 case OO_None:
7237 case NUM_OVERLOADED_OPERATORS:
7238 llvm_unreachable("not an overloaded operator?");
Douglas Gregor668d6d92009-12-13 20:44:55 +00007239 }
7240
John McCall60d7b3a2010-08-24 06:29:42 +00007241 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007242 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007243 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007244
Richard Smithefeeccf2012-10-21 03:28:35 +00007245 ExprResult First;
7246 if (E->getOperator() == OO_Amp)
7247 First = getDerived().TransformAddressOfOperand(E->getArg(0));
7248 else
7249 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007250 if (First.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007251 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007252
John McCall60d7b3a2010-08-24 06:29:42 +00007253 ExprResult Second;
Douglas Gregorb98b1992009-08-11 05:31:07 +00007254 if (E->getNumArgs() == 2) {
7255 Second = getDerived().TransformExpr(E->getArg(1));
7256 if (Second.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007257 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007258 }
Mike Stump1eb44332009-09-09 15:08:12 +00007259
Douglas Gregorb98b1992009-08-11 05:31:07 +00007260 if (!getDerived().AlwaysRebuild() &&
7261 Callee.get() == E->getCallee() &&
7262 First.get() == E->getArg(0) &&
Mike Stump1eb44332009-09-09 15:08:12 +00007263 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregor92be2a52011-12-10 00:23:21 +00007264 return SemaRef.MaybeBindToTemporary(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007265
Lang Hamesbe9af122012-10-02 04:45:10 +00007266 Sema::FPContractStateRAII FPContractState(getSema());
7267 getSema().FPFeatures.fp_contract = E->isFPContractable();
7268
Douglas Gregorb98b1992009-08-11 05:31:07 +00007269 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
7270 E->getOperatorLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00007271 Callee.get(),
7272 First.get(),
7273 Second.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007274}
Mike Stump1eb44332009-09-09 15:08:12 +00007275
Douglas Gregorb98b1992009-08-11 05:31:07 +00007276template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007277ExprResult
John McCall454feb92009-12-08 09:21:05 +00007278TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
7279 return getDerived().TransformCallExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007280}
Mike Stump1eb44332009-09-09 15:08:12 +00007281
Douglas Gregorb98b1992009-08-11 05:31:07 +00007282template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007283ExprResult
Peter Collingbournee08ce652011-02-09 21:07:24 +00007284TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
7285 // Transform the callee.
7286 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
7287 if (Callee.isInvalid())
7288 return ExprError();
7289
7290 // Transform exec config.
7291 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
7292 if (EC.isInvalid())
7293 return ExprError();
7294
7295 // Transform arguments.
7296 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007297 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007298 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00007299 &ArgChanged))
7300 return ExprError();
7301
7302 if (!getDerived().AlwaysRebuild() &&
7303 Callee.get() == E->getCallee() &&
7304 !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00007305 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbournee08ce652011-02-09 21:07:24 +00007306
7307 // FIXME: Wrong source location information for the '('.
7308 SourceLocation FakeLParenLoc
7309 = ((Expr *)Callee.get())->getSourceRange().getBegin();
7310 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007311 Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00007312 E->getRParenLoc(), EC.get());
7313}
7314
7315template<typename Derived>
7316ExprResult
John McCall454feb92009-12-08 09:21:05 +00007317TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007318 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7319 if (!Type)
7320 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007321
John McCall60d7b3a2010-08-24 06:29:42 +00007322 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00007323 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007324 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007325 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007326
Douglas Gregorb98b1992009-08-11 05:31:07 +00007327 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007328 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007329 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007330 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007331 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00007332 E->getStmtClass(),
Fariborz Jahanianf799ae12013-02-22 22:02:53 +00007333 E->getAngleBrackets().getBegin(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007334 Type,
Fariborz Jahanianf799ae12013-02-22 22:02:53 +00007335 E->getAngleBrackets().getEnd(),
7336 // FIXME. this should be '(' location
7337 E->getAngleBrackets().getEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00007338 SubExpr.get(),
Abramo Bagnara6cf7d7d2012-10-15 21:08:58 +00007339 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007340}
Mike Stump1eb44332009-09-09 15:08:12 +00007341
Douglas Gregorb98b1992009-08-11 05:31:07 +00007342template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007343ExprResult
John McCall454feb92009-12-08 09:21:05 +00007344TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
7345 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007346}
Mike Stump1eb44332009-09-09 15:08:12 +00007347
7348template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007349ExprResult
John McCall454feb92009-12-08 09:21:05 +00007350TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
7351 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007352}
7353
Douglas Gregorb98b1992009-08-11 05:31:07 +00007354template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007355ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007356TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall454feb92009-12-08 09:21:05 +00007357 CXXReinterpretCastExpr *E) {
7358 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007359}
Mike Stump1eb44332009-09-09 15:08:12 +00007360
Douglas Gregorb98b1992009-08-11 05:31:07 +00007361template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007362ExprResult
John McCall454feb92009-12-08 09:21:05 +00007363TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
7364 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007365}
Mike Stump1eb44332009-09-09 15:08:12 +00007366
Douglas Gregorb98b1992009-08-11 05:31:07 +00007367template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007368ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007369TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall454feb92009-12-08 09:21:05 +00007370 CXXFunctionalCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007371 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7372 if (!Type)
7373 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007374
John McCall60d7b3a2010-08-24 06:29:42 +00007375 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00007376 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007377 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007378 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007379
Douglas Gregorb98b1992009-08-11 05:31:07 +00007380 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007381 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007382 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007383 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007384
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007385 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Eli Friedmancdd4b782013-08-15 22:02:56 +00007386 E->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00007387 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007388 E->getRParenLoc());
7389}
Mike Stump1eb44332009-09-09 15:08:12 +00007390
Douglas Gregorb98b1992009-08-11 05:31:07 +00007391template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007392ExprResult
John McCall454feb92009-12-08 09:21:05 +00007393TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007394 if (E->isTypeOperand()) {
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007395 TypeSourceInfo *TInfo
7396 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7397 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007398 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007399
Douglas Gregorb98b1992009-08-11 05:31:07 +00007400 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007401 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007402 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007403
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007404 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7405 E->getLocStart(),
7406 TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007407 E->getLocEnd());
7408 }
Mike Stump1eb44332009-09-09 15:08:12 +00007409
Eli Friedmanef331b72012-01-20 01:26:23 +00007410 // We don't know whether the subexpression is potentially evaluated until
7411 // after we perform semantic analysis. We speculatively assume it is
7412 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregorb98b1992009-08-11 05:31:07 +00007413 // potentially evaluated.
Eli Friedman80bfa3d2012-09-26 04:34:21 +00007414 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
7415 Sema::ReuseLambdaContextDecl);
Mike Stump1eb44332009-09-09 15:08:12 +00007416
John McCall60d7b3a2010-08-24 06:29:42 +00007417 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007418 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007419 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007420
Douglas Gregorb98b1992009-08-11 05:31:07 +00007421 if (!getDerived().AlwaysRebuild() &&
7422 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007423 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007424
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007425 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7426 E->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00007427 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007428 E->getLocEnd());
7429}
7430
7431template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007432ExprResult
Francois Pichet01b7c302010-09-08 12:20:18 +00007433TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
7434 if (E->isTypeOperand()) {
7435 TypeSourceInfo *TInfo
7436 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7437 if (!TInfo)
7438 return ExprError();
7439
7440 if (!getDerived().AlwaysRebuild() &&
7441 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007442 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00007443
Douglas Gregor3c52a212011-03-06 17:40:41 +00007444 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet01b7c302010-09-08 12:20:18 +00007445 E->getLocStart(),
7446 TInfo,
7447 E->getLocEnd());
7448 }
7449
Francois Pichet01b7c302010-09-08 12:20:18 +00007450 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7451
7452 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
7453 if (SubExpr.isInvalid())
7454 return ExprError();
7455
7456 if (!getDerived().AlwaysRebuild() &&
7457 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007458 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00007459
7460 return getDerived().RebuildCXXUuidofExpr(E->getType(),
7461 E->getLocStart(),
7462 SubExpr.get(),
7463 E->getLocEnd());
7464}
7465
7466template<typename Derived>
7467ExprResult
John McCall454feb92009-12-08 09:21:05 +00007468TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007469 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007470}
Mike Stump1eb44332009-09-09 15:08:12 +00007471
Douglas Gregorb98b1992009-08-11 05:31:07 +00007472template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007473ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007474TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall454feb92009-12-08 09:21:05 +00007475 CXXNullPtrLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007476 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007477}
Mike Stump1eb44332009-09-09 15:08:12 +00007478
Douglas Gregorb98b1992009-08-11 05:31:07 +00007479template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007480ExprResult
John McCall454feb92009-12-08 09:21:05 +00007481TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Richard Smithcafeb942013-06-07 02:33:37 +00007482 QualType T = getSema().getCurrentThisType();
Mike Stump1eb44332009-09-09 15:08:12 +00007483
Douglas Gregorec79d872012-02-24 17:41:38 +00007484 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
7485 // Make sure that we capture 'this'.
7486 getSema().CheckCXXThisCapture(E->getLocStart());
John McCall3fa5cae2010-10-26 07:05:15 +00007487 return SemaRef.Owned(E);
Douglas Gregorec79d872012-02-24 17:41:38 +00007488 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007489
Douglas Gregor828a1972010-01-07 23:12:05 +00007490 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007491}
Mike Stump1eb44332009-09-09 15:08:12 +00007492
Douglas Gregorb98b1992009-08-11 05:31:07 +00007493template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007494ExprResult
John McCall454feb92009-12-08 09:21:05 +00007495TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007496 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007497 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007498 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007499
Douglas Gregorb98b1992009-08-11 05:31:07 +00007500 if (!getDerived().AlwaysRebuild() &&
7501 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007502 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007503
Douglas Gregorbca01b42011-07-06 22:04:06 +00007504 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
7505 E->isThrownVariableInScope());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007506}
Mike Stump1eb44332009-09-09 15:08:12 +00007507
Douglas Gregorb98b1992009-08-11 05:31:07 +00007508template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007509ExprResult
John McCall454feb92009-12-08 09:21:05 +00007510TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00007511 ParmVarDecl *Param
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007512 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
7513 E->getParam()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007514 if (!Param)
John McCallf312b1e2010-08-26 23:41:50 +00007515 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007516
Chandler Carruth53cb6f82010-02-08 06:42:49 +00007517 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007518 Param == E->getParam())
John McCall3fa5cae2010-10-26 07:05:15 +00007519 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007520
Douglas Gregor036aed12009-12-23 23:03:06 +00007521 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007522}
Mike Stump1eb44332009-09-09 15:08:12 +00007523
Douglas Gregorb98b1992009-08-11 05:31:07 +00007524template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007525ExprResult
Richard Smithc3bf52c2013-04-20 22:23:05 +00007526TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
7527 FieldDecl *Field
7528 = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(),
7529 E->getField()));
7530 if (!Field)
7531 return ExprError();
7532
7533 if (!getDerived().AlwaysRebuild() && Field == E->getField())
7534 return SemaRef.Owned(E);
7535
7536 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
7537}
7538
7539template<typename Derived>
7540ExprResult
Douglas Gregorab6677e2010-09-08 00:15:04 +00007541TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
7542 CXXScalarValueInitExpr *E) {
7543 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7544 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007545 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007546
Douglas Gregorb98b1992009-08-11 05:31:07 +00007547 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007548 T == E->getTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007549 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007550
Chad Rosier4a9d7952012-08-08 18:46:20 +00007551 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregorab6677e2010-09-08 00:15:04 +00007552 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregored8abf12010-07-08 06:14:04 +00007553 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007554}
Mike Stump1eb44332009-09-09 15:08:12 +00007555
Douglas Gregorb98b1992009-08-11 05:31:07 +00007556template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007557ExprResult
John McCall454feb92009-12-08 09:21:05 +00007558TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007559 // Transform the type that we're allocating
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007560 TypeSourceInfo *AllocTypeInfo
7561 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
7562 if (!AllocTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007563 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007564
Douglas Gregorb98b1992009-08-11 05:31:07 +00007565 // Transform the size of the array we're allocating (if any).
John McCall60d7b3a2010-08-24 06:29:42 +00007566 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007567 if (ArraySize.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007568 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007569
Douglas Gregorb98b1992009-08-11 05:31:07 +00007570 // Transform the placement arguments (if any).
7571 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007572 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007573 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregoraa165f82011-01-03 19:04:46 +00007574 E->getNumPlacementArgs(), true,
7575 PlacementArgs, &ArgumentChanged))
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007576 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007577
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007578 // Transform the initializer (if any).
7579 Expr *OldInit = E->getInitializer();
7580 ExprResult NewInit;
7581 if (OldInit)
7582 NewInit = getDerived().TransformExpr(OldInit);
7583 if (NewInit.isInvalid())
7584 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007585
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007586 // Transform new operator and delete operator.
Douglas Gregor1af74512010-02-26 00:38:10 +00007587 FunctionDecl *OperatorNew = 0;
7588 if (E->getOperatorNew()) {
7589 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007590 getDerived().TransformDecl(E->getLocStart(),
7591 E->getOperatorNew()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007592 if (!OperatorNew)
John McCallf312b1e2010-08-26 23:41:50 +00007593 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007594 }
7595
7596 FunctionDecl *OperatorDelete = 0;
7597 if (E->getOperatorDelete()) {
7598 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007599 getDerived().TransformDecl(E->getLocStart(),
7600 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007601 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007602 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007603 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007604
Douglas Gregorb98b1992009-08-11 05:31:07 +00007605 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007606 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007607 ArraySize.get() == E->getArraySize() &&
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007608 NewInit.get() == OldInit &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007609 OperatorNew == E->getOperatorNew() &&
7610 OperatorDelete == E->getOperatorDelete() &&
7611 !ArgumentChanged) {
7612 // Mark any declarations we need as referenced.
7613 // FIXME: instantiation-specific.
Douglas Gregor1af74512010-02-26 00:38:10 +00007614 if (OperatorNew)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007615 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregor1af74512010-02-26 00:38:10 +00007616 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007617 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007618
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007619 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007620 QualType ElementType
7621 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
7622 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
7623 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
7624 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedman5f2987c2012-02-02 03:46:19 +00007625 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007626 }
7627 }
7628 }
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007629
John McCall3fa5cae2010-10-26 07:05:15 +00007630 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007631 }
Mike Stump1eb44332009-09-09 15:08:12 +00007632
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007633 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007634 if (!ArraySize.get()) {
7635 // If no array size was specified, but the new expression was
7636 // instantiated with an array type (e.g., "new T" where T is
7637 // instantiated with "int[4]"), extract the outer bound from the
7638 // array type as our array size. We do this with constant and
7639 // dependently-sized array types.
7640 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
7641 if (!ArrayT) {
7642 // Do nothing
7643 } else if (const ConstantArrayType *ConsArrayT
7644 = dyn_cast<ConstantArrayType>(ArrayT)) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00007645 ArraySize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007646 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
Chad Rosier4a9d7952012-08-08 18:46:20 +00007647 ConsArrayT->getSize(),
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007648 SemaRef.Context.getSizeType(),
7649 /*FIXME:*/E->getLocStart()));
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007650 AllocType = ConsArrayT->getElementType();
7651 } else if (const DependentSizedArrayType *DepArrayT
7652 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
7653 if (DepArrayT->getSizeExpr()) {
John McCall3fa5cae2010-10-26 07:05:15 +00007654 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007655 AllocType = DepArrayT->getElementType();
7656 }
7657 }
7658 }
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007659
Douglas Gregorb98b1992009-08-11 05:31:07 +00007660 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
7661 E->isGlobalNew(),
7662 /*FIXME:*/E->getLocStart(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007663 PlacementArgs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007664 /*FIXME:*/E->getLocStart(),
Douglas Gregor4bd40312010-07-13 15:54:32 +00007665 E->getTypeIdParens(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007666 AllocType,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007667 AllocTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00007668 ArraySize.get(),
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007669 E->getDirectInitRange(),
7670 NewInit.take());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007671}
Mike Stump1eb44332009-09-09 15:08:12 +00007672
Douglas Gregorb98b1992009-08-11 05:31:07 +00007673template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007674ExprResult
John McCall454feb92009-12-08 09:21:05 +00007675TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007676 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007677 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007678 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007679
Douglas Gregor1af74512010-02-26 00:38:10 +00007680 // Transform the delete operator, if known.
7681 FunctionDecl *OperatorDelete = 0;
7682 if (E->getOperatorDelete()) {
7683 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007684 getDerived().TransformDecl(E->getLocStart(),
7685 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007686 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007687 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007688 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007689
Douglas Gregorb98b1992009-08-11 05:31:07 +00007690 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007691 Operand.get() == E->getArgument() &&
7692 OperatorDelete == E->getOperatorDelete()) {
7693 // Mark any declarations we need as referenced.
7694 // FIXME: instantiation-specific.
7695 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007696 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007697
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007698 if (!E->getArgument()->isTypeDependent()) {
7699 QualType Destroyed = SemaRef.Context.getBaseElementType(
7700 E->getDestroyedType());
7701 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
7702 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007703 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedman5f2987c2012-02-02 03:46:19 +00007704 SemaRef.LookupDestructor(Record));
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007705 }
7706 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007707
John McCall3fa5cae2010-10-26 07:05:15 +00007708 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007709 }
Mike Stump1eb44332009-09-09 15:08:12 +00007710
Douglas Gregorb98b1992009-08-11 05:31:07 +00007711 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
7712 E->isGlobalDelete(),
7713 E->isArrayForm(),
John McCall9ae2f072010-08-23 23:25:46 +00007714 Operand.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007715}
Mike Stump1eb44332009-09-09 15:08:12 +00007716
Douglas Gregorb98b1992009-08-11 05:31:07 +00007717template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007718ExprResult
Douglas Gregora71d8192009-09-04 17:36:40 +00007719TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall454feb92009-12-08 09:21:05 +00007720 CXXPseudoDestructorExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007721 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora71d8192009-09-04 17:36:40 +00007722 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007723 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007724
John McCallb3d87482010-08-24 05:47:05 +00007725 ParsedType ObjectTypePtr;
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007726 bool MayBePseudoDestructor = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007727 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007728 E->getOperatorLoc(),
7729 E->isArrow()? tok::arrow : tok::period,
7730 ObjectTypePtr,
7731 MayBePseudoDestructor);
7732 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007733 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007734
John McCallb3d87482010-08-24 05:47:05 +00007735 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007736 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
7737 if (QualifierLoc) {
7738 QualifierLoc
7739 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
7740 if (!QualifierLoc)
John McCall43fed0d2010-11-12 08:19:04 +00007741 return ExprError();
7742 }
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007743 CXXScopeSpec SS;
7744 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00007745
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007746 PseudoDestructorTypeStorage Destroyed;
7747 if (E->getDestroyedTypeInfo()) {
7748 TypeSourceInfo *DestroyedTypeInfo
John McCall43fed0d2010-11-12 08:19:04 +00007749 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00007750 ObjectType, 0, SS);
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007751 if (!DestroyedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007752 return ExprError();
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007753 Destroyed = DestroyedTypeInfo;
Douglas Gregor6b18e742011-11-09 02:19:47 +00007754 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007755 // We aren't likely to be able to resolve the identifier down to a type
7756 // now anyway, so just retain the identifier.
7757 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
7758 E->getDestroyedTypeLoc());
7759 } else {
7760 // Look for a destructor known with the given name.
John McCallb3d87482010-08-24 05:47:05 +00007761 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007762 *E->getDestroyedTypeIdentifier(),
7763 E->getDestroyedTypeLoc(),
7764 /*Scope=*/0,
7765 SS, ObjectTypePtr,
7766 false);
7767 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007768 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007769
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007770 Destroyed
7771 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
7772 E->getDestroyedTypeLoc());
7773 }
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007774
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007775 TypeSourceInfo *ScopeTypeInfo = 0;
7776 if (E->getScopeTypeInfo()) {
Douglas Gregor303b96f2013-03-08 21:25:01 +00007777 CXXScopeSpec EmptySS;
7778 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
7779 E->getScopeTypeInfo(), ObjectType, 0, EmptySS);
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007780 if (!ScopeTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007781 return ExprError();
Douglas Gregora71d8192009-09-04 17:36:40 +00007782 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007783
John McCall9ae2f072010-08-23 23:25:46 +00007784 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregora71d8192009-09-04 17:36:40 +00007785 E->getOperatorLoc(),
7786 E->isArrow(),
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007787 SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007788 ScopeTypeInfo,
7789 E->getColonColonLoc(),
Douglas Gregorfce46ee2010-02-24 23:50:37 +00007790 E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007791 Destroyed);
Douglas Gregora71d8192009-09-04 17:36:40 +00007792}
Mike Stump1eb44332009-09-09 15:08:12 +00007793
Douglas Gregora71d8192009-09-04 17:36:40 +00007794template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007795ExprResult
John McCallba135432009-11-21 08:51:07 +00007796TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall454feb92009-12-08 09:21:05 +00007797 UnresolvedLookupExpr *Old) {
John McCallf7a1a742009-11-24 19:00:30 +00007798 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
7799 Sema::LookupOrdinaryName);
7800
7801 // Transform all the decls.
7802 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
7803 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007804 NamedDecl *InstD = static_cast<NamedDecl*>(
7805 getDerived().TransformDecl(Old->getNameLoc(),
7806 *I));
John McCall9f54ad42009-12-10 09:41:52 +00007807 if (!InstD) {
7808 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7809 // This can happen because of dependent hiding.
7810 if (isa<UsingShadowDecl>(*I))
7811 continue;
Serge Pavlov1e75a1a2013-09-04 04:50:29 +00007812 else {
7813 R.clear();
John McCallf312b1e2010-08-26 23:41:50 +00007814 return ExprError();
Serge Pavlov1e75a1a2013-09-04 04:50:29 +00007815 }
John McCall9f54ad42009-12-10 09:41:52 +00007816 }
John McCallf7a1a742009-11-24 19:00:30 +00007817
7818 // Expand using declarations.
7819 if (isa<UsingDecl>(InstD)) {
7820 UsingDecl *UD = cast<UsingDecl>(InstD);
7821 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7822 E = UD->shadow_end(); I != E; ++I)
7823 R.addDecl(*I);
7824 continue;
7825 }
7826
7827 R.addDecl(InstD);
7828 }
7829
7830 // Resolve a kind, but don't do any further analysis. If it's
7831 // ambiguous, the callee needs to deal with it.
7832 R.resolveKind();
7833
7834 // Rebuild the nested-name qualifier, if present.
7835 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00007836 if (Old->getQualifierLoc()) {
7837 NestedNameSpecifierLoc QualifierLoc
7838 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7839 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007840 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007841
Douglas Gregor4c9be892011-02-28 20:01:57 +00007842 SS.Adopt(QualifierLoc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007843 }
7844
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007845 if (Old->getNamingClass()) {
Douglas Gregor66c45152010-04-27 16:10:10 +00007846 CXXRecordDecl *NamingClass
7847 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
7848 Old->getNameLoc(),
7849 Old->getNamingClass()));
Serge Pavlov1e75a1a2013-09-04 04:50:29 +00007850 if (!NamingClass) {
7851 R.clear();
John McCallf312b1e2010-08-26 23:41:50 +00007852 return ExprError();
Serge Pavlov1e75a1a2013-09-04 04:50:29 +00007853 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007854
Douglas Gregor66c45152010-04-27 16:10:10 +00007855 R.setNamingClass(NamingClass);
John McCallf7a1a742009-11-24 19:00:30 +00007856 }
7857
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007858 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
7859
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007860 // If we have neither explicit template arguments, nor the template keyword,
7861 // it's a normal declaration name.
7862 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
John McCallf7a1a742009-11-24 19:00:30 +00007863 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
7864
7865 // If we have template arguments, rebuild them, then rebuild the
7866 // templateid expression.
7867 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola02e221b2012-08-28 04:13:54 +00007868 if (Old->hasExplicitTemplateArgs() &&
7869 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregorfcc12532010-12-20 17:31:10 +00007870 Old->getNumTemplateArgs(),
Serge Pavlov1e75a1a2013-09-04 04:50:29 +00007871 TransArgs)) {
7872 R.clear();
Douglas Gregorfcc12532010-12-20 17:31:10 +00007873 return ExprError();
Serge Pavlov1e75a1a2013-09-04 04:50:29 +00007874 }
John McCallf7a1a742009-11-24 19:00:30 +00007875
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007876 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007877 Old->requiresADL(), &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007878}
Mike Stump1eb44332009-09-09 15:08:12 +00007879
Douglas Gregorb98b1992009-08-11 05:31:07 +00007880template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007881ExprResult
John McCall454feb92009-12-08 09:21:05 +00007882TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007883 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7884 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007885 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007886
Douglas Gregorb98b1992009-08-11 05:31:07 +00007887 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007888 T == E->getQueriedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007889 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007890
Mike Stump1eb44332009-09-09 15:08:12 +00007891 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007892 E->getLocStart(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007893 T,
7894 E->getLocEnd());
7895}
Mike Stump1eb44332009-09-09 15:08:12 +00007896
Douglas Gregorb98b1992009-08-11 05:31:07 +00007897template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007898ExprResult
Francois Pichet6ad6f282010-12-07 00:08:36 +00007899TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
7900 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
7901 if (!LhsT)
7902 return ExprError();
7903
7904 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
7905 if (!RhsT)
7906 return ExprError();
7907
7908 if (!getDerived().AlwaysRebuild() &&
7909 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
7910 return SemaRef.Owned(E);
7911
7912 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
7913 E->getLocStart(),
7914 LhsT, RhsT,
7915 E->getLocEnd());
7916}
7917
7918template<typename Derived>
7919ExprResult
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007920TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
7921 bool ArgChanged = false;
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00007922 SmallVector<TypeSourceInfo *, 4> Args;
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007923 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
7924 TypeSourceInfo *From = E->getArg(I);
7925 TypeLoc FromTL = From->getTypeLoc();
David Blaikie39e6ab42013-02-18 22:06:02 +00007926 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007927 TypeLocBuilder TLB;
7928 TLB.reserve(FromTL.getFullDataSize());
7929 QualType To = getDerived().TransformType(TLB, FromTL);
7930 if (To.isNull())
7931 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007932
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007933 if (To == From->getType())
7934 Args.push_back(From);
7935 else {
7936 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7937 ArgChanged = true;
7938 }
7939 continue;
7940 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007941
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007942 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007943
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007944 // We have a pack expansion. Instantiate it.
David Blaikie39e6ab42013-02-18 22:06:02 +00007945 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007946 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
7947 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
7948 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007949
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007950 // Determine whether the set of unexpanded parameter packs can and should
7951 // be expanded.
7952 bool Expand = true;
7953 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00007954 Optional<unsigned> OrigNumExpansions =
7955 ExpansionTL.getTypePtr()->getNumExpansions();
7956 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007957 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
7958 PatternTL.getSourceRange(),
7959 Unexpanded,
7960 Expand, RetainExpansion,
7961 NumExpansions))
7962 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007963
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007964 if (!Expand) {
7965 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00007966 // transformation on the pack expansion, producing another pack
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007967 // expansion.
7968 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007969
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007970 TypeLocBuilder TLB;
7971 TLB.reserve(From->getTypeLoc().getFullDataSize());
7972
7973 QualType To = getDerived().TransformType(TLB, PatternTL);
7974 if (To.isNull())
7975 return ExprError();
7976
Chad Rosier4a9d7952012-08-08 18:46:20 +00007977 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007978 PatternTL.getSourceRange(),
7979 ExpansionTL.getEllipsisLoc(),
7980 NumExpansions);
7981 if (To.isNull())
7982 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007983
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007984 PackExpansionTypeLoc ToExpansionTL
7985 = TLB.push<PackExpansionTypeLoc>(To);
7986 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7987 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7988 continue;
7989 }
7990
7991 // Expand the pack expansion by substituting for each argument in the
7992 // pack(s).
7993 for (unsigned I = 0; I != *NumExpansions; ++I) {
7994 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
7995 TypeLocBuilder TLB;
7996 TLB.reserve(PatternTL.getFullDataSize());
7997 QualType To = getDerived().TransformType(TLB, PatternTL);
7998 if (To.isNull())
7999 return ExprError();
8000
Eli Friedman20cfeca2013-07-19 21:49:32 +00008001 if (To->containsUnexpandedParameterPack()) {
8002 To = getDerived().RebuildPackExpansionType(To,
8003 PatternTL.getSourceRange(),
8004 ExpansionTL.getEllipsisLoc(),
8005 NumExpansions);
8006 if (To.isNull())
8007 return ExprError();
8008
8009 PackExpansionTypeLoc ToExpansionTL
8010 = TLB.push<PackExpansionTypeLoc>(To);
8011 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8012 }
8013
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00008014 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8015 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008016
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00008017 if (!RetainExpansion)
8018 continue;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008019
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00008020 // If we're supposed to retain a pack expansion, do so by temporarily
8021 // forgetting the partially-substituted parameter pack.
8022 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
8023
8024 TypeLocBuilder TLB;
8025 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008026
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00008027 QualType To = getDerived().TransformType(TLB, PatternTL);
8028 if (To.isNull())
8029 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008030
8031 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00008032 PatternTL.getSourceRange(),
8033 ExpansionTL.getEllipsisLoc(),
8034 NumExpansions);
8035 if (To.isNull())
8036 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008037
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00008038 PackExpansionTypeLoc ToExpansionTL
8039 = TLB.push<PackExpansionTypeLoc>(To);
8040 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8041 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8042 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008043
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00008044 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8045 return SemaRef.Owned(E);
8046
8047 return getDerived().RebuildTypeTrait(E->getTrait(),
8048 E->getLocStart(),
8049 Args,
8050 E->getLocEnd());
8051}
8052
8053template<typename Derived>
8054ExprResult
John Wiegley21ff2e52011-04-28 00:16:57 +00008055TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
8056 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
8057 if (!T)
8058 return ExprError();
8059
8060 if (!getDerived().AlwaysRebuild() &&
8061 T == E->getQueriedTypeSourceInfo())
8062 return SemaRef.Owned(E);
8063
8064 ExprResult SubExpr;
8065 {
8066 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8067 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
8068 if (SubExpr.isInvalid())
8069 return ExprError();
8070
8071 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
8072 return SemaRef.Owned(E);
8073 }
8074
8075 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
8076 E->getLocStart(),
8077 T,
8078 SubExpr.get(),
8079 E->getLocEnd());
8080}
8081
8082template<typename Derived>
8083ExprResult
John Wiegley55262202011-04-25 06:54:41 +00008084TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
8085 ExprResult SubExpr;
8086 {
8087 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8088 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
8089 if (SubExpr.isInvalid())
8090 return ExprError();
8091
8092 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
8093 return SemaRef.Owned(E);
8094 }
8095
8096 return getDerived().RebuildExpressionTrait(
8097 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
8098}
8099
8100template<typename Derived>
8101ExprResult
John McCall865d4472009-11-19 22:55:06 +00008102TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00008103 DependentScopeDeclRefExpr *E) {
Richard Smithefeeccf2012-10-21 03:28:35 +00008104 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand*/false);
8105}
8106
8107template<typename Derived>
8108ExprResult
8109TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
8110 DependentScopeDeclRefExpr *E,
8111 bool IsAddressOfOperand) {
Reid Kleckner8690cee2013-10-15 18:38:02 +00008112 assert(E->getQualifierLoc());
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00008113 NestedNameSpecifierLoc QualifierLoc
8114 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
8115 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008116 return ExprError();
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008117 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00008118
John McCall43fed0d2010-11-12 08:19:04 +00008119 // TODO: If this is a conversion-function-id, verify that the
8120 // destination type name (if present) resolves the same way after
8121 // instantiation as it did in the local scope.
8122
Abramo Bagnara25777432010-08-11 22:01:17 +00008123 DeclarationNameInfo NameInfo
8124 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
8125 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00008126 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008127
John McCallf7a1a742009-11-24 19:00:30 +00008128 if (!E->hasExplicitTemplateArgs()) {
8129 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00008130 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00008131 // Note: it is sufficient to compare the Name component of NameInfo:
8132 // if name has not changed, DNLoc has not changed either.
8133 NameInfo.getName() == E->getDeclName())
John McCall3fa5cae2010-10-26 07:05:15 +00008134 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008135
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00008136 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008137 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00008138 NameInfo,
Richard Smithefeeccf2012-10-21 03:28:35 +00008139 /*TemplateArgs*/ 0,
8140 IsAddressOfOperand);
Douglas Gregorf17bb742009-10-22 17:20:55 +00008141 }
John McCalld5532b62009-11-23 01:53:49 +00008142
8143 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008144 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8145 E->getNumTemplateArgs(),
8146 TransArgs))
8147 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00008148
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00008149 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008150 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00008151 NameInfo,
Richard Smithefeeccf2012-10-21 03:28:35 +00008152 &TransArgs,
8153 IsAddressOfOperand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008154}
8155
8156template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008157ExprResult
John McCall454feb92009-12-08 09:21:05 +00008158TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithc83c2302012-12-19 01:39:02 +00008159 // CXXConstructExprs other than for list-initialization and
8160 // CXXTemporaryObjectExpr are always implicit, so when we have
8161 // a 1-argument construction we just transform that argument.
Richard Smith73ed67c2012-11-26 08:32:48 +00008162 if ((E->getNumArgs() == 1 ||
8163 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithc83c2302012-12-19 01:39:02 +00008164 (!getDerived().DropCallArgument(E->getArg(0))) &&
8165 !E->isListInitialization())
Douglas Gregor321725d2010-02-03 03:01:57 +00008166 return getDerived().TransformExpr(E->getArg(0));
8167
Douglas Gregorb98b1992009-08-11 05:31:07 +00008168 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
8169
8170 QualType T = getDerived().TransformType(E->getType());
8171 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00008172 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00008173
8174 CXXConstructorDecl *Constructor
8175 = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00008176 getDerived().TransformDecl(E->getLocStart(),
8177 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00008178 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00008179 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008180
Douglas Gregorb98b1992009-08-11 05:31:07 +00008181 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008182 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008183 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008184 &ArgumentChanged))
8185 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008186
Douglas Gregorb98b1992009-08-11 05:31:07 +00008187 if (!getDerived().AlwaysRebuild() &&
8188 T == E->getType() &&
8189 Constructor == E->getConstructor() &&
Douglas Gregorc845aad2010-02-26 00:01:57 +00008190 !ArgumentChanged) {
Douglas Gregor1af74512010-02-26 00:38:10 +00008191 // Mark the constructor as referenced.
8192 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00008193 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00008194 return SemaRef.Owned(E);
Douglas Gregorc845aad2010-02-26 00:01:57 +00008195 }
Mike Stump1eb44332009-09-09 15:08:12 +00008196
Douglas Gregor4411d2e2009-12-14 16:27:04 +00008197 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
8198 Constructor, E->isElidable(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008199 Args,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00008200 E->hadMultipleCandidates(),
Richard Smithc83c2302012-12-19 01:39:02 +00008201 E->isListInitialization(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00008202 E->requiresZeroInitialization(),
Chandler Carruth428edaf2010-10-25 08:47:36 +00008203 E->getConstructionKind(),
Enea Zaffanella1245a542013-09-07 05:49:53 +00008204 E->getParenOrBraceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008205}
Mike Stump1eb44332009-09-09 15:08:12 +00008206
Douglas Gregorb98b1992009-08-11 05:31:07 +00008207/// \brief Transform a C++ temporary-binding expression.
8208///
Douglas Gregor51326552009-12-24 18:51:59 +00008209/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
8210/// transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00008211template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008212ExprResult
John McCall454feb92009-12-08 09:21:05 +00008213TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00008214 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008215}
Mike Stump1eb44332009-09-09 15:08:12 +00008216
John McCall4765fa02010-12-06 08:20:24 +00008217/// \brief Transform a C++ expression that contains cleanups that should
8218/// be run after the expression is evaluated.
Douglas Gregorb98b1992009-08-11 05:31:07 +00008219///
John McCall4765fa02010-12-06 08:20:24 +00008220/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor51326552009-12-24 18:51:59 +00008221/// just transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00008222template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008223ExprResult
John McCall4765fa02010-12-06 08:20:24 +00008224TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00008225 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008226}
Mike Stump1eb44332009-09-09 15:08:12 +00008227
Douglas Gregorb98b1992009-08-11 05:31:07 +00008228template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008229ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00008230TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregorab6677e2010-09-08 00:15:04 +00008231 CXXTemporaryObjectExpr *E) {
8232 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8233 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00008234 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008235
Douglas Gregorb98b1992009-08-11 05:31:07 +00008236 CXXConstructorDecl *Constructor
8237 = cast_or_null<CXXConstructorDecl>(
Chad Rosier4a9d7952012-08-08 18:46:20 +00008238 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00008239 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00008240 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00008241 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008242
Douglas Gregorb98b1992009-08-11 05:31:07 +00008243 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008244 SmallVector<Expr*, 8> Args;
Douglas Gregorb98b1992009-08-11 05:31:07 +00008245 Args.reserve(E->getNumArgs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008246 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008247 &ArgumentChanged))
8248 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008249
Douglas Gregorb98b1992009-08-11 05:31:07 +00008250 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00008251 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00008252 Constructor == E->getConstructor() &&
Douglas Gregor91be6f52010-03-02 17:18:33 +00008253 !ArgumentChanged) {
8254 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00008255 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00008256 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor91be6f52010-03-02 17:18:33 +00008257 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008258
Richard Smithc83c2302012-12-19 01:39:02 +00008259 // FIXME: Pass in E->isListInitialization().
Douglas Gregorab6677e2010-09-08 00:15:04 +00008260 return getDerived().RebuildCXXTemporaryObjectExpr(T,
8261 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008262 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008263 E->getLocEnd());
8264}
Mike Stump1eb44332009-09-09 15:08:12 +00008265
Douglas Gregorb98b1992009-08-11 05:31:07 +00008266template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008267ExprResult
Douglas Gregor01d08012012-02-07 10:09:13 +00008268TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Faisal Valifad9e132013-09-26 19:54:12 +00008269
Rafael Espindolaf003acd2013-10-04 14:28:51 +00008270 // FIXME: Implement nested generic lambda transformations.
8271 if (E->isGenericLambda()) {
8272 getSema().Diag(E->getIntroducerRange().getBegin(),
8273 diag::err_glambda_not_fully_implemented)
8274 << " template transformation of generic lambdas not implemented yet";
8275 return ExprError();
Faisal Valifad9e132013-09-26 19:54:12 +00008276 }
Rafael Espindolaf003acd2013-10-04 14:28:51 +00008277 // Transform the type of the lambda parameters and start the definition of
8278 // the lambda itself.
8279 TypeSourceInfo *MethodTy
8280 = TransformType(E->getCallOperator()->getTypeSourceInfo());
8281 if (!MethodTy)
Douglas Gregordfca6f52012-02-13 22:00:16 +00008282 return ExprError();
8283
Eli Friedman8da8a662012-09-19 01:18:11 +00008284 // Create the local class that will describe the lambda.
8285 CXXRecordDecl *Class
8286 = getSema().createLambdaClosureType(E->getIntroducerRange(),
Rafael Espindolaf003acd2013-10-04 14:28:51 +00008287 MethodTy,
Eli Friedman8da8a662012-09-19 01:18:11 +00008288 /*KnownDependent=*/false);
8289 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
8290
Douglas Gregorc6889e72012-02-14 22:28:59 +00008291 // Transform lambda parameters.
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00008292 SmallVector<QualType, 4> ParamTypes;
8293 SmallVector<ParmVarDecl *, 4> Params;
Douglas Gregorc6889e72012-02-14 22:28:59 +00008294 if (getDerived().TransformFunctionTypeParams(E->getLocStart(),
8295 E->getCallOperator()->param_begin(),
8296 E->getCallOperator()->param_size(),
8297 0, ParamTypes, &Params))
Richard Smith612409e2012-07-25 03:56:55 +00008298 return ExprError();
Rafael Espindolaf003acd2013-10-04 14:28:51 +00008299 getSema().PushLambdaScope();
8300 LambdaScopeInfo *LSI = getSema().getCurLambda();
8301 // TODO: Fix for nested lambdas
8302 LSI->GLTemplateParameterList = 0;
Douglas Gregordfca6f52012-02-13 22:00:16 +00008303 // Build the call operator.
Rafael Espindolaf003acd2013-10-04 14:28:51 +00008304 CXXMethodDecl *CallOperator
Douglas Gregordfca6f52012-02-13 22:00:16 +00008305 = getSema().startLambdaDefinition(Class, E->getIntroducerRange(),
Rafael Espindolaf003acd2013-10-04 14:28:51 +00008306 MethodTy,
Douglas Gregorc6889e72012-02-14 22:28:59 +00008307 E->getCallOperator()->getLocEnd(),
Richard Smithadb1d4c2012-07-22 23:45:10 +00008308 Params);
Rafael Espindolaf003acd2013-10-04 14:28:51 +00008309 getDerived().transformAttrs(E->getCallOperator(), CallOperator);
8310
8311 return getDerived().TransformLambdaScope(E, CallOperator);
Richard Smith612409e2012-07-25 03:56:55 +00008312}
8313
8314template<typename Derived>
8315ExprResult
8316TreeTransform<Derived>::TransformLambdaScope(LambdaExpr *E,
8317 CXXMethodDecl *CallOperator) {
Richard Smith0d8e9642013-05-16 06:20:58 +00008318 bool Invalid = false;
8319
8320 // Transform any init-capture expressions before entering the scope of the
8321 // lambda.
Robert Wilhelme7205c02013-08-10 12:33:24 +00008322 SmallVector<ExprResult, 8> InitCaptureExprs;
Richard Smith0d8e9642013-05-16 06:20:58 +00008323 InitCaptureExprs.resize(E->explicit_capture_end() -
8324 E->explicit_capture_begin());
8325 for (LambdaExpr::capture_iterator C = E->capture_begin(),
8326 CEnd = E->capture_end();
8327 C != CEnd; ++C) {
8328 if (!C->isInitCapture())
8329 continue;
8330 InitCaptureExprs[C - E->capture_begin()] =
Richard Smith04fa7a32013-09-28 04:02:39 +00008331 getDerived().TransformInitializer(
8332 C->getCapturedVar()->getInit(),
8333 C->getCapturedVar()->getInitStyle() == VarDecl::CallInit);
Richard Smith0d8e9642013-05-16 06:20:58 +00008334 }
8335
Douglas Gregord5387e82012-02-14 00:00:48 +00008336 // Introduce the context of the call operator.
8337 Sema::ContextRAII SavedContext(getSema(), CallOperator);
8338
Faisal Valifad9e132013-09-26 19:54:12 +00008339 LambdaScopeInfo *const LSI = getSema().getCurLambda();
Douglas Gregordfca6f52012-02-13 22:00:16 +00008340 // Enter the scope of the lambda.
Faisal Valifad9e132013-09-26 19:54:12 +00008341 getSema().buildLambdaScope(LSI, CallOperator, E->getIntroducerRange(),
Douglas Gregordfca6f52012-02-13 22:00:16 +00008342 E->getCaptureDefault(),
James Dennettf68af642013-08-09 23:08:25 +00008343 E->getCaptureDefaultLoc(),
Douglas Gregordfca6f52012-02-13 22:00:16 +00008344 E->hasExplicitParameters(),
8345 E->hasExplicitResultType(),
8346 E->isMutable());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008347
Douglas Gregordfca6f52012-02-13 22:00:16 +00008348 // Transform captures.
Douglas Gregordfca6f52012-02-13 22:00:16 +00008349 bool FinishedExplicitCaptures = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008350 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregordfca6f52012-02-13 22:00:16 +00008351 CEnd = E->capture_end();
8352 C != CEnd; ++C) {
8353 // When we hit the first implicit capture, tell Sema that we've finished
8354 // the list of explicit captures.
8355 if (!FinishedExplicitCaptures && C->isImplicit()) {
8356 getSema().finishLambdaExplicitCaptures(LSI);
8357 FinishedExplicitCaptures = true;
8358 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008359
Douglas Gregordfca6f52012-02-13 22:00:16 +00008360 // Capturing 'this' is trivial.
8361 if (C->capturesThis()) {
8362 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
8363 continue;
8364 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008365
Richard Smith0d8e9642013-05-16 06:20:58 +00008366 // Rebuild init-captures, including the implied field declaration.
8367 if (C->isInitCapture()) {
8368 ExprResult Init = InitCaptureExprs[C - E->capture_begin()];
8369 if (Init.isInvalid()) {
8370 Invalid = true;
8371 continue;
8372 }
Richard Smith04fa7a32013-09-28 04:02:39 +00008373 VarDecl *OldVD = C->getCapturedVar();
8374 VarDecl *NewVD = getSema().checkInitCapture(
8375 C->getLocation(), OldVD->getType()->isReferenceType(),
8376 OldVD->getIdentifier(), Init.take());
8377 if (!NewVD)
Richard Smith0d8e9642013-05-16 06:20:58 +00008378 Invalid = true;
8379 else
Richard Smith04fa7a32013-09-28 04:02:39 +00008380 getDerived().transformedLocalDecl(OldVD, NewVD);
8381 getSema().buildInitCaptureField(LSI, NewVD);
Richard Smith0d8e9642013-05-16 06:20:58 +00008382 continue;
8383 }
8384
8385 assert(C->capturesVariable() && "unexpected kind of lambda capture");
8386
Douglas Gregora7365242012-02-14 19:27:52 +00008387 // Determine the capture kind for Sema.
8388 Sema::TryCaptureKind Kind
8389 = C->isImplicit()? Sema::TryCapture_Implicit
8390 : C->getCaptureKind() == LCK_ByCopy
8391 ? Sema::TryCapture_ExplicitByVal
8392 : Sema::TryCapture_ExplicitByRef;
8393 SourceLocation EllipsisLoc;
8394 if (C->isPackExpansion()) {
8395 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
8396 bool ShouldExpand = false;
8397 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00008398 Optional<unsigned> NumExpansions;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008399 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
8400 C->getLocation(),
Douglas Gregora7365242012-02-14 19:27:52 +00008401 Unexpanded,
8402 ShouldExpand, RetainExpansion,
Richard Smith0d8e9642013-05-16 06:20:58 +00008403 NumExpansions)) {
8404 Invalid = true;
8405 continue;
8406 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008407
Douglas Gregora7365242012-02-14 19:27:52 +00008408 if (ShouldExpand) {
8409 // The transform has determined that we should perform an expansion;
8410 // transform and capture each of the arguments.
8411 // expansion of the pattern. Do so.
8412 VarDecl *Pack = C->getCapturedVar();
8413 for (unsigned I = 0; I != *NumExpansions; ++I) {
8414 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8415 VarDecl *CapturedVar
Chad Rosier4a9d7952012-08-08 18:46:20 +00008416 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregora7365242012-02-14 19:27:52 +00008417 Pack));
8418 if (!CapturedVar) {
8419 Invalid = true;
8420 continue;
8421 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008422
Douglas Gregora7365242012-02-14 19:27:52 +00008423 // Capture the transformed variable.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008424 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
8425 }
Douglas Gregora7365242012-02-14 19:27:52 +00008426 continue;
8427 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008428
Douglas Gregora7365242012-02-14 19:27:52 +00008429 EllipsisLoc = C->getEllipsisLoc();
8430 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008431
Douglas Gregordfca6f52012-02-13 22:00:16 +00008432 // Transform the captured variable.
8433 VarDecl *CapturedVar
Chad Rosier4a9d7952012-08-08 18:46:20 +00008434 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregordfca6f52012-02-13 22:00:16 +00008435 C->getCapturedVar()));
8436 if (!CapturedVar) {
8437 Invalid = true;
8438 continue;
8439 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008440
Douglas Gregordfca6f52012-02-13 22:00:16 +00008441 // Capture the transformed variable.
Douglas Gregor999713e2012-02-18 09:37:24 +00008442 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
Douglas Gregordfca6f52012-02-13 22:00:16 +00008443 }
8444 if (!FinishedExplicitCaptures)
8445 getSema().finishLambdaExplicitCaptures(LSI);
8446
Douglas Gregordfca6f52012-02-13 22:00:16 +00008447
8448 // Enter a new evaluation context to insulate the lambda from any
8449 // cleanups from the enclosing full-expression.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008450 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
Douglas Gregordfca6f52012-02-13 22:00:16 +00008451
8452 if (Invalid) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008453 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
Douglas Gregordfca6f52012-02-13 22:00:16 +00008454 /*IsInstantiation=*/true);
8455 return ExprError();
8456 }
8457
8458 // Instantiate the body of the lambda expression.
Douglas Gregord5387e82012-02-14 00:00:48 +00008459 StmtResult Body = getDerived().TransformStmt(E->getBody());
8460 if (Body.isInvalid()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008461 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
Douglas Gregord5387e82012-02-14 00:00:48 +00008462 /*IsInstantiation=*/true);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008463 return ExprError();
Douglas Gregord5387e82012-02-14 00:00:48 +00008464 }
Douglas Gregorccc1b5e2012-02-21 00:37:24 +00008465
Chad Rosier4a9d7952012-08-08 18:46:20 +00008466 return getSema().ActOnLambdaExpr(E->getLocStart(), Body.take(),
Douglas Gregorf54486a2012-04-04 17:40:10 +00008467 /*CurScope=*/0, /*IsInstantiation=*/true);
Douglas Gregor01d08012012-02-07 10:09:13 +00008468}
8469
8470template<typename Derived>
8471ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00008472TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall454feb92009-12-08 09:21:05 +00008473 CXXUnresolvedConstructExpr *E) {
Douglas Gregorab6677e2010-09-08 00:15:04 +00008474 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8475 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00008476 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008477
Douglas Gregorb98b1992009-08-11 05:31:07 +00008478 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008479 SmallVector<Expr*, 8> Args;
Douglas Gregoraa165f82011-01-03 19:04:46 +00008480 Args.reserve(E->arg_size());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008481 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008482 &ArgumentChanged))
8483 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008484
Douglas Gregorb98b1992009-08-11 05:31:07 +00008485 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00008486 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00008487 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00008488 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008489
Douglas Gregorb98b1992009-08-11 05:31:07 +00008490 // FIXME: we're faking the locations of the commas
Douglas Gregorab6677e2010-09-08 00:15:04 +00008491 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008492 E->getLParenLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008493 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008494 E->getRParenLoc());
8495}
Mike Stump1eb44332009-09-09 15:08:12 +00008496
Douglas Gregorb98b1992009-08-11 05:31:07 +00008497template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008498ExprResult
John McCall865d4472009-11-19 22:55:06 +00008499TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00008500 CXXDependentScopeMemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008501 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008502 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00008503 Expr *OldBase;
8504 QualType BaseType;
8505 QualType ObjectType;
8506 if (!E->isImplicitAccess()) {
8507 OldBase = E->getBase();
8508 Base = getDerived().TransformExpr(OldBase);
8509 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008510 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008511
John McCallaa81e162009-12-01 22:10:20 +00008512 // Start the member reference and compute the object's type.
John McCallb3d87482010-08-24 05:47:05 +00008513 ParsedType ObjectTy;
Douglas Gregord4dca082010-02-24 18:44:31 +00008514 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00008515 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008516 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00008517 E->isArrow()? tok::arrow : tok::period,
Douglas Gregord4dca082010-02-24 18:44:31 +00008518 ObjectTy,
8519 MayBePseudoDestructor);
John McCallaa81e162009-12-01 22:10:20 +00008520 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008521 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00008522
John McCallb3d87482010-08-24 05:47:05 +00008523 ObjectType = ObjectTy.get();
John McCallaa81e162009-12-01 22:10:20 +00008524 BaseType = ((Expr*) Base.get())->getType();
8525 } else {
8526 OldBase = 0;
8527 BaseType = getDerived().TransformType(E->getBaseType());
8528 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
8529 }
Mike Stump1eb44332009-09-09 15:08:12 +00008530
Douglas Gregor6cd21982009-10-20 05:58:46 +00008531 // Transform the first part of the nested-name-specifier that qualifies
8532 // the member name.
Douglas Gregorc68afe22009-09-03 21:38:09 +00008533 NamedDecl *FirstQualifierInScope
Douglas Gregor6cd21982009-10-20 05:58:46 +00008534 = getDerived().TransformFirstQualifierInScope(
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008535 E->getFirstQualifierFoundInScope(),
8536 E->getQualifierLoc().getBeginLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00008537
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008538 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregora38c6872009-09-03 16:14:30 +00008539 if (E->getQualifier()) {
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008540 QualifierLoc
8541 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
8542 ObjectType,
8543 FirstQualifierInScope);
8544 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008545 return ExprError();
Douglas Gregora38c6872009-09-03 16:14:30 +00008546 }
Mike Stump1eb44332009-09-09 15:08:12 +00008547
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008548 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
8549
John McCall43fed0d2010-11-12 08:19:04 +00008550 // TODO: If this is a conversion-function-id, verify that the
8551 // destination type name (if present) resolves the same way after
8552 // instantiation as it did in the local scope.
8553
Abramo Bagnara25777432010-08-11 22:01:17 +00008554 DeclarationNameInfo NameInfo
John McCall43fed0d2010-11-12 08:19:04 +00008555 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnara25777432010-08-11 22:01:17 +00008556 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00008557 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008558
John McCallaa81e162009-12-01 22:10:20 +00008559 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008560 // This is a reference to a member without an explicitly-specified
8561 // template argument list. Optimize for this common case.
8562 if (!getDerived().AlwaysRebuild() &&
John McCallaa81e162009-12-01 22:10:20 +00008563 Base.get() == OldBase &&
8564 BaseType == E->getBaseType() &&
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008565 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00008566 NameInfo.getName() == E->getMember() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008567 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCall3fa5cae2010-10-26 07:05:15 +00008568 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008569
John McCall9ae2f072010-08-23 23:25:46 +00008570 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008571 BaseType,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008572 E->isArrow(),
8573 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008574 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008575 TemplateKWLoc,
John McCall129e2df2009-11-30 22:42:35 +00008576 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00008577 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00008578 /*TemplateArgs*/ 0);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008579 }
8580
John McCalld5532b62009-11-23 01:53:49 +00008581 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008582 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8583 E->getNumTemplateArgs(),
8584 TransArgs))
8585 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008586
John McCall9ae2f072010-08-23 23:25:46 +00008587 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008588 BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008589 E->isArrow(),
8590 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008591 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008592 TemplateKWLoc,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008593 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00008594 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00008595 &TransArgs);
8596}
8597
8598template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008599ExprResult
John McCall454feb92009-12-08 09:21:05 +00008600TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall129e2df2009-11-30 22:42:35 +00008601 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008602 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00008603 QualType BaseType;
8604 if (!Old->isImplicitAccess()) {
8605 Base = getDerived().TransformExpr(Old->getBase());
8606 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008607 return ExprError();
Richard Smith9138b4e2011-10-26 19:06:56 +00008608 Base = getSema().PerformMemberExprBaseConversion(Base.take(),
8609 Old->isArrow());
8610 if (Base.isInvalid())
8611 return ExprError();
8612 BaseType = Base.get()->getType();
John McCallaa81e162009-12-01 22:10:20 +00008613 } else {
8614 BaseType = getDerived().TransformType(Old->getBaseType());
8615 }
John McCall129e2df2009-11-30 22:42:35 +00008616
Douglas Gregor4c9be892011-02-28 20:01:57 +00008617 NestedNameSpecifierLoc QualifierLoc;
8618 if (Old->getQualifierLoc()) {
8619 QualifierLoc
8620 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
8621 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008622 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00008623 }
8624
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008625 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
8626
Abramo Bagnara25777432010-08-11 22:01:17 +00008627 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall129e2df2009-11-30 22:42:35 +00008628 Sema::LookupOrdinaryName);
8629
8630 // Transform all the decls.
8631 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
8632 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00008633 NamedDecl *InstD = static_cast<NamedDecl*>(
8634 getDerived().TransformDecl(Old->getMemberLoc(),
8635 *I));
John McCall9f54ad42009-12-10 09:41:52 +00008636 if (!InstD) {
8637 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
8638 // This can happen because of dependent hiding.
8639 if (isa<UsingShadowDecl>(*I))
8640 continue;
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00008641 else {
8642 R.clear();
John McCallf312b1e2010-08-26 23:41:50 +00008643 return ExprError();
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00008644 }
John McCall9f54ad42009-12-10 09:41:52 +00008645 }
John McCall129e2df2009-11-30 22:42:35 +00008646
8647 // Expand using declarations.
8648 if (isa<UsingDecl>(InstD)) {
8649 UsingDecl *UD = cast<UsingDecl>(InstD);
8650 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
8651 E = UD->shadow_end(); I != E; ++I)
8652 R.addDecl(*I);
8653 continue;
8654 }
8655
8656 R.addDecl(InstD);
8657 }
8658
8659 R.resolveKind();
8660
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008661 // Determine the naming class.
Chandler Carruth042d6f92010-05-19 01:37:01 +00008662 if (Old->getNamingClass()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008663 CXXRecordDecl *NamingClass
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008664 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregor66c45152010-04-27 16:10:10 +00008665 Old->getMemberLoc(),
8666 Old->getNamingClass()));
8667 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00008668 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008669
Douglas Gregor66c45152010-04-27 16:10:10 +00008670 R.setNamingClass(NamingClass);
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008671 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008672
John McCall129e2df2009-11-30 22:42:35 +00008673 TemplateArgumentListInfo TransArgs;
8674 if (Old->hasExplicitTemplateArgs()) {
8675 TransArgs.setLAngleLoc(Old->getLAngleLoc());
8676 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008677 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
8678 Old->getNumTemplateArgs(),
8679 TransArgs))
8680 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00008681 }
John McCallc2233c52010-01-15 08:34:02 +00008682
8683 // FIXME: to do this check properly, we will need to preserve the
8684 // first-qualifier-in-scope here, just in case we had a dependent
8685 // base (and therefore couldn't do the check) and a
8686 // nested-name-qualifier (and therefore could do the lookup).
8687 NamedDecl *FirstQualifierInScope = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008688
John McCall9ae2f072010-08-23 23:25:46 +00008689 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008690 BaseType,
John McCall129e2df2009-11-30 22:42:35 +00008691 Old->getOperatorLoc(),
8692 Old->isArrow(),
Douglas Gregor4c9be892011-02-28 20:01:57 +00008693 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008694 TemplateKWLoc,
John McCallc2233c52010-01-15 08:34:02 +00008695 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00008696 R,
8697 (Old->hasExplicitTemplateArgs()
8698 ? &TransArgs : 0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00008699}
8700
8701template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008702ExprResult
Sebastian Redl2e156222010-09-10 20:55:43 +00008703TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Sean Hunteea06c62011-05-31 19:54:49 +00008704 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl2e156222010-09-10 20:55:43 +00008705 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
8706 if (SubExpr.isInvalid())
8707 return ExprError();
8708
8709 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00008710 return SemaRef.Owned(E);
Sebastian Redl2e156222010-09-10 20:55:43 +00008711
8712 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
8713}
8714
8715template<typename Derived>
8716ExprResult
Douglas Gregorbe230c32011-01-03 17:17:50 +00008717TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor4f1d2822011-01-13 00:19:55 +00008718 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
8719 if (Pattern.isInvalid())
8720 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008721
Douglas Gregor4f1d2822011-01-13 00:19:55 +00008722 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
8723 return SemaRef.Owned(E);
8724
Douglas Gregor67fd1252011-01-14 21:20:45 +00008725 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
8726 E->getNumExpansions());
Douglas Gregorbe230c32011-01-03 17:17:50 +00008727}
Douglas Gregoree8aff02011-01-04 17:33:58 +00008728
8729template<typename Derived>
8730ExprResult
8731TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
8732 // If E is not value-dependent, then nothing will change when we transform it.
8733 // Note: This is an instantiation-centric view.
8734 if (!E->isValueDependent())
8735 return SemaRef.Owned(E);
8736
8737 // Note: None of the implementations of TryExpandParameterPacks can ever
8738 // produce a diagnostic when given only a single unexpanded parameter pack,
Chad Rosier4a9d7952012-08-08 18:46:20 +00008739 // so
Douglas Gregoree8aff02011-01-04 17:33:58 +00008740 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
8741 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00008742 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00008743 Optional<unsigned> NumExpansions;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008744 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikiea71f9d02011-09-22 02:34:54 +00008745 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00008746 ShouldExpand, RetainExpansion,
8747 NumExpansions))
Douglas Gregoree8aff02011-01-04 17:33:58 +00008748 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008749
Douglas Gregor089e8932011-10-10 18:59:29 +00008750 if (RetainExpansion)
Douglas Gregoree8aff02011-01-04 17:33:58 +00008751 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008752
Douglas Gregor089e8932011-10-10 18:59:29 +00008753 NamedDecl *Pack = E->getPack();
8754 if (!ShouldExpand) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008755 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
Douglas Gregor089e8932011-10-10 18:59:29 +00008756 Pack));
8757 if (!Pack)
8758 return ExprError();
8759 }
8760
Chad Rosier4a9d7952012-08-08 18:46:20 +00008761
Douglas Gregoree8aff02011-01-04 17:33:58 +00008762 // We now know the length of the parameter pack, so build a new expression
8763 // that stores that length.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008764 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
8765 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregor089e8932011-10-10 18:59:29 +00008766 NumExpansions);
Douglas Gregoree8aff02011-01-04 17:33:58 +00008767}
8768
Douglas Gregorbe230c32011-01-03 17:17:50 +00008769template<typename Derived>
8770ExprResult
Douglas Gregorc7793c72011-01-15 01:15:58 +00008771TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
8772 SubstNonTypeTemplateParmPackExpr *E) {
8773 // Default behavior is to do nothing with this transformation.
8774 return SemaRef.Owned(E);
8775}
8776
8777template<typename Derived>
8778ExprResult
John McCall91a57552011-07-15 05:09:51 +00008779TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
8780 SubstNonTypeTemplateParmExpr *E) {
8781 // Default behavior is to do nothing with this transformation.
8782 return SemaRef.Owned(E);
8783}
8784
8785template<typename Derived>
8786ExprResult
Richard Smith9a4db032012-09-12 00:56:43 +00008787TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
8788 // Default behavior is to do nothing with this transformation.
8789 return SemaRef.Owned(E);
8790}
8791
8792template<typename Derived>
8793ExprResult
Douglas Gregor03e80032011-06-21 17:03:29 +00008794TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
8795 MaterializeTemporaryExpr *E) {
8796 return getDerived().TransformExpr(E->GetTemporaryExpr());
8797}
Chad Rosier4a9d7952012-08-08 18:46:20 +00008798
Douglas Gregor03e80032011-06-21 17:03:29 +00008799template<typename Derived>
8800ExprResult
Richard Smith7c3e6152013-06-12 22:31:48 +00008801TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
8802 CXXStdInitializerListExpr *E) {
8803 return getDerived().TransformExpr(E->getSubExpr());
8804}
8805
8806template<typename Derived>
8807ExprResult
John McCall454feb92009-12-08 09:21:05 +00008808TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008809 return SemaRef.MaybeBindToTemporary(E);
8810}
8811
8812template<typename Derived>
8813ExprResult
8814TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Jordy Rosed8b5ca12012-03-12 17:53:02 +00008815 return SemaRef.Owned(E);
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008816}
8817
8818template<typename Derived>
8819ExprResult
Patrick Beardeb382ec2012-04-19 00:25:12 +00008820TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
8821 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
8822 if (SubExpr.isInvalid())
8823 return ExprError();
8824
8825 if (!getDerived().AlwaysRebuild() &&
8826 SubExpr.get() == E->getSubExpr())
8827 return SemaRef.Owned(E);
8828
8829 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008830}
8831
8832template<typename Derived>
8833ExprResult
8834TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
8835 // Transform each of the elements.
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00008836 SmallVector<Expr *, 8> Elements;
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008837 bool ArgChanged = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008838 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008839 /*IsCall=*/false, Elements, &ArgChanged))
8840 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008841
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008842 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8843 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008844
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008845 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
8846 Elements.data(),
8847 Elements.size());
8848}
8849
8850template<typename Derived>
8851ExprResult
8852TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier4a9d7952012-08-08 18:46:20 +00008853 ObjCDictionaryLiteral *E) {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008854 // Transform each of the elements.
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00008855 SmallVector<ObjCDictionaryElement, 8> Elements;
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008856 bool ArgChanged = false;
8857 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
8858 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008859
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008860 if (OrigElement.isPackExpansion()) {
8861 // This key/value element is a pack expansion.
8862 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
8863 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
8864 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
8865 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
8866
8867 // Determine whether the set of unexpanded parameter packs can
8868 // and should be expanded.
8869 bool Expand = true;
8870 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00008871 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
8872 Optional<unsigned> NumExpansions = OrigNumExpansions;
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008873 SourceRange PatternRange(OrigElement.Key->getLocStart(),
8874 OrigElement.Value->getLocEnd());
8875 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
8876 PatternRange,
8877 Unexpanded,
8878 Expand, RetainExpansion,
8879 NumExpansions))
8880 return ExprError();
8881
8882 if (!Expand) {
8883 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00008884 // transformation on the pack expansion, producing another pack
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008885 // expansion.
8886 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
8887 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8888 if (Key.isInvalid())
8889 return ExprError();
8890
8891 if (Key.get() != OrigElement.Key)
8892 ArgChanged = true;
8893
8894 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8895 if (Value.isInvalid())
8896 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008897
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008898 if (Value.get() != OrigElement.Value)
8899 ArgChanged = true;
8900
Chad Rosier4a9d7952012-08-08 18:46:20 +00008901 ObjCDictionaryElement Expansion = {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008902 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
8903 };
8904 Elements.push_back(Expansion);
8905 continue;
8906 }
8907
8908 // Record right away that the argument was changed. This needs
8909 // to happen even if the array expands to nothing.
8910 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008911
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008912 // The transform has determined that we should perform an elementwise
8913 // expansion of the pattern. Do so.
8914 for (unsigned I = 0; I != *NumExpansions; ++I) {
8915 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8916 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8917 if (Key.isInvalid())
8918 return ExprError();
8919
8920 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8921 if (Value.isInvalid())
8922 return ExprError();
8923
Chad Rosier4a9d7952012-08-08 18:46:20 +00008924 ObjCDictionaryElement Element = {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008925 Key.get(), Value.get(), SourceLocation(), NumExpansions
8926 };
8927
8928 // If any unexpanded parameter packs remain, we still have a
8929 // pack expansion.
8930 if (Key.get()->containsUnexpandedParameterPack() ||
8931 Value.get()->containsUnexpandedParameterPack())
8932 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008933
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008934 Elements.push_back(Element);
8935 }
8936
8937 // We've finished with this pack expansion.
8938 continue;
8939 }
8940
8941 // Transform and check key.
8942 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8943 if (Key.isInvalid())
8944 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008945
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008946 if (Key.get() != OrigElement.Key)
8947 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008948
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008949 // Transform and check value.
8950 ExprResult Value
8951 = getDerived().TransformExpr(OrigElement.Value);
8952 if (Value.isInvalid())
8953 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008954
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008955 if (Value.get() != OrigElement.Value)
8956 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008957
8958 ObjCDictionaryElement Element = {
David Blaikie66874fb2013-02-21 01:47:18 +00008959 Key.get(), Value.get(), SourceLocation(), None
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008960 };
8961 Elements.push_back(Element);
8962 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008963
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008964 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8965 return SemaRef.MaybeBindToTemporary(E);
8966
8967 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
8968 Elements.data(),
8969 Elements.size());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008970}
8971
Mike Stump1eb44332009-09-09 15:08:12 +00008972template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008973ExprResult
John McCall454feb92009-12-08 09:21:05 +00008974TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregor81d34662010-04-20 15:39:42 +00008975 TypeSourceInfo *EncodedTypeInfo
8976 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
8977 if (!EncodedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00008978 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008979
Douglas Gregorb98b1992009-08-11 05:31:07 +00008980 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor81d34662010-04-20 15:39:42 +00008981 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00008982 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008983
8984 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregor81d34662010-04-20 15:39:42 +00008985 EncodedTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008986 E->getRParenLoc());
8987}
Mike Stump1eb44332009-09-09 15:08:12 +00008988
Douglas Gregorb98b1992009-08-11 05:31:07 +00008989template<typename Derived>
John McCallf85e1932011-06-15 23:02:42 +00008990ExprResult TreeTransform<Derived>::
8991TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
John McCall93b64572013-04-11 02:14:26 +00008992 // This is a kind of implicit conversion, and it needs to get dropped
8993 // and recomputed for the same general reasons that ImplicitCastExprs
8994 // do, as well a more specific one: this expression is only valid when
8995 // it appears *immediately* as an argument expression.
8996 return getDerived().TransformExpr(E->getSubExpr());
John McCallf85e1932011-06-15 23:02:42 +00008997}
8998
8999template<typename Derived>
9000ExprResult TreeTransform<Derived>::
9001TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00009002 TypeSourceInfo *TSInfo
John McCallf85e1932011-06-15 23:02:42 +00009003 = getDerived().TransformType(E->getTypeInfoAsWritten());
9004 if (!TSInfo)
9005 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00009006
John McCallf85e1932011-06-15 23:02:42 +00009007 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier4a9d7952012-08-08 18:46:20 +00009008 if (Result.isInvalid())
John McCallf85e1932011-06-15 23:02:42 +00009009 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00009010
John McCallf85e1932011-06-15 23:02:42 +00009011 if (!getDerived().AlwaysRebuild() &&
9012 TSInfo == E->getTypeInfoAsWritten() &&
9013 Result.get() == E->getSubExpr())
9014 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00009015
John McCallf85e1932011-06-15 23:02:42 +00009016 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00009017 E->getBridgeKeywordLoc(), TSInfo,
John McCallf85e1932011-06-15 23:02:42 +00009018 Result.get());
9019}
9020
9021template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009022ExprResult
John McCall454feb92009-12-08 09:21:05 +00009023TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00009024 // Transform arguments.
9025 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00009026 SmallVector<Expr*, 8> Args;
Douglas Gregoraa165f82011-01-03 19:04:46 +00009027 Args.reserve(E->getNumArgs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00009028 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00009029 &ArgChanged))
9030 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00009031
Douglas Gregor92e986e2010-04-22 16:44:27 +00009032 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
9033 // Class message: transform the receiver type.
9034 TypeSourceInfo *ReceiverTypeInfo
9035 = getDerived().TransformType(E->getClassReceiverTypeInfo());
9036 if (!ReceiverTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00009037 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00009038
Douglas Gregor92e986e2010-04-22 16:44:27 +00009039 // If nothing changed, just retain the existing message send.
9040 if (!getDerived().AlwaysRebuild() &&
9041 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00009042 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor92e986e2010-04-22 16:44:27 +00009043
9044 // Build a new class message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00009045 SmallVector<SourceLocation, 16> SelLocs;
9046 E->getSelectorLocs(SelLocs);
Douglas Gregor92e986e2010-04-22 16:44:27 +00009047 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
9048 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00009049 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00009050 E->getMethodDecl(),
9051 E->getLeftLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009052 Args,
Douglas Gregor92e986e2010-04-22 16:44:27 +00009053 E->getRightLoc());
9054 }
9055
9056 // Instance message: transform the receiver
9057 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
9058 "Only class and instance messages may be instantiated");
John McCall60d7b3a2010-08-24 06:29:42 +00009059 ExprResult Receiver
Douglas Gregor92e986e2010-04-22 16:44:27 +00009060 = getDerived().TransformExpr(E->getInstanceReceiver());
9061 if (Receiver.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009062 return ExprError();
Douglas Gregor92e986e2010-04-22 16:44:27 +00009063
9064 // If nothing changed, just retain the existing message send.
9065 if (!getDerived().AlwaysRebuild() &&
9066 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00009067 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00009068
Douglas Gregor92e986e2010-04-22 16:44:27 +00009069 // Build a new instance message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00009070 SmallVector<SourceLocation, 16> SelLocs;
9071 E->getSelectorLocs(SelLocs);
John McCall9ae2f072010-08-23 23:25:46 +00009072 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00009073 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00009074 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00009075 E->getMethodDecl(),
9076 E->getLeftLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009077 Args,
Douglas Gregor92e986e2010-04-22 16:44:27 +00009078 E->getRightLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00009079}
9080
Mike Stump1eb44332009-09-09 15:08:12 +00009081template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009082ExprResult
John McCall454feb92009-12-08 09:21:05 +00009083TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00009084 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009085}
9086
Mike Stump1eb44332009-09-09 15:08:12 +00009087template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009088ExprResult
John McCall454feb92009-12-08 09:21:05 +00009089TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00009090 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009091}
9092
Mike Stump1eb44332009-09-09 15:08:12 +00009093template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009094ExprResult
John McCall454feb92009-12-08 09:21:05 +00009095TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009096 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00009097 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009098 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009099 return ExprError();
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009100
9101 // We don't need to transform the ivar; it will never change.
Chad Rosier4a9d7952012-08-08 18:46:20 +00009102
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009103 // If nothing changed, just retain the existing expression.
9104 if (!getDerived().AlwaysRebuild() &&
9105 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00009106 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00009107
John McCall9ae2f072010-08-23 23:25:46 +00009108 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009109 E->getLocation(),
9110 E->isArrow(), E->isFreeIvar());
Douglas Gregorb98b1992009-08-11 05:31:07 +00009111}
9112
Mike Stump1eb44332009-09-09 15:08:12 +00009113template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009114ExprResult
John McCall454feb92009-12-08 09:21:05 +00009115TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCall12f78a62010-12-02 01:19:52 +00009116 // 'super' and types never change. Property never changes. Just
9117 // retain the existing expression.
9118 if (!E->isObjectReceiver())
John McCall3fa5cae2010-10-26 07:05:15 +00009119 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00009120
Douglas Gregore3303542010-04-26 20:47:02 +00009121 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00009122 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregore3303542010-04-26 20:47:02 +00009123 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009124 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00009125
Douglas Gregore3303542010-04-26 20:47:02 +00009126 // We don't need to transform the property; it will never change.
Chad Rosier4a9d7952012-08-08 18:46:20 +00009127
Douglas Gregore3303542010-04-26 20:47:02 +00009128 // If nothing changed, just retain the existing expression.
9129 if (!getDerived().AlwaysRebuild() &&
9130 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00009131 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009132
John McCall12f78a62010-12-02 01:19:52 +00009133 if (E->isExplicitProperty())
9134 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
9135 E->getExplicitProperty(),
9136 E->getLocation());
9137
9138 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall3c3b7f92011-10-25 17:37:35 +00009139 SemaRef.Context.PseudoObjectTy,
John McCall12f78a62010-12-02 01:19:52 +00009140 E->getImplicitPropertyGetter(),
9141 E->getImplicitPropertySetter(),
9142 E->getLocation());
Douglas Gregorb98b1992009-08-11 05:31:07 +00009143}
9144
Mike Stump1eb44332009-09-09 15:08:12 +00009145template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009146ExprResult
Ted Kremenekebcb57a2012-03-06 20:05:56 +00009147TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
9148 // Transform the base expression.
9149 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
9150 if (Base.isInvalid())
9151 return ExprError();
9152
9153 // Transform the key expression.
9154 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
9155 if (Key.isInvalid())
9156 return ExprError();
9157
9158 // If nothing changed, just retain the existing expression.
9159 if (!getDerived().AlwaysRebuild() &&
9160 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
9161 return SemaRef.Owned(E);
9162
Chad Rosier4a9d7952012-08-08 18:46:20 +00009163 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremenekebcb57a2012-03-06 20:05:56 +00009164 Base.get(), Key.get(),
9165 E->getAtIndexMethodDecl(),
9166 E->setAtIndexMethodDecl());
9167}
9168
9169template<typename Derived>
9170ExprResult
John McCall454feb92009-12-08 09:21:05 +00009171TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009172 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00009173 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009174 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009175 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00009176
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009177 // If nothing changed, just retain the existing expression.
9178 if (!getDerived().AlwaysRebuild() &&
9179 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00009180 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00009181
John McCall9ae2f072010-08-23 23:25:46 +00009182 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Fariborz Jahanianec8deba2013-03-28 19:50:55 +00009183 E->getOpLoc(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009184 E->isArrow());
Douglas Gregorb98b1992009-08-11 05:31:07 +00009185}
9186
Mike Stump1eb44332009-09-09 15:08:12 +00009187template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009188ExprResult
John McCall454feb92009-12-08 09:21:05 +00009189TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009190 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00009191 SmallVector<Expr*, 8> SubExprs;
Douglas Gregoraa165f82011-01-03 19:04:46 +00009192 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00009193 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregoraa165f82011-01-03 19:04:46 +00009194 SubExprs, &ArgumentChanged))
9195 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009196
Douglas Gregorb98b1992009-08-11 05:31:07 +00009197 if (!getDerived().AlwaysRebuild() &&
9198 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00009199 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00009200
Douglas Gregorb98b1992009-08-11 05:31:07 +00009201 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009202 SubExprs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00009203 E->getRParenLoc());
9204}
9205
Mike Stump1eb44332009-09-09 15:08:12 +00009206template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009207ExprResult
Hal Finkel414a1bd2013-09-18 03:29:45 +00009208TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) {
9209 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
9210 if (SrcExpr.isInvalid())
9211 return ExprError();
9212
9213 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
9214 if (!Type)
9215 return ExprError();
9216
9217 if (!getDerived().AlwaysRebuild() &&
9218 Type == E->getTypeSourceInfo() &&
9219 SrcExpr.get() == E->getSrcExpr())
9220 return SemaRef.Owned(E);
9221
9222 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
9223 SrcExpr.get(), Type,
9224 E->getRParenLoc());
9225}
9226
9227template<typename Derived>
9228ExprResult
John McCall454feb92009-12-08 09:21:05 +00009229TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCallc6ac9c32011-02-04 18:33:18 +00009230 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier4a9d7952012-08-08 18:46:20 +00009231
John McCallc6ac9c32011-02-04 18:33:18 +00009232 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
9233 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
9234
9235 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahanian05865202011-12-03 17:47:53 +00009236 blockScope->TheDecl->setBlockMissingReturnType(
9237 oldBlock->blockMissingReturnType());
Chad Rosier4a9d7952012-08-08 18:46:20 +00009238
Chris Lattner686775d2011-07-20 06:58:45 +00009239 SmallVector<ParmVarDecl*, 4> params;
9240 SmallVector<QualType, 4> paramTypes;
Chad Rosier4a9d7952012-08-08 18:46:20 +00009241
Fariborz Jahaniana729da22010-07-09 18:44:02 +00009242 // Parameter substitution.
John McCallc6ac9c32011-02-04 18:33:18 +00009243 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
9244 oldBlock->param_begin(),
9245 oldBlock->param_size(),
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00009246 0, paramTypes, &params)) {
9247 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregor92be2a52011-12-10 00:23:21 +00009248 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00009249 }
John McCallc6ac9c32011-02-04 18:33:18 +00009250
Jordan Rose09189892013-03-08 22:25:36 +00009251 const FunctionProtoType *exprFunctionType = E->getFunctionType();
Eli Friedman84b007f2012-01-26 03:00:14 +00009252 QualType exprResultType =
9253 getDerived().TransformType(exprFunctionType->getResultType());
Douglas Gregora779d9c2011-01-19 21:32:01 +00009254
Jordan Rosebea522f2013-03-08 21:51:21 +00009255 QualType functionType =
9256 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes,
Jordan Rose09189892013-03-08 22:25:36 +00009257 exprFunctionType->getExtProtoInfo());
John McCallc6ac9c32011-02-04 18:33:18 +00009258 blockScope->FunctionType = functionType;
John McCall711c52b2011-01-05 12:14:39 +00009259
9260 // Set the parameters on the block decl.
John McCallc6ac9c32011-02-04 18:33:18 +00009261 if (!params.empty())
David Blaikie4278c652011-09-21 18:16:56 +00009262 blockScope->TheDecl->setParams(params);
Eli Friedman84b007f2012-01-26 03:00:14 +00009263
9264 if (!oldBlock->blockMissingReturnType()) {
9265 blockScope->HasImplicitReturnType = false;
9266 blockScope->ReturnType = exprResultType;
9267 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00009268
John McCall711c52b2011-01-05 12:14:39 +00009269 // Transform the body
John McCallc6ac9c32011-02-04 18:33:18 +00009270 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00009271 if (body.isInvalid()) {
9272 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
John McCall711c52b2011-01-05 12:14:39 +00009273 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00009274 }
John McCall711c52b2011-01-05 12:14:39 +00009275
John McCallc6ac9c32011-02-04 18:33:18 +00009276#ifndef NDEBUG
9277 // In builds with assertions, make sure that we captured everything we
9278 // captured before.
Douglas Gregorfc921372011-05-20 15:32:55 +00009279 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
9280 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
9281 e = oldBlock->capture_end(); i != e; ++i) {
9282 VarDecl *oldCapture = i->getVariable();
John McCallc6ac9c32011-02-04 18:33:18 +00009283
Douglas Gregorfc921372011-05-20 15:32:55 +00009284 // Ignore parameter packs.
9285 if (isa<ParmVarDecl>(oldCapture) &&
9286 cast<ParmVarDecl>(oldCapture)->isParameterPack())
9287 continue;
John McCallc6ac9c32011-02-04 18:33:18 +00009288
Douglas Gregorfc921372011-05-20 15:32:55 +00009289 VarDecl *newCapture =
9290 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
9291 oldCapture));
9292 assert(blockScope->CaptureMap.count(newCapture));
9293 }
Douglas Gregorec79d872012-02-24 17:41:38 +00009294 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCallc6ac9c32011-02-04 18:33:18 +00009295 }
9296#endif
9297
9298 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
9299 /*Scope=*/0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009300}
9301
Mike Stump1eb44332009-09-09 15:08:12 +00009302template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009303ExprResult
Tanya Lattner61eee0c2011-06-04 00:47:47 +00009304TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikieb219cfc2011-09-23 05:06:16 +00009305 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner61eee0c2011-06-04 00:47:47 +00009306}
Eli Friedman276b0612011-10-11 02:20:01 +00009307
9308template<typename Derived>
9309ExprResult
9310TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedmandfa64ba2011-10-14 22:48:56 +00009311 QualType RetTy = getDerived().TransformType(E->getType());
9312 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00009313 SmallVector<Expr*, 8> SubExprs;
Eli Friedmandfa64ba2011-10-14 22:48:56 +00009314 SubExprs.reserve(E->getNumSubExprs());
9315 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
9316 SubExprs, &ArgumentChanged))
9317 return ExprError();
9318
9319 if (!getDerived().AlwaysRebuild() &&
9320 !ArgumentChanged)
9321 return SemaRef.Owned(E);
9322
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009323 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedmandfa64ba2011-10-14 22:48:56 +00009324 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedman276b0612011-10-11 02:20:01 +00009325}
Chad Rosier4a9d7952012-08-08 18:46:20 +00009326
Douglas Gregorb98b1992009-08-11 05:31:07 +00009327//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00009328// Type reconstruction
9329//===----------------------------------------------------------------------===//
9330
Mike Stump1eb44332009-09-09 15:08:12 +00009331template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00009332QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
9333 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00009334 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009335 getDerived().getBaseEntity());
9336}
9337
Mike Stump1eb44332009-09-09 15:08:12 +00009338template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00009339QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
9340 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00009341 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009342 getDerived().getBaseEntity());
9343}
9344
Mike Stump1eb44332009-09-09 15:08:12 +00009345template<typename Derived>
9346QualType
John McCall85737a72009-10-30 00:06:24 +00009347TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
9348 bool WrittenAsLValue,
9349 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00009350 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall85737a72009-10-30 00:06:24 +00009351 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00009352}
9353
9354template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009355QualType
John McCall85737a72009-10-30 00:06:24 +00009356TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
9357 QualType ClassType,
9358 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00009359 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall85737a72009-10-30 00:06:24 +00009360 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00009361}
9362
9363template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009364QualType
Douglas Gregor577f75a2009-08-04 16:50:30 +00009365TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
9366 ArrayType::ArraySizeModifier SizeMod,
9367 const llvm::APInt *Size,
9368 Expr *SizeExpr,
9369 unsigned IndexTypeQuals,
9370 SourceRange BracketsRange) {
9371 if (SizeExpr || !Size)
9372 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
9373 IndexTypeQuals, BracketsRange,
9374 getDerived().getBaseEntity());
Mike Stump1eb44332009-09-09 15:08:12 +00009375
9376 QualType Types[] = {
9377 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
9378 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
9379 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregor577f75a2009-08-04 16:50:30 +00009380 };
Craig Topperb9602322013-07-15 03:38:40 +00009381 const unsigned NumTypes = llvm::array_lengthof(Types);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009382 QualType SizeType;
9383 for (unsigned I = 0; I != NumTypes; ++I)
9384 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
9385 SizeType = Types[I];
9386 break;
9387 }
Mike Stump1eb44332009-09-09 15:08:12 +00009388
Eli Friedman01f276d2012-01-25 23:20:27 +00009389 // Note that we can return a VariableArrayType here in the case where
9390 // the element type was a dependent VariableArrayType.
9391 IntegerLiteral *ArraySize
9392 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
9393 /*FIXME*/BracketsRange.getBegin());
9394 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009395 IndexTypeQuals, BracketsRange,
Mike Stump1eb44332009-09-09 15:08:12 +00009396 getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00009397}
Mike Stump1eb44332009-09-09 15:08:12 +00009398
Douglas Gregor577f75a2009-08-04 16:50:30 +00009399template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009400QualType
9401TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009402 ArrayType::ArraySizeModifier SizeMod,
9403 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +00009404 unsigned IndexTypeQuals,
9405 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009406 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall85737a72009-10-30 00:06:24 +00009407 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009408}
9409
9410template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009411QualType
Mike Stump1eb44332009-09-09 15:08:12 +00009412TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009413 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +00009414 unsigned IndexTypeQuals,
9415 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009416 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall85737a72009-10-30 00:06:24 +00009417 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009418}
Mike Stump1eb44332009-09-09 15:08:12 +00009419
Douglas Gregor577f75a2009-08-04 16:50:30 +00009420template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009421QualType
9422TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009423 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00009424 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009425 unsigned IndexTypeQuals,
9426 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009427 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00009428 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009429 IndexTypeQuals, BracketsRange);
9430}
9431
9432template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009433QualType
9434TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009435 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00009436 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009437 unsigned IndexTypeQuals,
9438 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009439 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00009440 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009441 IndexTypeQuals, BracketsRange);
9442}
9443
9444template<typename Derived>
9445QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsone86d78c2010-11-10 21:56:12 +00009446 unsigned NumElements,
9447 VectorType::VectorKind VecKind) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00009448 // FIXME: semantic checking!
Bob Wilsone86d78c2010-11-10 21:56:12 +00009449 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009450}
Mike Stump1eb44332009-09-09 15:08:12 +00009451
Douglas Gregor577f75a2009-08-04 16:50:30 +00009452template<typename Derived>
9453QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
9454 unsigned NumElements,
9455 SourceLocation AttributeLoc) {
9456 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
9457 NumElements, true);
9458 IntegerLiteral *VectorSize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00009459 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
9460 AttributeLoc);
John McCall9ae2f072010-08-23 23:25:46 +00009461 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009462}
Mike Stump1eb44332009-09-09 15:08:12 +00009463
Douglas Gregor577f75a2009-08-04 16:50:30 +00009464template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009465QualType
9466TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00009467 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009468 SourceLocation AttributeLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00009469 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009470}
Mike Stump1eb44332009-09-09 15:08:12 +00009471
Douglas Gregor577f75a2009-08-04 16:50:30 +00009472template<typename Derived>
Jordan Rosebea522f2013-03-08 21:51:21 +00009473QualType TreeTransform<Derived>::RebuildFunctionProtoType(
9474 QualType T,
9475 llvm::MutableArrayRef<QualType> ParamTypes,
Jordan Rose09189892013-03-08 22:25:36 +00009476 const FunctionProtoType::ExtProtoInfo &EPI) {
9477 return SemaRef.BuildFunctionType(T, ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009478 getDerived().getBaseLocation(),
Eli Friedmanfa869542010-08-05 02:54:05 +00009479 getDerived().getBaseEntity(),
Jordan Rose09189892013-03-08 22:25:36 +00009480 EPI);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009481}
Mike Stump1eb44332009-09-09 15:08:12 +00009482
Douglas Gregor577f75a2009-08-04 16:50:30 +00009483template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00009484QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
9485 return SemaRef.Context.getFunctionNoProtoType(T);
9486}
9487
9488template<typename Derived>
John McCalled976492009-12-04 22:46:56 +00009489QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
9490 assert(D && "no decl found");
9491 if (D->isInvalidDecl()) return QualType();
9492
Douglas Gregor92e986e2010-04-22 16:44:27 +00009493 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCalled976492009-12-04 22:46:56 +00009494 TypeDecl *Ty;
9495 if (isa<UsingDecl>(D)) {
9496 UsingDecl *Using = cast<UsingDecl>(D);
Enea Zaffanella8d030c72013-07-22 10:54:09 +00009497 assert(Using->hasTypename() &&
John McCalled976492009-12-04 22:46:56 +00009498 "UnresolvedUsingTypenameDecl transformed to non-typename using");
9499
9500 // A valid resolved using typename decl points to exactly one type decl.
9501 assert(++Using->shadow_begin() == Using->shadow_end());
9502 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Chad Rosier4a9d7952012-08-08 18:46:20 +00009503
John McCalled976492009-12-04 22:46:56 +00009504 } else {
9505 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
9506 "UnresolvedUsingTypenameDecl transformed to non-using decl");
9507 Ty = cast<UnresolvedUsingTypenameDecl>(D);
9508 }
9509
9510 return SemaRef.Context.getTypeDeclType(Ty);
9511}
9512
9513template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00009514QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
9515 SourceLocation Loc) {
9516 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009517}
9518
9519template<typename Derived>
9520QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
9521 return SemaRef.Context.getTypeOfType(Underlying);
9522}
9523
9524template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00009525QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
9526 SourceLocation Loc) {
9527 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009528}
9529
9530template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00009531QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
9532 UnaryTransformType::UTTKind UKind,
9533 SourceLocation Loc) {
9534 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
9535}
9536
9537template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00009538QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00009539 TemplateName Template,
9540 SourceLocation TemplateNameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +00009541 TemplateArgumentListInfo &TemplateArgs) {
John McCalld5532b62009-11-23 01:53:49 +00009542 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009543}
Mike Stump1eb44332009-09-09 15:08:12 +00009544
Douglas Gregordcee1a12009-08-06 05:28:30 +00009545template<typename Derived>
Eli Friedmanb001de72011-10-06 23:00:33 +00009546QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
9547 SourceLocation KWLoc) {
9548 return SemaRef.BuildAtomicType(ValueType, KWLoc);
9549}
9550
9551template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009552TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009553TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +00009554 bool TemplateKW,
9555 TemplateDecl *Template) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009556 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregord1067e52009-08-06 06:41:21 +00009557 Template);
9558}
9559
9560template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009561TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009562TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
9563 const IdentifierInfo &Name,
9564 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +00009565 QualType ObjectType,
9566 NamedDecl *FirstQualifierInScope) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009567 UnqualifiedId TemplateName;
9568 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregord6ab2322010-06-16 23:00:59 +00009569 Sema::TemplateTy Template;
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009570 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00009571 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009572 SS, TemplateKWLoc, TemplateName,
John McCallb3d87482010-08-24 05:47:05 +00009573 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00009574 /*EnteringContext=*/false,
9575 Template);
John McCall43fed0d2010-11-12 08:19:04 +00009576 return Template.get();
Douglas Gregord1067e52009-08-06 06:41:21 +00009577}
Mike Stump1eb44332009-09-09 15:08:12 +00009578
Douglas Gregorb98b1992009-08-11 05:31:07 +00009579template<typename Derived>
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009580TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009581TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009582 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009583 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009584 QualType ObjectType) {
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009585 UnqualifiedId Name;
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009586 // FIXME: Bogus location information.
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009587 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009588 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009589 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00009590 Sema::TemplateTy Template;
9591 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009592 SS, TemplateKWLoc, Name,
John McCallb3d87482010-08-24 05:47:05 +00009593 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00009594 /*EnteringContext=*/false,
9595 Template);
Serge Pavlov18062392013-08-27 13:15:56 +00009596 return Template.get();
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009597}
Chad Rosier4a9d7952012-08-08 18:46:20 +00009598
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009599template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009600ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00009601TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
9602 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00009603 Expr *OrigCallee,
9604 Expr *First,
9605 Expr *Second) {
9606 Expr *Callee = OrigCallee->IgnoreParenCasts();
9607 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump1eb44332009-09-09 15:08:12 +00009608
Douglas Gregorb98b1992009-08-11 05:31:07 +00009609 // Determine whether this should be a builtin operation.
Sebastian Redlf322ed62009-10-29 20:17:01 +00009610 if (Op == OO_Subscript) {
John McCall9ae2f072010-08-23 23:25:46 +00009611 if (!First->getType()->isOverloadableType() &&
9612 !Second->getType()->isOverloadableType())
9613 return getSema().CreateBuiltinArraySubscriptExpr(First,
9614 Callee->getLocStart(),
9615 Second, OpLoc);
Eli Friedman1a3c75f2009-11-16 19:13:03 +00009616 } else if (Op == OO_Arrow) {
9617 // -> is never a builtin operation.
John McCall9ae2f072010-08-23 23:25:46 +00009618 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
9619 } else if (Second == 0 || isPostIncDec) {
9620 if (!First->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009621 // The argument is not of overloadable type, so try to create a
9622 // built-in unary operation.
John McCall2de56d12010-08-25 11:45:40 +00009623 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00009624 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump1eb44332009-09-09 15:08:12 +00009625
John McCall9ae2f072010-08-23 23:25:46 +00009626 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009627 }
9628 } else {
John McCall9ae2f072010-08-23 23:25:46 +00009629 if (!First->getType()->isOverloadableType() &&
9630 !Second->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009631 // Neither of the arguments is an overloadable type, so try to
9632 // create a built-in binary operation.
John McCall2de56d12010-08-25 11:45:40 +00009633 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00009634 ExprResult Result
John McCall9ae2f072010-08-23 23:25:46 +00009635 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009636 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009637 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009638
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009639 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00009640 }
9641 }
Mike Stump1eb44332009-09-09 15:08:12 +00009642
9643 // Compute the transformed set of functions (and function templates) to be
Douglas Gregorb98b1992009-08-11 05:31:07 +00009644 // used during overload resolution.
John McCall6e266892010-01-26 03:27:55 +00009645 UnresolvedSet<16> Functions;
Mike Stump1eb44332009-09-09 15:08:12 +00009646
John McCall9ae2f072010-08-23 23:25:46 +00009647 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCallba135432009-11-21 08:51:07 +00009648 assert(ULE->requiresADL());
9649
9650 // FIXME: Do we have to check
9651 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall6e266892010-01-26 03:27:55 +00009652 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCallba135432009-11-21 08:51:07 +00009653 } else {
Richard Smithf6411662012-11-28 21:47:39 +00009654 // If we've resolved this to a particular non-member function, just call
9655 // that function. If we resolved it to a member function,
9656 // CreateOverloaded* will find that function for us.
9657 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
9658 if (!isa<CXXMethodDecl>(ND))
9659 Functions.addDecl(ND);
John McCallba135432009-11-21 08:51:07 +00009660 }
Mike Stump1eb44332009-09-09 15:08:12 +00009661
Douglas Gregorb98b1992009-08-11 05:31:07 +00009662 // Add any functions found via argument-dependent lookup.
John McCall9ae2f072010-08-23 23:25:46 +00009663 Expr *Args[2] = { First, Second };
9664 unsigned NumArgs = 1 + (Second != 0);
Mike Stump1eb44332009-09-09 15:08:12 +00009665
Douglas Gregorb98b1992009-08-11 05:31:07 +00009666 // Create the overloaded operator invocation for unary operators.
9667 if (NumArgs == 1 || isPostIncDec) {
John McCall2de56d12010-08-25 11:45:40 +00009668 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00009669 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCall9ae2f072010-08-23 23:25:46 +00009670 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009671 }
Mike Stump1eb44332009-09-09 15:08:12 +00009672
Douglas Gregor5b8968c2011-07-15 16:25:15 +00009673 if (Op == OO_Subscript) {
9674 SourceLocation LBrace;
9675 SourceLocation RBrace;
9676
9677 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
9678 DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
9679 LBrace = SourceLocation::getFromRawEncoding(
9680 NameLoc.CXXOperatorName.BeginOpNameLoc);
9681 RBrace = SourceLocation::getFromRawEncoding(
9682 NameLoc.CXXOperatorName.EndOpNameLoc);
9683 } else {
9684 LBrace = Callee->getLocStart();
9685 RBrace = OpLoc;
9686 }
9687
9688 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
9689 First, Second);
9690 }
Sebastian Redlf322ed62009-10-29 20:17:01 +00009691
Douglas Gregorb98b1992009-08-11 05:31:07 +00009692 // Create the overloaded operator invocation for binary operators.
John McCall2de56d12010-08-25 11:45:40 +00009693 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00009694 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00009695 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
9696 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009697 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009698
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009699 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00009700}
Mike Stump1eb44332009-09-09 15:08:12 +00009701
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009702template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00009703ExprResult
John McCall9ae2f072010-08-23 23:25:46 +00009704TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009705 SourceLocation OperatorLoc,
9706 bool isArrow,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00009707 CXXScopeSpec &SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009708 TypeSourceInfo *ScopeType,
9709 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00009710 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009711 PseudoDestructorTypeStorage Destroyed) {
John McCall9ae2f072010-08-23 23:25:46 +00009712 QualType BaseType = Base->getType();
9713 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009714 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier4a9d7952012-08-08 18:46:20 +00009715 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greifbf2ca2f2010-02-25 13:04:33 +00009716 !BaseType->getAs<PointerType>()->getPointeeType()
9717 ->template getAs<RecordType>())){
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009718 // This pseudo-destructor expression is still a pseudo-destructor.
John McCall9ae2f072010-08-23 23:25:46 +00009719 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009720 isArrow? tok::arrow : tok::period,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00009721 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009722 Destroyed,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009723 /*FIXME?*/true);
9724 }
Abramo Bagnara25777432010-08-11 22:01:17 +00009725
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009726 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnara25777432010-08-11 22:01:17 +00009727 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
9728 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
9729 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
9730 NameInfo.setNamedTypeInfo(DestroyedType);
9731
Richard Smith6314db92012-05-15 06:15:11 +00009732 // The scope type is now known to be a valid nested name specifier
9733 // component. Tack it on to the end of the nested name specifier.
9734 if (ScopeType)
9735 SS.Extend(SemaRef.Context, SourceLocation(),
9736 ScopeType->getTypeLoc(), CCLoc);
Abramo Bagnara25777432010-08-11 22:01:17 +00009737
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009738 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCall9ae2f072010-08-23 23:25:46 +00009739 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009740 OperatorLoc, isArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009741 SS, TemplateKWLoc,
9742 /*FIXME: FirstQualifier*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00009743 NameInfo,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009744 /*TemplateArgs*/ 0);
9745}
9746
Tareq A. Siraj051303c2013-04-16 18:53:08 +00009747template<typename Derived>
9748StmtResult
9749TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
Wei Pan9fd6b8f2013-05-04 03:59:06 +00009750 SourceLocation Loc = S->getLocStart();
9751 unsigned NumParams = S->getCapturedDecl()->getNumParams();
9752 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/0,
9753 S->getCapturedRegionKind(), NumParams);
9754 StmtResult Body = getDerived().TransformStmt(S->getCapturedStmt());
9755
9756 if (Body.isInvalid()) {
9757 getSema().ActOnCapturedRegionError();
9758 return StmtError();
9759 }
9760
9761 return getSema().ActOnCapturedRegionEnd(Body.take());
Tareq A. Siraj051303c2013-04-16 18:53:08 +00009762}
9763
Douglas Gregor577f75a2009-08-04 16:50:30 +00009764} // end namespace clang
9765
9766#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H