blob: 4b70e702b6b20bea2307d4292da302f8480161d1 [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.
Richard Smithbaa9af12013-11-07 20:07:17 +0000145 ///
146 /// We must always rebuild all AST nodes when performing variadic template
147 /// pack expansion, in order to avoid violating the AST invariant that each
148 /// statement node appears at most once in its containing declaration.
149 bool AlwaysRebuild() { return SemaRef.ArgumentPackSubstitutionIndex != -1; }
Mike Stump1eb44332009-09-09 15:08:12 +0000150
Douglas Gregor577f75a2009-08-04 16:50:30 +0000151 /// \brief Returns the location of the entity being transformed, if that
152 /// information was not available elsewhere in the AST.
153 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000154 /// By default, returns no source-location information. Subclasses can
Douglas Gregor577f75a2009-08-04 16:50:30 +0000155 /// provide an alternative implementation that provides better location
156 /// information.
157 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump1eb44332009-09-09 15:08:12 +0000158
Douglas Gregor577f75a2009-08-04 16:50:30 +0000159 /// \brief Returns the name of the entity being transformed, if that
160 /// information was not available elsewhere in the AST.
161 ///
162 /// By default, returns an empty name. Subclasses can provide an alternative
163 /// implementation with a more precise name.
164 DeclarationName getBaseEntity() { return DeclarationName(); }
165
Douglas Gregorb98b1992009-08-11 05:31:07 +0000166 /// \brief Sets the "base" location and entity when that
167 /// information is known based on another transformation.
168 ///
169 /// By default, the source location and entity are ignored. Subclasses can
170 /// override this function to provide a customized implementation.
171 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump1eb44332009-09-09 15:08:12 +0000172
Douglas Gregorb98b1992009-08-11 05:31:07 +0000173 /// \brief RAII object that temporarily sets the base location and entity
174 /// used for reporting diagnostics in types.
175 class TemporaryBase {
176 TreeTransform &Self;
177 SourceLocation OldLocation;
178 DeclarationName OldEntity;
Mike Stump1eb44332009-09-09 15:08:12 +0000179
Douglas Gregorb98b1992009-08-11 05:31:07 +0000180 public:
181 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump1eb44332009-09-09 15:08:12 +0000182 DeclarationName Entity) : Self(Self) {
Douglas Gregorb98b1992009-08-11 05:31:07 +0000183 OldLocation = Self.getDerived().getBaseLocation();
184 OldEntity = Self.getDerived().getBaseEntity();
Chad Rosier4a9d7952012-08-08 18:46:20 +0000185
Douglas Gregorae201f72011-01-25 17:51:48 +0000186 if (Location.isValid())
187 Self.getDerived().setBase(Location, Entity);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000188 }
Mike Stump1eb44332009-09-09 15:08:12 +0000189
Douglas Gregorb98b1992009-08-11 05:31:07 +0000190 ~TemporaryBase() {
191 Self.getDerived().setBase(OldLocation, OldEntity);
192 }
193 };
Mike Stump1eb44332009-09-09 15:08:12 +0000194
195 /// \brief Determine whether the given type \p T has already been
Douglas Gregor577f75a2009-08-04 16:50:30 +0000196 /// transformed.
197 ///
198 /// Subclasses can provide an alternative implementation of this routine
Mike Stump1eb44332009-09-09 15:08:12 +0000199 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregor577f75a2009-08-04 16:50:30 +0000200 /// not change. For example, template instantiation need not traverse
201 /// non-dependent types.
202 bool AlreadyTransformed(QualType T) {
203 return T.isNull();
204 }
205
Douglas Gregor6eef5192009-12-14 19:27:10 +0000206 /// \brief Determine whether the given call argument should be dropped, e.g.,
207 /// because it is a default argument.
208 ///
209 /// Subclasses can provide an alternative implementation of this routine to
210 /// determine which kinds of call arguments get dropped. By default,
211 /// CXXDefaultArgument nodes are dropped (prior to transformation).
212 bool DropCallArgument(Expr *E) {
213 return E->isDefaultArgument();
214 }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000215
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000216 /// \brief Determine whether we should expand a pack expansion with the
217 /// given set of parameter packs into separate arguments by repeatedly
218 /// transforming the pattern.
219 ///
Douglas Gregorb99268b2010-12-21 00:52:54 +0000220 /// By default, the transformer never tries to expand pack expansions.
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000221 /// Subclasses can override this routine to provide different behavior.
222 ///
223 /// \param EllipsisLoc The location of the ellipsis that identifies the
224 /// pack expansion.
225 ///
226 /// \param PatternRange The source range that covers the entire pattern of
227 /// the pack expansion.
228 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000229 /// \param Unexpanded The set of unexpanded parameter packs within the
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000230 /// pattern.
231 ///
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000232 /// \param ShouldExpand Will be set to \c true if the transformer should
233 /// expand the corresponding pack expansions into separate arguments. When
234 /// set, \c NumExpansions must also be set.
235 ///
Douglas Gregord3731192011-01-10 07:32:04 +0000236 /// \param RetainExpansion Whether the caller should add an unexpanded
237 /// pack expansion after all of the expanded arguments. This is used
238 /// when extending explicitly-specified template argument packs per
239 /// C++0x [temp.arg.explicit]p9.
240 ///
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000241 /// \param NumExpansions The number of separate arguments that will be in
Douglas Gregorcded4f62011-01-14 17:04:44 +0000242 /// the expanded form of the corresponding pack expansion. This is both an
243 /// input and an output parameter, which can be set by the caller if the
244 /// number of expansions is known a priori (e.g., due to a prior substitution)
245 /// and will be set by the callee when the number of expansions is known.
246 /// The callee must set this value when \c ShouldExpand is \c true; it may
247 /// set this value in other cases.
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000248 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000249 /// \returns true if an error occurred (e.g., because the parameter packs
250 /// are to be instantiated with arguments of different lengths), false
251 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000252 /// must be set.
253 bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
254 SourceRange PatternRange,
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +0000255 ArrayRef<UnexpandedParameterPack> Unexpanded,
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000256 bool &ShouldExpand,
Douglas Gregord3731192011-01-10 07:32:04 +0000257 bool &RetainExpansion,
David Blaikiedc84cd52013-02-20 22:23:23 +0000258 Optional<unsigned> &NumExpansions) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000259 ShouldExpand = false;
260 return false;
261 }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000262
Douglas Gregord3731192011-01-10 07:32:04 +0000263 /// \brief "Forget" about the partially-substituted pack template argument,
264 /// when performing an instantiation that must preserve the parameter pack
265 /// use.
266 ///
267 /// This routine is meant to be overridden by the template instantiator.
268 TemplateArgument ForgetPartiallySubstitutedPack() {
269 return TemplateArgument();
270 }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000271
Douglas Gregord3731192011-01-10 07:32:04 +0000272 /// \brief "Remember" the partially-substituted pack template argument
273 /// after performing an instantiation that must preserve the parameter pack
274 /// use.
275 ///
276 /// This routine is meant to be overridden by the template instantiator.
277 void RememberPartiallySubstitutedPack(TemplateArgument Arg) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000278
Douglas Gregor12c9c002011-01-07 16:43:16 +0000279 /// \brief Note to the derived class when a function parameter pack is
280 /// being expanded.
281 void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000282
Douglas Gregor577f75a2009-08-04 16:50:30 +0000283 /// \brief Transforms the given type into another type.
284 ///
John McCalla2becad2009-10-21 00:40:46 +0000285 /// By default, this routine transforms a type by creating a
John McCalla93c9342009-12-07 02:54:59 +0000286 /// TypeSourceInfo for it and delegating to the appropriate
John McCalla2becad2009-10-21 00:40:46 +0000287 /// function. This is expensive, but we don't mind, because
288 /// this method is deprecated anyway; all users should be
John McCalla93c9342009-12-07 02:54:59 +0000289 /// switched to storing TypeSourceInfos.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000290 ///
291 /// \returns the transformed type.
John McCall43fed0d2010-11-12 08:19:04 +0000292 QualType TransformType(QualType T);
Mike Stump1eb44332009-09-09 15:08:12 +0000293
John McCalla2becad2009-10-21 00:40:46 +0000294 /// \brief Transforms the given type-with-location into a new
295 /// type-with-location.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000296 ///
John McCalla2becad2009-10-21 00:40:46 +0000297 /// By default, this routine transforms a type by delegating to the
298 /// appropriate TransformXXXType to build a new type. Subclasses
299 /// may override this function (to take over all type
300 /// transformations) or some set of the TransformXXXType functions
301 /// to alter the transformation.
John McCall43fed0d2010-11-12 08:19:04 +0000302 TypeSourceInfo *TransformType(TypeSourceInfo *DI);
John McCalla2becad2009-10-21 00:40:46 +0000303
304 /// \brief Transform the given type-with-location into a new
305 /// type, collecting location information in the given builder
306 /// as necessary.
307 ///
John McCall43fed0d2010-11-12 08:19:04 +0000308 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
Mike Stump1eb44332009-09-09 15:08:12 +0000309
Douglas Gregor657c1ac2009-08-06 22:17:10 +0000310 /// \brief Transform the given statement.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000311 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000312 /// By default, this routine transforms a statement by delegating to the
Douglas Gregor43959a92009-08-20 07:17:43 +0000313 /// appropriate TransformXXXStmt function to transform a specific kind of
314 /// statement or the TransformExpr() function to transform an expression.
315 /// Subclasses may override this function to transform statements using some
316 /// other mechanism.
317 ///
318 /// \returns the transformed statement.
John McCall60d7b3a2010-08-24 06:29:42 +0000319 StmtResult TransformStmt(Stmt *S);
Mike Stump1eb44332009-09-09 15:08:12 +0000320
Alexey Bataev4fa7eab2013-07-19 03:13:43 +0000321 /// \brief Transform the given statement.
322 ///
323 /// By default, this routine transforms a statement by delegating to the
324 /// appropriate TransformOMPXXXClause function to transform a specific kind
325 /// of clause. Subclasses may override this function to transform statements
326 /// using some other mechanism.
327 ///
328 /// \returns the transformed OpenMP clause.
329 OMPClause *TransformOMPClause(OMPClause *S);
330
Douglas Gregor657c1ac2009-08-06 22:17:10 +0000331 /// \brief Transform the given expression.
332 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +0000333 /// By default, this routine transforms an expression by delegating to the
334 /// appropriate TransformXXXExpr function to build a new expression.
335 /// Subclasses may override this function to transform expressions using some
336 /// other mechanism.
337 ///
338 /// \returns the transformed expression.
John McCall60d7b3a2010-08-24 06:29:42 +0000339 ExprResult TransformExpr(Expr *E);
Mike Stump1eb44332009-09-09 15:08:12 +0000340
Richard Smithc83c2302012-12-19 01:39:02 +0000341 /// \brief Transform the given initializer.
342 ///
343 /// By default, this routine transforms an initializer by stripping off the
344 /// semantic nodes added by initialization, then passing the result to
345 /// TransformExpr or TransformExprs.
346 ///
347 /// \returns the transformed initializer.
348 ExprResult TransformInitializer(Expr *Init, bool CXXDirectInit);
349
Douglas Gregoraa165f82011-01-03 19:04:46 +0000350 /// \brief Transform the given list of expressions.
351 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000352 /// This routine transforms a list of expressions by invoking
353 /// \c TransformExpr() for each subexpression. However, it also provides
Douglas Gregoraa165f82011-01-03 19:04:46 +0000354 /// support for variadic templates by expanding any pack expansions (if the
355 /// derived class permits such expansion) along the way. When pack expansions
356 /// are present, the number of outputs may not equal the number of inputs.
357 ///
358 /// \param Inputs The set of expressions to be transformed.
359 ///
360 /// \param NumInputs The number of expressions in \c Inputs.
361 ///
362 /// \param IsCall If \c true, then this transform is being performed on
Chad Rosier4a9d7952012-08-08 18:46:20 +0000363 /// function-call arguments, and any arguments that should be dropped, will
Douglas Gregoraa165f82011-01-03 19:04:46 +0000364 /// be.
365 ///
366 /// \param Outputs The transformed input expressions will be added to this
367 /// vector.
368 ///
369 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
370 /// due to transformation.
371 ///
372 /// \returns true if an error occurred, false otherwise.
373 bool TransformExprs(Expr **Inputs, unsigned NumInputs, bool IsCall,
Chris Lattner686775d2011-07-20 06:58:45 +0000374 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +0000375 bool *ArgChanged = 0);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000376
Douglas Gregor577f75a2009-08-04 16:50:30 +0000377 /// \brief Transform the given declaration, which is referenced from a type
378 /// or expression.
379 ///
Douglas Gregordfca6f52012-02-13 22:00:16 +0000380 /// By default, acts as the identity function on declarations, unless the
381 /// transformer has had to transform the declaration itself. Subclasses
Douglas Gregordcee1a12009-08-06 05:28:30 +0000382 /// may override this function to provide alternate behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +0000383 Decl *TransformDecl(SourceLocation Loc, Decl *D) {
Douglas Gregordfca6f52012-02-13 22:00:16 +0000384 llvm::DenseMap<Decl *, Decl *>::iterator Known
385 = TransformedLocalDecls.find(D);
386 if (Known != TransformedLocalDecls.end())
387 return Known->second;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000388
389 return D;
Douglas Gregordfca6f52012-02-13 22:00:16 +0000390 }
Douglas Gregor43959a92009-08-20 07:17:43 +0000391
Chad Rosier4a9d7952012-08-08 18:46:20 +0000392 /// \brief Transform the attributes associated with the given declaration and
Douglas Gregordfca6f52012-02-13 22:00:16 +0000393 /// place them on the new declaration.
394 ///
395 /// By default, this operation does nothing. Subclasses may override this
396 /// behavior to transform attributes.
397 void transformAttrs(Decl *Old, Decl *New) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000398
Douglas Gregordfca6f52012-02-13 22:00:16 +0000399 /// \brief Note that a local declaration has been transformed by this
400 /// transformer.
401 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000402 /// Local declarations are typically transformed via a call to
Douglas Gregordfca6f52012-02-13 22:00:16 +0000403 /// TransformDefinition. However, in some cases (e.g., lambda expressions),
404 /// the transformer itself has to transform the declarations. This routine
405 /// can be overridden by a subclass that keeps track of such mappings.
406 void transformedLocalDecl(Decl *Old, Decl *New) {
407 TransformedLocalDecls[Old] = New;
408 }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000409
Douglas Gregor43959a92009-08-20 07:17:43 +0000410 /// \brief Transform the definition of the given declaration.
411 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000412 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregor43959a92009-08-20 07:17:43 +0000413 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +0000414 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
415 return getDerived().TransformDecl(Loc, D);
Douglas Gregor7c1e98f2010-03-01 15:56:25 +0000416 }
Mike Stump1eb44332009-09-09 15:08:12 +0000417
Douglas Gregor6cd21982009-10-20 05:58:46 +0000418 /// \brief Transform the given declaration, which was the first part of a
419 /// nested-name-specifier in a member access expression.
420 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000421 /// This specific declaration transformation only applies to the first
Douglas Gregor6cd21982009-10-20 05:58:46 +0000422 /// identifier in a nested-name-specifier of a member access expression, e.g.,
423 /// the \c T in \c x->T::member
424 ///
425 /// By default, invokes TransformDecl() to transform the declaration.
426 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +0000427 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
428 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregor6cd21982009-10-20 05:58:46 +0000429 }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000430
Douglas Gregorc22b5ff2011-02-25 02:25:35 +0000431 /// \brief Transform the given nested-name-specifier with source-location
432 /// information.
433 ///
434 /// By default, transforms all of the types and declarations within the
435 /// nested-name-specifier. Subclasses may override this function to provide
436 /// alternate behavior.
437 NestedNameSpecifierLoc TransformNestedNameSpecifierLoc(
438 NestedNameSpecifierLoc NNS,
439 QualType ObjectType = QualType(),
440 NamedDecl *FirstQualifierInScope = 0);
441
Douglas Gregor81499bb2009-09-03 22:13:48 +0000442 /// \brief Transform the given declaration name.
443 ///
444 /// By default, transforms the types of conversion function, constructor,
445 /// and destructor names and then (if needed) rebuilds the declaration name.
446 /// Identifiers and selectors are returned unmodified. Sublcasses may
447 /// override this function to provide alternate behavior.
Abramo Bagnara25777432010-08-11 22:01:17 +0000448 DeclarationNameInfo
John McCall43fed0d2010-11-12 08:19:04 +0000449 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump1eb44332009-09-09 15:08:12 +0000450
Douglas Gregor577f75a2009-08-04 16:50:30 +0000451 /// \brief Transform the given template name.
Mike Stump1eb44332009-09-09 15:08:12 +0000452 ///
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000453 /// \param SS The nested-name-specifier that qualifies the template
454 /// name. This nested-name-specifier must already have been transformed.
455 ///
456 /// \param Name The template name to transform.
457 ///
458 /// \param NameLoc The source location of the template name.
459 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000460 /// \param ObjectType If we're translating a template name within a member
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000461 /// access expression, this is the type of the object whose member template
462 /// is being referenced.
463 ///
464 /// \param FirstQualifierInScope If the first part of a nested-name-specifier
465 /// also refers to a name within the current (lexical) scope, this is the
466 /// declaration it refers to.
467 ///
468 /// By default, transforms the template name by transforming the declarations
469 /// and nested-name-specifiers that occur within the template name.
470 /// Subclasses may override this function to provide alternate behavior.
471 TemplateName TransformTemplateName(CXXScopeSpec &SS,
472 TemplateName Name,
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000473 SourceLocation NameLoc,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000474 QualType ObjectType = QualType(),
475 NamedDecl *FirstQualifierInScope = 0);
476
Douglas Gregor577f75a2009-08-04 16:50:30 +0000477 /// \brief Transform the given template argument.
478 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000479 /// By default, this operation transforms the type, expression, or
480 /// declaration stored within the template argument and constructs a
Douglas Gregor670444e2009-08-04 22:27:00 +0000481 /// new template argument from the transformed result. Subclasses may
482 /// override this function to provide alternate behavior.
John McCall833ca992009-10-29 08:12:44 +0000483 ///
484 /// Returns true if there was an error.
485 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
486 TemplateArgumentLoc &Output);
487
Douglas Gregorfcc12532010-12-20 17:31:10 +0000488 /// \brief Transform the given set of template arguments.
489 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000490 /// By default, this operation transforms all of the template arguments
Douglas Gregorfcc12532010-12-20 17:31:10 +0000491 /// in the input set using \c TransformTemplateArgument(), and appends
492 /// the transformed arguments to the output list.
493 ///
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000494 /// Note that this overload of \c TransformTemplateArguments() is merely
495 /// a convenience function. Subclasses that wish to override this behavior
496 /// should override the iterator-based member template version.
497 ///
Douglas Gregorfcc12532010-12-20 17:31:10 +0000498 /// \param Inputs The set of template arguments to be transformed.
499 ///
500 /// \param NumInputs The number of template arguments in \p Inputs.
501 ///
502 /// \param Outputs The set of transformed template arguments output by this
503 /// routine.
504 ///
505 /// Returns true if an error occurred.
506 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
507 unsigned NumInputs,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000508 TemplateArgumentListInfo &Outputs) {
509 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs);
510 }
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000511
512 /// \brief Transform the given set of template arguments.
513 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000514 /// By default, this operation transforms all of the template arguments
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000515 /// in the input set using \c TransformTemplateArgument(), and appends
Chad Rosier4a9d7952012-08-08 18:46:20 +0000516 /// the transformed arguments to the output list.
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000517 ///
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000518 /// \param First An iterator to the first template argument.
519 ///
520 /// \param Last An iterator one step past the last template argument.
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000521 ///
522 /// \param Outputs The set of transformed template arguments output by this
523 /// routine.
524 ///
525 /// Returns true if an error occurred.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000526 template<typename InputIterator>
527 bool TransformTemplateArguments(InputIterator First,
528 InputIterator Last,
529 TemplateArgumentListInfo &Outputs);
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000530
John McCall833ca992009-10-29 08:12:44 +0000531 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
532 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
533 TemplateArgumentLoc &ArgLoc);
534
John McCalla93c9342009-12-07 02:54:59 +0000535 /// \brief Fakes up a TypeSourceInfo for a type.
536 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
537 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall833ca992009-10-29 08:12:44 +0000538 getDerived().getBaseLocation());
539 }
Mike Stump1eb44332009-09-09 15:08:12 +0000540
John McCalla2becad2009-10-21 00:40:46 +0000541#define ABSTRACT_TYPELOC(CLASS, PARENT)
542#define TYPELOC(CLASS, PARENT) \
John McCall43fed0d2010-11-12 08:19:04 +0000543 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCalla2becad2009-10-21 00:40:46 +0000544#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +0000545
Douglas Gregorcefc3af2012-04-16 07:05:22 +0000546 QualType TransformFunctionProtoType(TypeLocBuilder &TLB,
547 FunctionProtoTypeLoc TL,
548 CXXRecordDecl *ThisContext,
549 unsigned ThisTypeQuals);
550
David Majnemerfc210492013-10-15 09:33:02 +0000551 StmtResult TransformSEHHandler(Stmt *Handler);
John Wiegley28bbe4b2011-04-28 01:08:34 +0000552
Chad Rosier4a9d7952012-08-08 18:46:20 +0000553 QualType
John McCall43fed0d2010-11-12 08:19:04 +0000554 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
555 TemplateSpecializationTypeLoc TL,
556 TemplateName Template);
557
Chad Rosier4a9d7952012-08-08 18:46:20 +0000558 QualType
John McCall43fed0d2010-11-12 08:19:04 +0000559 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
560 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +0000561 TemplateName Template,
562 CXXScopeSpec &SS);
Douglas Gregora88f09f2011-02-28 17:23:35 +0000563
Chad Rosier4a9d7952012-08-08 18:46:20 +0000564 QualType
Douglas Gregora88f09f2011-02-28 17:23:35 +0000565 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000566 DependentTemplateSpecializationTypeLoc TL,
567 NestedNameSpecifierLoc QualifierLoc);
568
John McCall21ef0fa2010-03-11 09:03:00 +0000569 /// \brief Transforms the parameters of a function type into the
570 /// given vectors.
571 ///
572 /// The result vectors should be kept in sync; null entries in the
573 /// variables vector are acceptable.
574 ///
575 /// Return true on error.
Douglas Gregora009b592011-01-07 00:20:55 +0000576 bool TransformFunctionTypeParams(SourceLocation Loc,
577 ParmVarDecl **Params, unsigned NumParams,
578 const QualType *ParamTypes,
Chris Lattner686775d2011-07-20 06:58:45 +0000579 SmallVectorImpl<QualType> &PTypes,
580 SmallVectorImpl<ParmVarDecl*> *PVars);
John McCall21ef0fa2010-03-11 09:03:00 +0000581
582 /// \brief Transforms a single function-type parameter. Return null
583 /// on error.
John McCallfb44de92011-05-01 22:35:37 +0000584 ///
585 /// \param indexAdjustment - A number to add to the parameter's
586 /// scope index; can be negative
Douglas Gregor6a24bfd2011-01-14 22:40:04 +0000587 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCallfb44de92011-05-01 22:35:37 +0000588 int indexAdjustment,
David Blaikiedc84cd52013-02-20 22:23:23 +0000589 Optional<unsigned> NumExpansions,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +0000590 bool ExpectParameterPack);
John McCall21ef0fa2010-03-11 09:03:00 +0000591
John McCall43fed0d2010-11-12 08:19:04 +0000592 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall833ca992009-10-29 08:12:44 +0000593
John McCall60d7b3a2010-08-24 06:29:42 +0000594 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
595 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Mike Stump1eb44332009-09-09 15:08:12 +0000596
Richard Smith612409e2012-07-25 03:56:55 +0000597 /// \brief Transform the captures and body of a lambda expression.
598 ExprResult TransformLambdaScope(LambdaExpr *E, CXXMethodDecl *CallOperator);
599
Faisal Valia3d311e2013-10-23 06:44:28 +0000600 TemplateParameterList *TransformTemplateParameterList(
601 TemplateParameterList *TPL) {
602 return TPL;
603 }
604
Richard Smithefeeccf2012-10-21 03:28:35 +0000605 ExprResult TransformAddressOfOperand(Expr *E);
606 ExprResult TransformDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E,
607 bool IsAddressOfOperand);
608
Eli Friedman1ac6c932013-09-06 01:13:30 +0000609// FIXME: We use LLVM_ATTRIBUTE_NOINLINE because inlining causes a ridiculous
610// amount of stack usage with clang.
Douglas Gregor43959a92009-08-20 07:17:43 +0000611#define STMT(Node, Parent) \
Eli Friedman1ac6c932013-09-06 01:13:30 +0000612 LLVM_ATTRIBUTE_NOINLINE \
John McCall60d7b3a2010-08-24 06:29:42 +0000613 StmtResult Transform##Node(Node *S);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000614#define EXPR(Node, Parent) \
Eli Friedman1ac6c932013-09-06 01:13:30 +0000615 LLVM_ATTRIBUTE_NOINLINE \
John McCall60d7b3a2010-08-24 06:29:42 +0000616 ExprResult Transform##Node(Node *E);
Sean Hunt7381d5c2010-05-18 06:22:21 +0000617#define ABSTRACT_STMT(Stmt)
Sean Hunt4bfe1962010-05-05 15:24:00 +0000618#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +0000619
Alexey Bataev4fa7eab2013-07-19 03:13:43 +0000620#define OPENMP_CLAUSE(Name, Class) \
Eli Friedman1ac6c932013-09-06 01:13:30 +0000621 LLVM_ATTRIBUTE_NOINLINE \
Alexey Bataev4fa7eab2013-07-19 03:13:43 +0000622 OMPClause *Transform ## Class(Class *S);
623#include "clang/Basic/OpenMPKinds.def"
624
Douglas Gregor577f75a2009-08-04 16:50:30 +0000625 /// \brief Build a new pointer type given its pointee type.
626 ///
627 /// By default, performs semantic analysis when building the pointer type.
628 /// Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000629 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000630
631 /// \brief Build a new block pointer type given its pointee type.
632 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000633 /// By default, performs semantic analysis when building the block pointer
Douglas Gregor577f75a2009-08-04 16:50:30 +0000634 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000635 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000636
John McCall85737a72009-10-30 00:06:24 +0000637 /// \brief Build a new reference type given the type it references.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000638 ///
John McCall85737a72009-10-30 00:06:24 +0000639 /// By default, performs semantic analysis when building the
640 /// reference type. Subclasses may override this routine to provide
641 /// different behavior.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000642 ///
John McCall85737a72009-10-30 00:06:24 +0000643 /// \param LValue whether the type was written with an lvalue sigil
644 /// or an rvalue sigil.
645 QualType RebuildReferenceType(QualType ReferentType,
646 bool LValue,
647 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000648
Douglas Gregor577f75a2009-08-04 16:50:30 +0000649 /// \brief Build a new member pointer type given the pointee type and the
650 /// class type it refers into.
651 ///
652 /// By default, performs semantic analysis when building the member pointer
653 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000654 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
655 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000656
Douglas Gregor577f75a2009-08-04 16:50:30 +0000657 /// \brief Build a new array type given the element type, size
658 /// modifier, size of the array (if known), size expression, and index type
659 /// qualifiers.
660 ///
661 /// By default, performs semantic analysis when building the array type.
662 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000663 /// Also by default, all of the other Rebuild*Array
Douglas Gregor577f75a2009-08-04 16:50:30 +0000664 QualType RebuildArrayType(QualType ElementType,
665 ArrayType::ArraySizeModifier SizeMod,
666 const llvm::APInt *Size,
667 Expr *SizeExpr,
668 unsigned IndexTypeQuals,
669 SourceRange BracketsRange);
Mike Stump1eb44332009-09-09 15:08:12 +0000670
Douglas Gregor577f75a2009-08-04 16:50:30 +0000671 /// \brief Build a new constant array type given the element type, size
672 /// modifier, (known) size of the array, and index type qualifiers.
673 ///
674 /// By default, performs semantic analysis when building the array type.
675 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000676 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000677 ArrayType::ArraySizeModifier SizeMod,
678 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +0000679 unsigned IndexTypeQuals,
680 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000681
Douglas Gregor577f75a2009-08-04 16:50:30 +0000682 /// \brief Build a new incomplete array type given the element type, size
683 /// modifier, and index type qualifiers.
684 ///
685 /// By default, performs semantic analysis when building the array type.
686 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000687 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000688 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +0000689 unsigned IndexTypeQuals,
690 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000691
Mike Stump1eb44332009-09-09 15:08:12 +0000692 /// \brief Build a new variable-length array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000693 /// size modifier, size expression, and index type qualifiers.
694 ///
695 /// By default, performs semantic analysis when building the array type.
696 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000697 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000698 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +0000699 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000700 unsigned IndexTypeQuals,
701 SourceRange BracketsRange);
702
Mike Stump1eb44332009-09-09 15:08:12 +0000703 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000704 /// size modifier, size expression, and index type qualifiers.
705 ///
706 /// By default, performs semantic analysis when building the array type.
707 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000708 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000709 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +0000710 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000711 unsigned IndexTypeQuals,
712 SourceRange BracketsRange);
713
714 /// \brief Build a new vector type given the element type and
715 /// number of elements.
716 ///
717 /// By default, performs semantic analysis when building the vector type.
718 /// Subclasses may override this routine to provide different behavior.
John Thompson82287d12010-02-05 00:12:22 +0000719 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsone86d78c2010-11-10 21:56:12 +0000720 VectorType::VectorKind VecKind);
Mike Stump1eb44332009-09-09 15:08:12 +0000721
Douglas Gregor577f75a2009-08-04 16:50:30 +0000722 /// \brief Build a new extended vector type given the element type and
723 /// number of elements.
724 ///
725 /// By default, performs semantic analysis when building the vector type.
726 /// Subclasses may override this routine to provide different behavior.
727 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
728 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000729
730 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregor577f75a2009-08-04 16:50:30 +0000731 /// given the element type and number of elements.
732 ///
733 /// By default, performs semantic analysis when building the vector type.
734 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000735 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +0000736 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000737 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000738
Douglas Gregor577f75a2009-08-04 16:50:30 +0000739 /// \brief Build a new function type.
740 ///
741 /// By default, performs semantic analysis when building the function type.
742 /// Subclasses may override this routine to provide different behavior.
743 QualType RebuildFunctionProtoType(QualType T,
Jordan Rosebea522f2013-03-08 21:51:21 +0000744 llvm::MutableArrayRef<QualType> ParamTypes,
Jordan Rose09189892013-03-08 22:25:36 +0000745 const FunctionProtoType::ExtProtoInfo &EPI);
Mike Stump1eb44332009-09-09 15:08:12 +0000746
John McCalla2becad2009-10-21 00:40:46 +0000747 /// \brief Build a new unprototyped function type.
748 QualType RebuildFunctionNoProtoType(QualType ResultType);
749
John McCalled976492009-12-04 22:46:56 +0000750 /// \brief Rebuild an unresolved typename type, given the decl that
751 /// the UnresolvedUsingTypenameDecl was transformed to.
752 QualType RebuildUnresolvedUsingType(Decl *D);
753
Douglas Gregor577f75a2009-08-04 16:50:30 +0000754 /// \brief Build a new typedef type.
Richard Smith162e1c12011-04-15 14:24:37 +0000755 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
Douglas Gregor577f75a2009-08-04 16:50:30 +0000756 return SemaRef.Context.getTypeDeclType(Typedef);
757 }
758
759 /// \brief Build a new class/struct/union type.
760 QualType RebuildRecordType(RecordDecl *Record) {
761 return SemaRef.Context.getTypeDeclType(Record);
762 }
763
764 /// \brief Build a new Enum type.
765 QualType RebuildEnumType(EnumDecl *Enum) {
766 return SemaRef.Context.getTypeDeclType(Enum);
767 }
John McCall7da24312009-09-05 00:15:47 +0000768
Mike Stump1eb44332009-09-09 15:08:12 +0000769 /// \brief Build a new typeof(expr) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000770 ///
771 /// By default, performs semantic analysis when building the typeof type.
772 /// Subclasses may override this routine to provide different behavior.
John McCall2a984ca2010-10-12 00:20:44 +0000773 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000774
Mike Stump1eb44332009-09-09 15:08:12 +0000775 /// \brief Build a new typeof(type) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000776 ///
777 /// By default, builds a new TypeOfType with the given underlying type.
778 QualType RebuildTypeOfType(QualType Underlying);
779
Sean Huntca63c202011-05-24 22:41:36 +0000780 /// \brief Build a new unary transform type.
781 QualType RebuildUnaryTransformType(QualType BaseType,
782 UnaryTransformType::UTTKind UKind,
783 SourceLocation Loc);
784
Richard Smitha2c36462013-04-26 16:15:35 +0000785 /// \brief Build a new C++11 decltype type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000786 ///
787 /// By default, performs semantic analysis when building the decltype type.
788 /// Subclasses may override this routine to provide different behavior.
John McCall2a984ca2010-10-12 00:20:44 +0000789 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump1eb44332009-09-09 15:08:12 +0000790
Richard Smitha2c36462013-04-26 16:15:35 +0000791 /// \brief Build a new C++11 auto type.
Richard Smith34b41d92011-02-20 03:19:35 +0000792 ///
793 /// By default, builds a new AutoType with the given deduced type.
Richard Smitha2c36462013-04-26 16:15:35 +0000794 QualType RebuildAutoType(QualType Deduced, bool IsDecltypeAuto) {
Richard Smithdc7a4f52013-04-30 13:56:41 +0000795 // Note, IsDependent is always false here: we implicitly convert an 'auto'
796 // which has been deduced to a dependent type into an undeduced 'auto', so
797 // that we'll retry deduction after the transformation.
Faisal Valifad9e132013-09-26 19:54:12 +0000798 return SemaRef.Context.getAutoType(Deduced, IsDecltypeAuto,
799 /*IsDependent*/ false);
Richard Smith34b41d92011-02-20 03:19:35 +0000800 }
801
Douglas Gregor577f75a2009-08-04 16:50:30 +0000802 /// \brief Build a new template specialization type.
803 ///
804 /// By default, performs semantic analysis when building the template
805 /// specialization type. Subclasses may override this routine to provide
806 /// different behavior.
807 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall833ca992009-10-29 08:12:44 +0000808 SourceLocation TemplateLoc,
Douglas Gregor67714232011-03-03 02:41:12 +0000809 TemplateArgumentListInfo &Args);
Mike Stump1eb44332009-09-09 15:08:12 +0000810
Abramo Bagnara075f8f12010-12-10 16:29:40 +0000811 /// \brief Build a new parenthesized type.
812 ///
813 /// By default, builds a new ParenType type from the inner type.
814 /// Subclasses may override this routine to provide different behavior.
815 QualType RebuildParenType(QualType InnerType) {
816 return SemaRef.Context.getParenType(InnerType);
817 }
818
Douglas Gregor577f75a2009-08-04 16:50:30 +0000819 /// \brief Build a new qualified name type.
820 ///
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000821 /// By default, builds a new ElaboratedType type from the keyword,
822 /// the nested-name-specifier and the named type.
823 /// Subclasses may override this routine to provide different behavior.
John McCall21e413f2010-11-04 19:04:38 +0000824 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
825 ElaboratedTypeKeyword Keyword,
Douglas Gregor9e876872011-03-01 18:12:44 +0000826 NestedNameSpecifierLoc QualifierLoc,
827 QualType Named) {
Chad Rosier4a9d7952012-08-08 18:46:20 +0000828 return SemaRef.Context.getElaboratedType(Keyword,
829 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor9e876872011-03-01 18:12:44 +0000830 Named);
Mike Stump1eb44332009-09-09 15:08:12 +0000831 }
Douglas Gregor577f75a2009-08-04 16:50:30 +0000832
833 /// \brief Build a new typename type that refers to a template-id.
834 ///
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000835 /// By default, builds a new DependentNameType type from the
836 /// nested-name-specifier and the given type. Subclasses may override
837 /// this routine to provide different behavior.
John McCall33500952010-06-11 00:33:02 +0000838 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000839 ElaboratedTypeKeyword Keyword,
840 NestedNameSpecifierLoc QualifierLoc,
841 const IdentifierInfo *Name,
842 SourceLocation NameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +0000843 TemplateArgumentListInfo &Args) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000844 // Rebuild the template name.
845 // TODO: avoid TemplateName abstraction
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000846 CXXScopeSpec SS;
847 SS.Adopt(QualifierLoc);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000848 TemplateName InstName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000849 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(), 0);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000850
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000851 if (InstName.isNull())
852 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +0000853
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000854 // If it's still dependent, make a dependent specialization.
855 if (InstName.getAsDependentTemplateName())
Chad Rosier4a9d7952012-08-08 18:46:20 +0000856 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
857 QualifierLoc.getNestedNameSpecifier(),
858 Name,
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000859 Args);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000860
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000861 // Otherwise, make an elaborated type wrapping a non-dependent
862 // specialization.
863 QualType T =
864 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
865 if (T.isNull()) return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +0000866
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000867 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == 0)
868 return T;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000869
870 return SemaRef.Context.getElaboratedType(Keyword,
871 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000872 T);
873 }
874
Douglas Gregor577f75a2009-08-04 16:50:30 +0000875 /// \brief Build a new typename type that refers to an identifier.
876 ///
877 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000878 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregor577f75a2009-08-04 16:50:30 +0000879 /// different behavior.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000880 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000881 SourceLocation KeywordLoc,
Douglas Gregor2494dd02011-03-01 01:34:45 +0000882 NestedNameSpecifierLoc QualifierLoc,
883 const IdentifierInfo *Id,
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000884 SourceLocation IdLoc) {
Douglas Gregor40336422010-03-31 22:19:08 +0000885 CXXScopeSpec SS;
Douglas Gregor2494dd02011-03-01 01:34:45 +0000886 SS.Adopt(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000887
Douglas Gregor2494dd02011-03-01 01:34:45 +0000888 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregor40336422010-03-31 22:19:08 +0000889 // If the name is still dependent, just build a new dependent name type.
890 if (!SemaRef.computeDeclContext(SS))
Chad Rosier4a9d7952012-08-08 18:46:20 +0000891 return SemaRef.Context.getDependentNameType(Keyword,
892 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor2494dd02011-03-01 01:34:45 +0000893 Id);
Douglas Gregor40336422010-03-31 22:19:08 +0000894 }
895
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000896 if (Keyword == ETK_None || Keyword == ETK_Typename)
Douglas Gregor2494dd02011-03-01 01:34:45 +0000897 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
Douglas Gregore29425b2011-02-28 22:42:13 +0000898 *Id, IdLoc);
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000899
900 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
901
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000902 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregor40336422010-03-31 22:19:08 +0000903 // into a non-dependent elaborated-type-specifier. Find the tag we're
904 // referring to.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000905 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregor40336422010-03-31 22:19:08 +0000906 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
907 if (!DC)
908 return QualType();
909
John McCall56138762010-05-27 06:40:31 +0000910 if (SemaRef.RequireCompleteDeclContext(SS, DC))
911 return QualType();
912
Douglas Gregor40336422010-03-31 22:19:08 +0000913 TagDecl *Tag = 0;
914 SemaRef.LookupQualifiedName(Result, DC);
915 switch (Result.getResultKind()) {
916 case LookupResult::NotFound:
917 case LookupResult::NotFoundInCurrentInstantiation:
918 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000919
Douglas Gregor40336422010-03-31 22:19:08 +0000920 case LookupResult::Found:
921 Tag = Result.getAsSingle<TagDecl>();
922 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000923
Douglas Gregor40336422010-03-31 22:19:08 +0000924 case LookupResult::FoundOverloaded:
925 case LookupResult::FoundUnresolvedValue:
926 llvm_unreachable("Tag lookup cannot find non-tags");
Chad Rosier4a9d7952012-08-08 18:46:20 +0000927
Douglas Gregor40336422010-03-31 22:19:08 +0000928 case LookupResult::Ambiguous:
929 // Let the LookupResult structure handle ambiguities.
930 return QualType();
931 }
932
933 if (!Tag) {
Nick Lewycky446e4022011-01-24 19:01:04 +0000934 // Check where the name exists but isn't a tag type and use that to emit
935 // better diagnostics.
936 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
937 SemaRef.LookupQualifiedName(Result, DC);
938 switch (Result.getResultKind()) {
939 case LookupResult::Found:
940 case LookupResult::FoundOverloaded:
941 case LookupResult::FoundUnresolvedValue: {
Richard Smith3e4c6c42011-05-05 21:57:07 +0000942 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
Nick Lewycky446e4022011-01-24 19:01:04 +0000943 unsigned Kind = 0;
944 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
Richard Smith162e1c12011-04-15 14:24:37 +0000945 else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2;
946 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3;
Nick Lewycky446e4022011-01-24 19:01:04 +0000947 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
948 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
949 break;
Richard Smith3e4c6c42011-05-05 21:57:07 +0000950 }
Nick Lewycky446e4022011-01-24 19:01:04 +0000951 default:
952 // FIXME: Would be nice to highlight just the source range.
953 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
954 << Kind << Id << DC;
955 break;
956 }
Douglas Gregor40336422010-03-31 22:19:08 +0000957 return QualType();
958 }
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000959
Richard Trieubbf34c02011-06-10 03:11:26 +0000960 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
961 IdLoc, *Id)) {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000962 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregor40336422010-03-31 22:19:08 +0000963 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
964 return QualType();
965 }
966
967 // Build the elaborated-type-specifier type.
968 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000969 return SemaRef.Context.getElaboratedType(Keyword,
970 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor2494dd02011-03-01 01:34:45 +0000971 T);
Douglas Gregordcee1a12009-08-06 05:28:30 +0000972 }
Mike Stump1eb44332009-09-09 15:08:12 +0000973
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000974 /// \brief Build a new pack expansion type.
975 ///
976 /// By default, builds a new PackExpansionType type from the given pattern.
977 /// Subclasses may override this routine to provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +0000978 QualType RebuildPackExpansionType(QualType Pattern,
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000979 SourceRange PatternRange,
Douglas Gregorcded4f62011-01-14 17:04:44 +0000980 SourceLocation EllipsisLoc,
David Blaikiedc84cd52013-02-20 22:23:23 +0000981 Optional<unsigned> NumExpansions) {
Douglas Gregorcded4f62011-01-14 17:04:44 +0000982 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
983 NumExpansions);
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000984 }
985
Eli Friedmanb001de72011-10-06 23:00:33 +0000986 /// \brief Build a new atomic type given its value type.
987 ///
988 /// By default, performs semantic analysis when building the atomic type.
989 /// Subclasses may override this routine to provide different behavior.
990 QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
991
Douglas Gregord1067e52009-08-06 06:41:21 +0000992 /// \brief Build a new template name given a nested name specifier, a flag
993 /// indicating whether the "template" keyword was provided, and the template
994 /// that the template name refers to.
995 ///
996 /// By default, builds the new template name directly. Subclasses may override
997 /// this routine to provide different behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000998 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +0000999 bool TemplateKW,
1000 TemplateDecl *Template);
1001
Douglas Gregord1067e52009-08-06 06:41:21 +00001002 /// \brief Build a new template name given a nested name specifier and the
1003 /// name that is referred to as a template.
1004 ///
1005 /// By default, performs semantic analysis to determine whether the name can
1006 /// be resolved to a specific template, then builds the appropriate kind of
1007 /// template name. Subclasses may override this routine to provide different
1008 /// behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00001009 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
1010 const IdentifierInfo &Name,
1011 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +00001012 QualType ObjectType,
1013 NamedDecl *FirstQualifierInScope);
Mike Stump1eb44332009-09-09 15:08:12 +00001014
Douglas Gregorca1bdd72009-11-04 00:56:37 +00001015 /// \brief Build a new template name given a nested name specifier and the
1016 /// overloaded operator name that is referred to as a template.
1017 ///
1018 /// By default, performs semantic analysis to determine whether the name can
1019 /// be resolved to a specific template, then builds the appropriate kind of
1020 /// template name. Subclasses may override this routine to provide different
1021 /// behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00001022 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00001023 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00001024 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00001025 QualType ObjectType);
Douglas Gregor1aee05d2011-01-15 06:45:20 +00001026
1027 /// \brief Build a new template name given a template template parameter pack
Chad Rosier4a9d7952012-08-08 18:46:20 +00001028 /// and the
Douglas Gregor1aee05d2011-01-15 06:45:20 +00001029 ///
1030 /// By default, performs semantic analysis to determine whether the name can
1031 /// be resolved to a specific template, then builds the appropriate kind of
1032 /// template name. Subclasses may override this routine to provide different
1033 /// behavior.
1034 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
1035 const TemplateArgument &ArgPack) {
1036 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
1037 }
1038
Douglas Gregor43959a92009-08-20 07:17:43 +00001039 /// \brief Build a new compound statement.
1040 ///
1041 /// By default, performs semantic analysis to build the new statement.
1042 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001043 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001044 MultiStmtArg Statements,
1045 SourceLocation RBraceLoc,
1046 bool IsStmtExpr) {
John McCall9ae2f072010-08-23 23:25:46 +00001047 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregor43959a92009-08-20 07:17:43 +00001048 IsStmtExpr);
1049 }
1050
1051 /// \brief Build a new case statement.
1052 ///
1053 /// By default, performs semantic analysis to build the new statement.
1054 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001055 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001056 Expr *LHS,
Douglas Gregor43959a92009-08-20 07:17:43 +00001057 SourceLocation EllipsisLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001058 Expr *RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +00001059 SourceLocation ColonLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001060 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +00001061 ColonLoc);
1062 }
Mike Stump1eb44332009-09-09 15:08:12 +00001063
Douglas Gregor43959a92009-08-20 07:17:43 +00001064 /// \brief Attach the body to a new case 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 RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001069 getSema().ActOnCaseStmtBody(S, Body);
1070 return S;
Douglas Gregor43959a92009-08-20 07:17:43 +00001071 }
Mike Stump1eb44332009-09-09 15:08:12 +00001072
Douglas Gregor43959a92009-08-20 07:17:43 +00001073 /// \brief Build a new default statement.
1074 ///
1075 /// By default, performs semantic analysis to build the new statement.
1076 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001077 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001078 SourceLocation ColonLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001079 Stmt *SubStmt) {
1080 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregor43959a92009-08-20 07:17:43 +00001081 /*CurScope=*/0);
1082 }
Mike Stump1eb44332009-09-09 15:08:12 +00001083
Douglas Gregor43959a92009-08-20 07:17:43 +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.
Chris Lattner57ad3782011-02-17 20:34:02 +00001088 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1089 SourceLocation ColonLoc, Stmt *SubStmt) {
1090 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregor43959a92009-08-20 07:17:43 +00001091 }
Mike Stump1eb44332009-09-09 15:08:12 +00001092
Richard Smith534986f2012-04-14 00:33:13 +00001093 /// \brief Build a new label statement.
1094 ///
1095 /// By default, performs semantic analysis to build the new statement.
1096 /// Subclasses may override this routine to provide different behavior.
Alexander Kornienko49908902012-07-09 10:04:07 +00001097 StmtResult RebuildAttributedStmt(SourceLocation AttrLoc,
1098 ArrayRef<const Attr*> Attrs,
Richard Smith534986f2012-04-14 00:33:13 +00001099 Stmt *SubStmt) {
1100 return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt);
1101 }
1102
Douglas Gregor43959a92009-08-20 07:17:43 +00001103 /// \brief Build a new "if" statement.
1104 ///
1105 /// By default, performs semantic analysis to build the new statement.
1106 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001107 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Chad Rosier4a9d7952012-08-08 18:46:20 +00001108 VarDecl *CondVar, Stmt *Then,
Chris Lattner57ad3782011-02-17 20:34:02 +00001109 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00001110 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregor43959a92009-08-20 07:17:43 +00001111 }
Mike Stump1eb44332009-09-09 15:08:12 +00001112
Douglas Gregor43959a92009-08-20 07:17:43 +00001113 /// \brief Start building a new switch statement.
1114 ///
1115 /// By default, performs semantic analysis to build the new statement.
1116 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001117 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Chris Lattner57ad3782011-02-17 20:34:02 +00001118 Expr *Cond, VarDecl *CondVar) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001119 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCalld226f652010-08-21 09:40:31 +00001120 CondVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00001121 }
Mike Stump1eb44332009-09-09 15:08:12 +00001122
Douglas Gregor43959a92009-08-20 07:17:43 +00001123 /// \brief Attach the body to the switch statement.
1124 ///
1125 /// By default, performs semantic analysis to build the new statement.
1126 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001127 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattner57ad3782011-02-17 20:34:02 +00001128 Stmt *Switch, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001129 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001130 }
1131
1132 /// \brief Build a new while statement.
1133 ///
1134 /// By default, performs semantic analysis to build the new statement.
1135 /// Subclasses may override this routine to provide different behavior.
Chris Lattner57ad3782011-02-17 20:34:02 +00001136 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1137 VarDecl *CondVar, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001138 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001139 }
Mike Stump1eb44332009-09-09 15:08:12 +00001140
Douglas Gregor43959a92009-08-20 07:17:43 +00001141 /// \brief Build a new do-while statement.
1142 ///
1143 /// By default, performs semantic analysis to build the new statement.
1144 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001145 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001146 SourceLocation WhileLoc, SourceLocation LParenLoc,
1147 Expr *Cond, SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001148 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1149 Cond, RParenLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001150 }
1151
1152 /// \brief Build a new for statement.
1153 ///
1154 /// By default, performs semantic analysis to build the new statement.
1155 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001156 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
Chad Rosier4a9d7952012-08-08 18:46:20 +00001157 Stmt *Init, Sema::FullExprArg Cond,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001158 VarDecl *CondVar, Sema::FullExprArg Inc,
1159 SourceLocation RParenLoc, Stmt *Body) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001160 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001161 CondVar, Inc, RParenLoc, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001162 }
Mike Stump1eb44332009-09-09 15:08:12 +00001163
Douglas Gregor43959a92009-08-20 07:17:43 +00001164 /// \brief Build a new goto statement.
1165 ///
1166 /// By default, performs semantic analysis to build the new statement.
1167 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001168 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1169 LabelDecl *Label) {
Chris Lattner57ad3782011-02-17 20:34:02 +00001170 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregor43959a92009-08-20 07:17:43 +00001171 }
1172
1173 /// \brief Build a new indirect goto statement.
1174 ///
1175 /// By default, performs semantic analysis to build the new statement.
1176 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001177 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001178 SourceLocation StarLoc,
1179 Expr *Target) {
John McCall9ae2f072010-08-23 23:25:46 +00001180 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregor43959a92009-08-20 07:17:43 +00001181 }
Mike Stump1eb44332009-09-09 15:08:12 +00001182
Douglas Gregor43959a92009-08-20 07:17:43 +00001183 /// \brief Build a new return statement.
1184 ///
1185 /// By default, performs semantic analysis to build the new statement.
1186 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001187 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
John McCall9ae2f072010-08-23 23:25:46 +00001188 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregor43959a92009-08-20 07:17:43 +00001189 }
Mike Stump1eb44332009-09-09 15:08:12 +00001190
Douglas Gregor43959a92009-08-20 07:17:43 +00001191 /// \brief Build a new declaration statement.
1192 ///
1193 /// By default, performs semantic analysis to build the new statement.
1194 /// Subclasses may override this routine to provide different behavior.
Rafael Espindola4549d7f2013-07-09 12:05:01 +00001195 StmtResult RebuildDeclStmt(llvm::MutableArrayRef<Decl *> Decls,
1196 SourceLocation StartLoc, SourceLocation EndLoc) {
1197 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls);
Richard Smith406c38e2011-02-23 00:37:57 +00001198 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001199 }
Mike Stump1eb44332009-09-09 15:08:12 +00001200
Anders Carlsson703e3942010-01-24 05:50:09 +00001201 /// \brief Build a new inline asm statement.
1202 ///
1203 /// By default, performs semantic analysis to build the new statement.
1204 /// Subclasses may override this routine to provide different behavior.
Chad Rosierdf5faf52012-08-25 00:11:56 +00001205 StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
1206 bool IsVolatile, unsigned NumOutputs,
1207 unsigned NumInputs, IdentifierInfo **Names,
1208 MultiExprArg Constraints, MultiExprArg Exprs,
1209 Expr *AsmString, MultiExprArg Clobbers,
1210 SourceLocation RParenLoc) {
1211 return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1212 NumInputs, Names, Constraints, Exprs,
1213 AsmString, Clobbers, RParenLoc);
Anders Carlsson703e3942010-01-24 05:50:09 +00001214 }
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001215
Chad Rosier8cd64b42012-06-11 20:47:18 +00001216 /// \brief Build a new MS style inline asm statement.
1217 ///
1218 /// By default, performs semantic analysis to build the new statement.
1219 /// Subclasses may override this routine to provide different behavior.
Chad Rosierdf5faf52012-08-25 00:11:56 +00001220 StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc,
John McCallaeeacf72013-05-03 00:10:13 +00001221 ArrayRef<Token> AsmToks,
1222 StringRef AsmString,
1223 unsigned NumOutputs, unsigned NumInputs,
1224 ArrayRef<StringRef> Constraints,
1225 ArrayRef<StringRef> Clobbers,
1226 ArrayRef<Expr*> Exprs,
1227 SourceLocation EndLoc) {
1228 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString,
1229 NumOutputs, NumInputs,
1230 Constraints, Clobbers, Exprs, EndLoc);
Chad Rosier8cd64b42012-06-11 20:47:18 +00001231 }
1232
James Dennett699c9042012-06-15 07:13:21 +00001233 /// \brief Build a new Objective-C \@try statement.
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001234 ///
1235 /// By default, performs semantic analysis to build the new statement.
1236 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001237 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001238 Stmt *TryBody,
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00001239 MultiStmtArg CatchStmts,
John McCall9ae2f072010-08-23 23:25:46 +00001240 Stmt *Finally) {
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001241 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
John McCall9ae2f072010-08-23 23:25:46 +00001242 Finally);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001243 }
1244
Douglas Gregorbe270a02010-04-26 17:57:08 +00001245 /// \brief Rebuild an Objective-C exception declaration.
1246 ///
1247 /// By default, performs semantic analysis to build the new declaration.
1248 /// Subclasses may override this routine to provide different behavior.
1249 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1250 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001251 return getSema().BuildObjCExceptionDecl(TInfo, T,
1252 ExceptionDecl->getInnerLocStart(),
1253 ExceptionDecl->getLocation(),
1254 ExceptionDecl->getIdentifier());
Douglas Gregorbe270a02010-04-26 17:57:08 +00001255 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001256
James Dennett699c9042012-06-15 07:13:21 +00001257 /// \brief Build a new Objective-C \@catch statement.
Douglas Gregorbe270a02010-04-26 17:57:08 +00001258 ///
1259 /// By default, performs semantic analysis to build the new statement.
1260 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001261 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorbe270a02010-04-26 17:57:08 +00001262 SourceLocation RParenLoc,
1263 VarDecl *Var,
John McCall9ae2f072010-08-23 23:25:46 +00001264 Stmt *Body) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00001265 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001266 Var, Body);
Douglas Gregorbe270a02010-04-26 17:57:08 +00001267 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001268
James Dennett699c9042012-06-15 07:13:21 +00001269 /// \brief Build a new Objective-C \@finally statement.
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +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 RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001274 Stmt *Body) {
1275 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001276 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001277
James Dennett699c9042012-06-15 07:13:21 +00001278 /// \brief Build a new Objective-C \@throw statement.
Douglas Gregord1377b22010-04-22 21:44:01 +00001279 ///
1280 /// By default, performs semantic analysis to build the new statement.
1281 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001282 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001283 Expr *Operand) {
1284 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregord1377b22010-04-22 21:44:01 +00001285 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001286
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00001287 /// \brief Build a new OpenMP parallel directive.
1288 ///
1289 /// By default, performs semantic analysis to build the new statement.
1290 /// Subclasses may override this routine to provide different behavior.
1291 StmtResult RebuildOMPParallelDirective(ArrayRef<OMPClause *> Clauses,
1292 Stmt *AStmt,
1293 SourceLocation StartLoc,
1294 SourceLocation EndLoc) {
1295 return getSema().ActOnOpenMPParallelDirective(Clauses, AStmt,
1296 StartLoc, EndLoc);
1297 }
1298
1299 /// \brief Build a new OpenMP 'default' clause.
1300 ///
1301 /// By default, performs semantic analysis to build the new statement.
1302 /// Subclasses may override this routine to provide different behavior.
1303 OMPClause *RebuildOMPDefaultClause(OpenMPDefaultClauseKind Kind,
1304 SourceLocation KindKwLoc,
1305 SourceLocation StartLoc,
1306 SourceLocation LParenLoc,
1307 SourceLocation EndLoc) {
1308 return getSema().ActOnOpenMPDefaultClause(Kind, KindKwLoc,
1309 StartLoc, LParenLoc, EndLoc);
1310 }
1311
1312 /// \brief Build a new OpenMP 'private' clause.
1313 ///
1314 /// By default, performs semantic analysis to build the new statement.
1315 /// Subclasses may override this routine to provide different behavior.
1316 OMPClause *RebuildOMPPrivateClause(ArrayRef<Expr *> VarList,
1317 SourceLocation StartLoc,
1318 SourceLocation LParenLoc,
1319 SourceLocation EndLoc) {
1320 return getSema().ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc,
1321 EndLoc);
1322 }
1323
Alexey Bataevd195bc32013-10-01 05:32:34 +00001324 /// \brief Build a new OpenMP 'firstprivate' clause.
1325 ///
1326 /// By default, performs semantic analysis to build the new statement.
1327 /// Subclasses may override this routine to provide different behavior.
1328 OMPClause *RebuildOMPFirstprivateClause(ArrayRef<Expr *> VarList,
1329 SourceLocation StartLoc,
1330 SourceLocation LParenLoc,
1331 SourceLocation EndLoc) {
1332 return getSema().ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc,
1333 EndLoc);
1334 }
1335
Alexey Bataev0c018352013-09-06 18:03:48 +00001336 OMPClause *RebuildOMPSharedClause(ArrayRef<Expr *> VarList,
1337 SourceLocation StartLoc,
1338 SourceLocation LParenLoc,
1339 SourceLocation EndLoc) {
1340 return getSema().ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc,
1341 EndLoc);
1342 }
1343
James Dennett699c9042012-06-15 07:13:21 +00001344 /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
John McCall07524032011-07-27 21:50:02 +00001345 ///
1346 /// By default, performs semantic analysis to build the new statement.
1347 /// Subclasses may override this routine to provide different behavior.
1348 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1349 Expr *object) {
1350 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1351 }
1352
James Dennett699c9042012-06-15 07:13:21 +00001353 /// \brief Build a new Objective-C \@synchronized statement.
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001354 ///
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001355 /// By default, performs semantic analysis to build the new statement.
1356 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001357 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCall07524032011-07-27 21:50:02 +00001358 Expr *Object, Stmt *Body) {
1359 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001360 }
Douglas Gregorc3203e72010-04-22 23:10:45 +00001361
James Dennett699c9042012-06-15 07:13:21 +00001362 /// \brief Build a new Objective-C \@autoreleasepool statement.
John McCallf85e1932011-06-15 23:02:42 +00001363 ///
1364 /// By default, performs semantic analysis to build the new statement.
1365 /// Subclasses may override this routine to provide different behavior.
1366 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1367 Stmt *Body) {
1368 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1369 }
John McCall990567c2011-07-27 01:07:15 +00001370
Douglas Gregorc3203e72010-04-22 23:10:45 +00001371 /// \brief Build a new Objective-C fast enumeration statement.
1372 ///
1373 /// By default, performs semantic analysis to build the new statement.
1374 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001375 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001376 Stmt *Element,
1377 Expr *Collection,
1378 SourceLocation RParenLoc,
1379 Stmt *Body) {
Sam Panzerbc20bbb2012-08-16 21:47:25 +00001380 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
Fariborz Jahaniana1eec4b2012-07-03 22:00:52 +00001381 Element,
John McCall9ae2f072010-08-23 23:25:46 +00001382 Collection,
Fariborz Jahaniana1eec4b2012-07-03 22:00:52 +00001383 RParenLoc);
1384 if (ForEachStmt.isInvalid())
1385 return StmtError();
1386
1387 return getSema().FinishObjCForCollectionStmt(ForEachStmt.take(), Body);
Douglas Gregorc3203e72010-04-22 23:10:45 +00001388 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001389
Douglas Gregor43959a92009-08-20 07:17:43 +00001390 /// \brief Build a new C++ exception declaration.
1391 ///
1392 /// By default, performs semantic analysis to build the new decaration.
1393 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001394 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCalla93c9342009-12-07 02:54:59 +00001395 TypeSourceInfo *Declarator,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001396 SourceLocation StartLoc,
1397 SourceLocation IdLoc,
1398 IdentifierInfo *Id) {
Douglas Gregorefdf9882011-04-14 22:32:28 +00001399 VarDecl *Var = getSema().BuildExceptionDeclaration(0, Declarator,
1400 StartLoc, IdLoc, Id);
1401 if (Var)
1402 getSema().CurContext->addDecl(Var);
1403 return Var;
Douglas Gregor43959a92009-08-20 07:17:43 +00001404 }
1405
1406 /// \brief Build a new C++ catch statement.
1407 ///
1408 /// By default, performs semantic analysis to build the new statement.
1409 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001410 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001411 VarDecl *ExceptionDecl,
1412 Stmt *Handler) {
John McCall9ae2f072010-08-23 23:25:46 +00001413 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1414 Handler));
Douglas Gregor43959a92009-08-20 07:17:43 +00001415 }
Mike Stump1eb44332009-09-09 15:08:12 +00001416
Douglas Gregor43959a92009-08-20 07:17:43 +00001417 /// \brief Build a new C++ try statement.
1418 ///
1419 /// By default, performs semantic analysis to build the new statement.
1420 /// Subclasses may override this routine to provide different behavior.
Robert Wilhelm21adb0c2013-08-22 09:20:03 +00001421 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock,
1422 ArrayRef<Stmt *> Handlers) {
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001423 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
Douglas Gregor43959a92009-08-20 07:17:43 +00001424 }
Mike Stump1eb44332009-09-09 15:08:12 +00001425
Richard Smithad762fc2011-04-14 22:09:26 +00001426 /// \brief Build a new C++0x range-based for statement.
1427 ///
1428 /// By default, performs semantic analysis to build the new statement.
1429 /// Subclasses may override this routine to provide different behavior.
1430 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1431 SourceLocation ColonLoc,
1432 Stmt *Range, Stmt *BeginEnd,
1433 Expr *Cond, Expr *Inc,
1434 Stmt *LoopVar,
1435 SourceLocation RParenLoc) {
Douglas Gregor6f96f4b2013-04-08 18:40:13 +00001436 // If we've just learned that the range is actually an Objective-C
1437 // collection, treat this as an Objective-C fast enumeration loop.
1438 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
1439 if (RangeStmt->isSingleDecl()) {
1440 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
Douglas Gregor39b60dc2013-05-02 18:35:56 +00001441 if (RangeVar->isInvalidDecl())
1442 return StmtError();
1443
Douglas Gregor6f96f4b2013-04-08 18:40:13 +00001444 Expr *RangeExpr = RangeVar->getInit();
1445 if (!RangeExpr->isTypeDependent() &&
1446 RangeExpr->getType()->isObjCObjectPointerType())
1447 return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, RangeExpr,
1448 RParenLoc);
1449 }
1450 }
1451 }
1452
Richard Smithad762fc2011-04-14 22:09:26 +00001453 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
Richard Smith8b533d92012-09-20 21:52:32 +00001454 Cond, Inc, LoopVar, RParenLoc,
1455 Sema::BFRK_Rebuild);
Richard Smithad762fc2011-04-14 22:09:26 +00001456 }
Douglas Gregorba0513d2011-10-25 01:33:02 +00001457
1458 /// \brief Build a new C++0x range-based for statement.
1459 ///
1460 /// By default, performs semantic analysis to build the new statement.
1461 /// Subclasses may override this routine to provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +00001462 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
Douglas Gregorba0513d2011-10-25 01:33:02 +00001463 bool IsIfExists,
1464 NestedNameSpecifierLoc QualifierLoc,
1465 DeclarationNameInfo NameInfo,
1466 Stmt *Nested) {
1467 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1468 QualifierLoc, NameInfo, Nested);
1469 }
1470
Richard Smithad762fc2011-04-14 22:09:26 +00001471 /// \brief Attach body to a C++0x range-based for statement.
1472 ///
1473 /// By default, performs semantic analysis to finish the new statement.
1474 /// Subclasses may override this routine to provide different behavior.
1475 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1476 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1477 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001478
David Majnemerfc210492013-10-15 09:33:02 +00001479 StmtResult RebuildSEHTryStmt(bool IsCXXTry, SourceLocation TryLoc,
1480 Stmt *TryBlock, Stmt *Handler) {
1481 return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler);
John Wiegley28bbe4b2011-04-28 01:08:34 +00001482 }
1483
David Majnemerfc210492013-10-15 09:33:02 +00001484 StmtResult RebuildSEHExceptStmt(SourceLocation Loc, Expr *FilterExpr,
John Wiegley28bbe4b2011-04-28 01:08:34 +00001485 Stmt *Block) {
David Majnemerfc210492013-10-15 09:33:02 +00001486 return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block);
John Wiegley28bbe4b2011-04-28 01:08:34 +00001487 }
1488
David Majnemerfc210492013-10-15 09:33:02 +00001489 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, Stmt *Block) {
1490 return getSema().ActOnSEHFinallyBlock(Loc, Block);
John Wiegley28bbe4b2011-04-28 01:08:34 +00001491 }
1492
Douglas Gregorb98b1992009-08-11 05:31:07 +00001493 /// \brief Build a new expression that references a declaration.
1494 ///
1495 /// By default, performs semantic analysis to build the new expression.
1496 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001497 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallf312b1e2010-08-26 23:41:50 +00001498 LookupResult &R,
1499 bool RequiresADL) {
John McCallf7a1a742009-11-24 19:00:30 +00001500 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1501 }
1502
1503
1504 /// \brief Build a new expression that references a declaration.
1505 ///
1506 /// By default, performs semantic analysis to build the new expression.
1507 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001508 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001509 ValueDecl *VD,
1510 const DeclarationNameInfo &NameInfo,
1511 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00001512 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001513 SS.Adopt(QualifierLoc);
John McCalldbd872f2009-12-08 09:08:17 +00001514
1515 // FIXME: loses template args.
Abramo Bagnara25777432010-08-11 22:01:17 +00001516
1517 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001518 }
Mike Stump1eb44332009-09-09 15:08:12 +00001519
Douglas Gregorb98b1992009-08-11 05:31:07 +00001520 /// \brief Build a new expression in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001521 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +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 RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001525 SourceLocation RParen) {
John McCall9ae2f072010-08-23 23:25:46 +00001526 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001527 }
1528
Douglas Gregora71d8192009-09-04 17:36:40 +00001529 /// \brief Build a new pseudo-destructor expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001530 ///
Douglas Gregora71d8192009-09-04 17:36:40 +00001531 /// By default, performs semantic analysis to build the new expression.
1532 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001533 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00001534 SourceLocation OperatorLoc,
1535 bool isArrow,
1536 CXXScopeSpec &SS,
1537 TypeSourceInfo *ScopeType,
1538 SourceLocation CCLoc,
1539 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00001540 PseudoDestructorTypeStorage Destroyed);
Mike Stump1eb44332009-09-09 15:08:12 +00001541
Douglas Gregorb98b1992009-08-11 05:31:07 +00001542 /// \brief Build a new unary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001543 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001544 /// By default, performs semantic analysis to build the new expression.
1545 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001546 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001547 UnaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001548 Expr *SubExpr) {
1549 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001550 }
Mike Stump1eb44332009-09-09 15:08:12 +00001551
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001552 /// \brief Build a new builtin offsetof expression.
1553 ///
1554 /// By default, performs semantic analysis to build the new expression.
1555 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001556 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001557 TypeSourceInfo *Type,
John McCallf312b1e2010-08-26 23:41:50 +00001558 Sema::OffsetOfComponent *Components,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001559 unsigned NumComponents,
1560 SourceLocation RParenLoc) {
1561 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1562 NumComponents, RParenLoc);
1563 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001564
1565 /// \brief Build a new sizeof, alignof or vec_step expression with a
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001566 /// type argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001567 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001568 /// By default, performs semantic analysis to build the new expression.
1569 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001570 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1571 SourceLocation OpLoc,
1572 UnaryExprOrTypeTrait ExprKind,
1573 SourceRange R) {
1574 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001575 }
1576
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001577 /// \brief Build a new sizeof, alignof or vec step expression with an
1578 /// expression argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001579 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001580 /// By default, performs semantic analysis to build the new expression.
1581 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001582 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1583 UnaryExprOrTypeTrait ExprKind,
1584 SourceRange R) {
John McCall60d7b3a2010-08-24 06:29:42 +00001585 ExprResult Result
Chandler Carruthe72c55b2011-05-29 07:32:14 +00001586 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001587 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001588 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001589
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001590 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00001591 }
Mike Stump1eb44332009-09-09 15:08:12 +00001592
Douglas Gregorb98b1992009-08-11 05:31:07 +00001593 /// \brief Build a new array subscript expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001594 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001595 /// By default, performs semantic analysis to build the new expression.
1596 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001597 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001598 SourceLocation LBracketLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001599 Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001600 SourceLocation RBracketLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001601 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1602 LBracketLoc, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001603 RBracketLoc);
1604 }
1605
1606 /// \brief Build a new call expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001607 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001608 /// By default, performs semantic analysis to build the new expression.
1609 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001610 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001611 MultiExprArg Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00001612 SourceLocation RParenLoc,
1613 Expr *ExecConfig = 0) {
John McCall9ae2f072010-08-23 23:25:46 +00001614 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001615 Args, RParenLoc, ExecConfig);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001616 }
1617
1618 /// \brief Build a new member access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001619 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001620 /// By default, performs semantic analysis to build the new expression.
1621 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001622 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001623 bool isArrow,
Douglas Gregor40d96a62011-02-28 21:54:11 +00001624 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001625 SourceLocation TemplateKWLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001626 const DeclarationNameInfo &MemberNameInfo,
1627 ValueDecl *Member,
1628 NamedDecl *FoundDecl,
John McCalld5532b62009-11-23 01:53:49 +00001629 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCallf89e55a2010-11-18 06:31:45 +00001630 NamedDecl *FirstQualifierInScope) {
Richard Smith9138b4e2011-10-26 19:06:56 +00001631 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
1632 isArrow);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001633 if (!Member->getDeclName()) {
John McCallf89e55a2010-11-18 06:31:45 +00001634 // We have a reference to an unnamed field. This is always the
1635 // base of an anonymous struct/union member access, i.e. the
1636 // field is always of record type.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001637 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCallf89e55a2010-11-18 06:31:45 +00001638 assert(Member->getType()->isRecordType() &&
1639 "unnamed member not of record type?");
Mike Stump1eb44332009-09-09 15:08:12 +00001640
Richard Smith9138b4e2011-10-26 19:06:56 +00001641 BaseResult =
1642 getSema().PerformObjectMemberConversion(BaseResult.take(),
John Wiegley429bb272011-04-08 18:41:53 +00001643 QualifierLoc.getNestedNameSpecifier(),
1644 FoundDecl, Member);
1645 if (BaseResult.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001646 return ExprError();
John Wiegley429bb272011-04-08 18:41:53 +00001647 Base = BaseResult.take();
John McCallf89e55a2010-11-18 06:31:45 +00001648 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump1eb44332009-09-09 15:08:12 +00001649 MemberExpr *ME =
John McCall9ae2f072010-08-23 23:25:46 +00001650 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnara25777432010-08-11 22:01:17 +00001651 Member, MemberNameInfo,
John McCallf89e55a2010-11-18 06:31:45 +00001652 cast<FieldDecl>(Member)->getType(),
1653 VK, OK_Ordinary);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001654 return getSema().Owned(ME);
1655 }
Mike Stump1eb44332009-09-09 15:08:12 +00001656
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001657 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001658 SS.Adopt(QualifierLoc);
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001659
John Wiegley429bb272011-04-08 18:41:53 +00001660 Base = BaseResult.take();
John McCall9ae2f072010-08-23 23:25:46 +00001661 QualType BaseType = Base->getType();
John McCallaa81e162009-12-01 22:10:20 +00001662
John McCall6bb80172010-03-30 21:47:33 +00001663 // FIXME: this involves duplicating earlier analysis in a lot of
1664 // cases; we should avoid this when possible.
Abramo Bagnara25777432010-08-11 22:01:17 +00001665 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall6bb80172010-03-30 21:47:33 +00001666 R.addDecl(FoundDecl);
John McCallc2233c52010-01-15 08:34:02 +00001667 R.resolveKind();
1668
John McCall9ae2f072010-08-23 23:25:46 +00001669 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001670 SS, TemplateKWLoc,
1671 FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00001672 R, ExplicitTemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001673 }
Mike Stump1eb44332009-09-09 15:08:12 +00001674
Douglas Gregorb98b1992009-08-11 05:31:07 +00001675 /// \brief Build a new binary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001676 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001677 /// By default, performs semantic analysis to build the new expression.
1678 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001679 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001680 BinaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001681 Expr *LHS, Expr *RHS) {
1682 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001683 }
1684
1685 /// \brief Build a new conditional operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001686 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001687 /// By default, performs semantic analysis to build the new expression.
1688 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001689 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCall56ca35d2011-02-17 10:25:35 +00001690 SourceLocation QuestionLoc,
1691 Expr *LHS,
1692 SourceLocation ColonLoc,
1693 Expr *RHS) {
John McCall9ae2f072010-08-23 23:25:46 +00001694 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1695 LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001696 }
1697
Douglas Gregorb98b1992009-08-11 05:31:07 +00001698 /// \brief Build a new C-style cast expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001699 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001700 /// By default, performs semantic analysis to build the new expression.
1701 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001702 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall9d125032010-01-15 18:39:57 +00001703 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001704 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001705 Expr *SubExpr) {
John McCallb042fdf2010-01-15 18:56:44 +00001706 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001707 SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001708 }
Mike Stump1eb44332009-09-09 15:08:12 +00001709
Douglas Gregorb98b1992009-08-11 05:31:07 +00001710 /// \brief Build a new compound literal expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001711 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001712 /// By default, performs semantic analysis to build the new expression.
1713 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001714 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCall42f56b52010-01-18 19:35:47 +00001715 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001716 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001717 Expr *Init) {
John McCall42f56b52010-01-18 19:35:47 +00001718 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001719 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001720 }
Mike Stump1eb44332009-09-09 15:08:12 +00001721
Douglas Gregorb98b1992009-08-11 05:31:07 +00001722 /// \brief Build a new extended vector element access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001723 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001724 /// By default, performs semantic analysis to build the new expression.
1725 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001726 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001727 SourceLocation OpLoc,
1728 SourceLocation AccessorLoc,
1729 IdentifierInfo &Accessor) {
John McCallaa81e162009-12-01 22:10:20 +00001730
John McCall129e2df2009-11-30 22:42:35 +00001731 CXXScopeSpec SS;
Abramo Bagnara25777432010-08-11 22:01:17 +00001732 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCall9ae2f072010-08-23 23:25:46 +00001733 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall129e2df2009-11-30 22:42:35 +00001734 OpLoc, /*IsArrow*/ false,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001735 SS, SourceLocation(),
1736 /*FirstQualifierInScope*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00001737 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00001738 /* TemplateArgs */ 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001739 }
Mike Stump1eb44332009-09-09 15:08:12 +00001740
Douglas Gregorb98b1992009-08-11 05:31:07 +00001741 /// \brief Build a new initializer list expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001742 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001743 /// By default, performs semantic analysis to build the new expression.
1744 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001745 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCallc8fc90a2011-07-06 07:30:07 +00001746 MultiExprArg Inits,
1747 SourceLocation RBraceLoc,
1748 QualType ResultTy) {
John McCall60d7b3a2010-08-24 06:29:42 +00001749 ExprResult Result
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001750 = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
Douglas Gregore48319a2009-11-09 17:16:50 +00001751 if (Result.isInvalid() || ResultTy->isDependentType())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001752 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00001753
Douglas Gregore48319a2009-11-09 17:16:50 +00001754 // Patch in the result type we were given, which may have been computed
1755 // when the initial InitListExpr was built.
1756 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1757 ILE->setType(ResultTy);
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001758 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00001759 }
Mike Stump1eb44332009-09-09 15:08:12 +00001760
Douglas Gregorb98b1992009-08-11 05:31:07 +00001761 /// \brief Build a new designated initializer expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001762 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001763 /// By default, performs semantic analysis to build the new expression.
1764 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001765 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001766 MultiExprArg ArrayExprs,
1767 SourceLocation EqualOrColonLoc,
1768 bool GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001769 Expr *Init) {
John McCall60d7b3a2010-08-24 06:29:42 +00001770 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00001771 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001772 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001773 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001774 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001775
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001776 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00001777 }
Mike Stump1eb44332009-09-09 15:08:12 +00001778
Douglas Gregorb98b1992009-08-11 05:31:07 +00001779 /// \brief Build a new value-initialized expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001780 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001781 /// By default, builds the implicit value initialization without performing
1782 /// any semantic analysis. Subclasses may override this routine to provide
1783 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001784 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001785 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1786 }
Mike Stump1eb44332009-09-09 15:08:12 +00001787
Douglas Gregorb98b1992009-08-11 05:31:07 +00001788 /// \brief Build a new \c va_arg expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001789 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001790 /// By default, performs semantic analysis to build the new expression.
1791 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001792 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001793 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001794 SourceLocation RParenLoc) {
1795 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001796 SubExpr, TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001797 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001798 }
1799
1800 /// \brief Build a new expression list in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001801 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001802 /// By default, performs semantic analysis to build the new expression.
1803 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001804 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redl5b9cc5d2012-02-11 23:51:47 +00001805 MultiExprArg SubExprs,
1806 SourceLocation RParenLoc) {
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001807 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001808 }
Mike Stump1eb44332009-09-09 15:08:12 +00001809
Douglas Gregorb98b1992009-08-11 05:31:07 +00001810 /// \brief Build a new address-of-label expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001811 ///
1812 /// By default, performs semantic analysis, using the name of the label
Douglas Gregorb98b1992009-08-11 05:31:07 +00001813 /// rather than attempting to map the label statement itself.
1814 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001815 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001816 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattner57ad3782011-02-17 20:34:02 +00001817 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001818 }
Mike Stump1eb44332009-09-09 15:08:12 +00001819
Douglas Gregorb98b1992009-08-11 05:31:07 +00001820 /// \brief Build a new GNU statement expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001821 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001822 /// By default, performs semantic analysis to build the new expression.
1823 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001824 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001825 Stmt *SubStmt,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001826 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001827 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001828 }
Mike Stump1eb44332009-09-09 15:08:12 +00001829
Douglas Gregorb98b1992009-08-11 05:31:07 +00001830 /// \brief Build a new __builtin_choose_expr expression.
1831 ///
1832 /// By default, performs semantic analysis to build the new expression.
1833 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001834 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001835 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001836 SourceLocation RParenLoc) {
1837 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001838 Cond, LHS, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001839 RParenLoc);
1840 }
Mike Stump1eb44332009-09-09 15:08:12 +00001841
Peter Collingbournef111d932011-04-15 00:35:48 +00001842 /// \brief Build a new generic selection expression.
1843 ///
1844 /// By default, performs semantic analysis to build the new expression.
1845 /// Subclasses may override this routine to provide different behavior.
1846 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
1847 SourceLocation DefaultLoc,
1848 SourceLocation RParenLoc,
1849 Expr *ControllingExpr,
Dmitri Gribenko80613222013-05-10 13:06:58 +00001850 ArrayRef<TypeSourceInfo *> Types,
1851 ArrayRef<Expr *> Exprs) {
Peter Collingbournef111d932011-04-15 00:35:48 +00001852 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
Dmitri Gribenko80613222013-05-10 13:06:58 +00001853 ControllingExpr, Types, Exprs);
Peter Collingbournef111d932011-04-15 00:35:48 +00001854 }
1855
Douglas Gregorb98b1992009-08-11 05:31:07 +00001856 /// \brief Build a new overloaded operator call expression.
1857 ///
1858 /// By default, performs semantic analysis to build the new expression.
1859 /// The semantic analysis provides the behavior of template instantiation,
1860 /// copying with transformations that turn what looks like an overloaded
Mike Stump1eb44332009-09-09 15:08:12 +00001861 /// operator call into a use of a builtin operator, performing
Douglas Gregorb98b1992009-08-11 05:31:07 +00001862 /// argument-dependent lookup, etc. Subclasses may override this routine to
1863 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001864 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001865 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001866 Expr *Callee,
1867 Expr *First,
1868 Expr *Second);
Mike Stump1eb44332009-09-09 15:08:12 +00001869
1870 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregorb98b1992009-08-11 05:31:07 +00001871 /// reinterpret_cast.
1872 ///
1873 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump1eb44332009-09-09 15:08:12 +00001874 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregorb98b1992009-08-11 05:31:07 +00001875 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001876 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001877 Stmt::StmtClass Class,
1878 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001879 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001880 SourceLocation RAngleLoc,
1881 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001882 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001883 SourceLocation RParenLoc) {
1884 switch (Class) {
1885 case Stmt::CXXStaticCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001886 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001887 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001888 SubExpr, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001889
1890 case Stmt::CXXDynamicCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001891 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001892 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001893 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001894
Douglas Gregorb98b1992009-08-11 05:31:07 +00001895 case Stmt::CXXReinterpretCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001896 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001897 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001898 SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001899 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001900
Douglas Gregorb98b1992009-08-11 05:31:07 +00001901 case Stmt::CXXConstCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001902 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001903 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001904 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001905
Douglas Gregorb98b1992009-08-11 05:31:07 +00001906 default:
David Blaikieb219cfc2011-09-23 05:06:16 +00001907 llvm_unreachable("Invalid C++ named cast");
Douglas Gregorb98b1992009-08-11 05:31:07 +00001908 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00001909 }
Mike Stump1eb44332009-09-09 15:08:12 +00001910
Douglas Gregorb98b1992009-08-11 05:31:07 +00001911 /// \brief Build a new C++ static_cast expression.
1912 ///
1913 /// By default, performs semantic analysis to build the new expression.
1914 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001915 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001916 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001917 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001918 SourceLocation RAngleLoc,
1919 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001920 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001921 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001922 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001923 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001924 SourceRange(LAngleLoc, RAngleLoc),
1925 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001926 }
1927
1928 /// \brief Build a new C++ dynamic_cast expression.
1929 ///
1930 /// By default, performs semantic analysis to build the new expression.
1931 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001932 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001933 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001934 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001935 SourceLocation RAngleLoc,
1936 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001937 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001938 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001939 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001940 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001941 SourceRange(LAngleLoc, RAngleLoc),
1942 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001943 }
1944
1945 /// \brief Build a new C++ reinterpret_cast expression.
1946 ///
1947 /// By default, performs semantic analysis to build the new expression.
1948 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001949 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001950 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001951 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001952 SourceLocation RAngleLoc,
1953 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001954 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001955 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001956 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001957 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001958 SourceRange(LAngleLoc, RAngleLoc),
1959 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001960 }
1961
1962 /// \brief Build a new C++ const_cast expression.
1963 ///
1964 /// By default, performs semantic analysis to build the new expression.
1965 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001966 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001967 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001968 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001969 SourceLocation RAngleLoc,
1970 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001971 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001972 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001973 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001974 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001975 SourceRange(LAngleLoc, RAngleLoc),
1976 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001977 }
Mike Stump1eb44332009-09-09 15:08:12 +00001978
Douglas Gregorb98b1992009-08-11 05:31:07 +00001979 /// \brief Build a new C++ functional-style cast expression.
1980 ///
1981 /// By default, performs semantic analysis to build the new expression.
1982 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001983 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1984 SourceLocation LParenLoc,
1985 Expr *Sub,
1986 SourceLocation RParenLoc) {
1987 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001988 MultiExprArg(&Sub, 1),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001989 RParenLoc);
1990 }
Mike Stump1eb44332009-09-09 15:08:12 +00001991
Douglas Gregorb98b1992009-08-11 05:31:07 +00001992 /// \brief Build a new C++ typeid(type) expression.
1993 ///
1994 /// By default, performs semantic analysis to build the new expression.
1995 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001996 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001997 SourceLocation TypeidLoc,
1998 TypeSourceInfo *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001999 SourceLocation RParenLoc) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002000 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00002001 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002002 }
Mike Stump1eb44332009-09-09 15:08:12 +00002003
Francois Pichet01b7c302010-09-08 12:20:18 +00002004
Douglas Gregorb98b1992009-08-11 05:31:07 +00002005 /// \brief Build a new C++ typeid(expr) expression.
2006 ///
2007 /// By default, performs semantic analysis to build the new expression.
2008 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002009 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00002010 SourceLocation TypeidLoc,
John McCall9ae2f072010-08-23 23:25:46 +00002011 Expr *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002012 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00002013 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00002014 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002015 }
2016
Francois Pichet01b7c302010-09-08 12:20:18 +00002017 /// \brief Build a new C++ __uuidof(type) expression.
2018 ///
2019 /// By default, performs semantic analysis to build the new expression.
2020 /// Subclasses may override this routine to provide different behavior.
2021 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2022 SourceLocation TypeidLoc,
2023 TypeSourceInfo *Operand,
2024 SourceLocation RParenLoc) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002025 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
Francois Pichet01b7c302010-09-08 12:20:18 +00002026 RParenLoc);
2027 }
2028
2029 /// \brief Build a new C++ __uuidof(expr) expression.
2030 ///
2031 /// By default, performs semantic analysis to build the new expression.
2032 /// Subclasses may override this routine to provide different behavior.
2033 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2034 SourceLocation TypeidLoc,
2035 Expr *Operand,
2036 SourceLocation RParenLoc) {
2037 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
2038 RParenLoc);
2039 }
2040
Douglas Gregorb98b1992009-08-11 05:31:07 +00002041 /// \brief Build a new C++ "this" expression.
2042 ///
2043 /// By default, builds a new "this" expression without performing any
Mike Stump1eb44332009-09-09 15:08:12 +00002044 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregorb98b1992009-08-11 05:31:07 +00002045 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002046 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00002047 QualType ThisType,
2048 bool isImplicit) {
Eli Friedmanb69b42c2012-01-11 02:36:31 +00002049 getSema().CheckCXXThisCapture(ThisLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002050 return getSema().Owned(
Douglas Gregor828a1972010-01-07 23:12:05 +00002051 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
2052 isImplicit));
Douglas Gregorb98b1992009-08-11 05:31:07 +00002053 }
2054
2055 /// \brief Build a new C++ throw expression.
2056 ///
2057 /// By default, performs semantic analysis to build the new expression.
2058 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorbca01b42011-07-06 22:04:06 +00002059 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
2060 bool IsThrownVariableInScope) {
2061 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002062 }
2063
2064 /// \brief Build a new C++ default-argument expression.
2065 ///
2066 /// By default, builds a new default-argument expression, which does not
2067 /// require any semantic analysis. Subclasses may override this routine to
2068 /// provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002069 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor036aed12009-12-23 23:03:06 +00002070 ParmVarDecl *Param) {
2071 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
2072 Param));
Douglas Gregorb98b1992009-08-11 05:31:07 +00002073 }
2074
Richard Smithc3bf52c2013-04-20 22:23:05 +00002075 /// \brief Build a new C++11 default-initialization expression.
2076 ///
2077 /// By default, builds a new default field initialization expression, which
2078 /// does not require any semantic analysis. Subclasses may override this
2079 /// routine to provide different behavior.
2080 ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc,
2081 FieldDecl *Field) {
2082 return getSema().Owned(CXXDefaultInitExpr::Create(getSema().Context, Loc,
2083 Field));
2084 }
2085
Douglas Gregorb98b1992009-08-11 05:31:07 +00002086 /// \brief Build a new C++ zero-initialization expression.
2087 ///
2088 /// By default, performs semantic analysis to build the new expression.
2089 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002090 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
2091 SourceLocation LParenLoc,
2092 SourceLocation RParenLoc) {
2093 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Dmitri Gribenko62ed8892013-05-05 20:40:26 +00002094 None, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002095 }
Mike Stump1eb44332009-09-09 15:08:12 +00002096
Douglas Gregorb98b1992009-08-11 05:31:07 +00002097 /// \brief Build a new C++ "new" expression.
2098 ///
2099 /// By default, performs semantic analysis to build the new expression.
2100 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002101 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00002102 bool UseGlobal,
2103 SourceLocation PlacementLParen,
2104 MultiExprArg PlacementArgs,
2105 SourceLocation PlacementRParen,
2106 SourceRange TypeIdParens,
2107 QualType AllocatedType,
2108 TypeSourceInfo *AllocatedTypeInfo,
2109 Expr *ArraySize,
Sebastian Redl2aed8b82012-02-16 12:22:20 +00002110 SourceRange DirectInitRange,
2111 Expr *Initializer) {
Mike Stump1eb44332009-09-09 15:08:12 +00002112 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002113 PlacementLParen,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002114 PlacementArgs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002115 PlacementRParen,
Douglas Gregor4bd40312010-07-13 15:54:32 +00002116 TypeIdParens,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00002117 AllocatedType,
2118 AllocatedTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00002119 ArraySize,
Sebastian Redl2aed8b82012-02-16 12:22:20 +00002120 DirectInitRange,
2121 Initializer);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002122 }
Mike Stump1eb44332009-09-09 15:08:12 +00002123
Douglas Gregorb98b1992009-08-11 05:31:07 +00002124 /// \brief Build a new C++ "delete" expression.
2125 ///
2126 /// By default, performs semantic analysis to build the new expression.
2127 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002128 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002129 bool IsGlobalDelete,
2130 bool IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00002131 Expr *Operand) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002132 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00002133 Operand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002134 }
Mike Stump1eb44332009-09-09 15:08:12 +00002135
Douglas Gregorb98b1992009-08-11 05:31:07 +00002136 /// \brief Build a new unary type trait expression.
2137 ///
2138 /// By default, performs semantic analysis to build the new expression.
2139 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002140 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00002141 SourceLocation StartLoc,
2142 TypeSourceInfo *T,
2143 SourceLocation RParenLoc) {
2144 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002145 }
2146
Francois Pichet6ad6f282010-12-07 00:08:36 +00002147 /// \brief Build a new binary type trait expression.
2148 ///
2149 /// By default, performs semantic analysis to build the new expression.
2150 /// Subclasses may override this routine to provide different behavior.
2151 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
2152 SourceLocation StartLoc,
2153 TypeSourceInfo *LhsT,
2154 TypeSourceInfo *RhsT,
2155 SourceLocation RParenLoc) {
2156 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
2157 }
2158
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00002159 /// \brief Build a new type trait expression.
2160 ///
2161 /// By default, performs semantic analysis to build the new expression.
2162 /// Subclasses may override this routine to provide different behavior.
2163 ExprResult RebuildTypeTrait(TypeTrait Trait,
2164 SourceLocation StartLoc,
2165 ArrayRef<TypeSourceInfo *> Args,
2166 SourceLocation RParenLoc) {
2167 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2168 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002169
John Wiegley21ff2e52011-04-28 00:16:57 +00002170 /// \brief Build a new array type trait expression.
2171 ///
2172 /// By default, performs semantic analysis to build the new expression.
2173 /// Subclasses may override this routine to provide different behavior.
2174 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2175 SourceLocation StartLoc,
2176 TypeSourceInfo *TSInfo,
2177 Expr *DimExpr,
2178 SourceLocation RParenLoc) {
2179 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2180 }
2181
John Wiegley55262202011-04-25 06:54:41 +00002182 /// \brief Build a new expression trait expression.
2183 ///
2184 /// By default, performs semantic analysis to build the new expression.
2185 /// Subclasses may override this routine to provide different behavior.
2186 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2187 SourceLocation StartLoc,
2188 Expr *Queried,
2189 SourceLocation RParenLoc) {
2190 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2191 }
2192
Mike Stump1eb44332009-09-09 15:08:12 +00002193 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregorb98b1992009-08-11 05:31:07 +00002194 /// expression.
2195 ///
2196 /// By default, performs semantic analysis to build the new expression.
2197 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00002198 ExprResult RebuildDependentScopeDeclRefExpr(
2199 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002200 SourceLocation TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00002201 const DeclarationNameInfo &NameInfo,
Richard Smithefeeccf2012-10-21 03:28:35 +00002202 const TemplateArgumentListInfo *TemplateArgs,
2203 bool IsAddressOfOperand) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002204 CXXScopeSpec SS;
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00002205 SS.Adopt(QualifierLoc);
John McCallf7a1a742009-11-24 19:00:30 +00002206
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002207 if (TemplateArgs || TemplateKWLoc.isValid())
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002208 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002209 NameInfo, TemplateArgs);
John McCallf7a1a742009-11-24 19:00:30 +00002210
Richard Smithefeeccf2012-10-21 03:28:35 +00002211 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo,
2212 IsAddressOfOperand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002213 }
2214
2215 /// \brief Build a new template-id expression.
2216 ///
2217 /// By default, performs semantic analysis to build the new expression.
2218 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002219 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002220 SourceLocation TemplateKWLoc,
2221 LookupResult &R,
2222 bool RequiresADL,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002223 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002224 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2225 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002226 }
2227
2228 /// \brief Build a new object-construction expression.
2229 ///
2230 /// By default, performs semantic analysis to build the new expression.
2231 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002232 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002233 SourceLocation Loc,
2234 CXXConstructorDecl *Constructor,
2235 bool IsElidable,
2236 MultiExprArg Args,
2237 bool HadMultipleCandidates,
Richard Smithc83c2302012-12-19 01:39:02 +00002238 bool ListInitialization,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002239 bool RequiresZeroInit,
Chandler Carruth428edaf2010-10-25 08:47:36 +00002240 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002241 SourceRange ParenRange) {
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00002242 SmallVector<Expr*, 8> ConvertedArgs;
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002243 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002244 ConvertedArgs))
John McCallf312b1e2010-08-26 23:41:50 +00002245 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002246
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002247 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002248 ConvertedArgs,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002249 HadMultipleCandidates,
Richard Smithc83c2302012-12-19 01:39:02 +00002250 ListInitialization,
Chandler Carruth428edaf2010-10-25 08:47:36 +00002251 RequiresZeroInit, ConstructKind,
2252 ParenRange);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002253 }
2254
2255 /// \brief Build a new object-construction expression.
2256 ///
2257 /// By default, performs semantic analysis to build the new expression.
2258 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002259 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2260 SourceLocation LParenLoc,
2261 MultiExprArg Args,
2262 SourceLocation RParenLoc) {
2263 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002264 LParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002265 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002266 RParenLoc);
2267 }
2268
2269 /// \brief Build a new object-construction expression.
2270 ///
2271 /// By default, performs semantic analysis to build the new expression.
2272 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002273 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2274 SourceLocation LParenLoc,
2275 MultiExprArg Args,
2276 SourceLocation RParenLoc) {
2277 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002278 LParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002279 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002280 RParenLoc);
2281 }
Mike Stump1eb44332009-09-09 15:08:12 +00002282
Douglas Gregorb98b1992009-08-11 05:31:07 +00002283 /// \brief Build a new member reference expression.
2284 ///
2285 /// By default, performs semantic analysis to build the new expression.
2286 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002287 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002288 QualType BaseType,
2289 bool IsArrow,
2290 SourceLocation OperatorLoc,
2291 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002292 SourceLocation TemplateKWLoc,
John McCall129e2df2009-11-30 22:42:35 +00002293 NamedDecl *FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002294 const DeclarationNameInfo &MemberNameInfo,
John McCall129e2df2009-11-30 22:42:35 +00002295 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002296 CXXScopeSpec SS;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002297 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002298
John McCall9ae2f072010-08-23 23:25:46 +00002299 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002300 OperatorLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002301 SS, TemplateKWLoc,
2302 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002303 MemberNameInfo,
2304 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002305 }
2306
John McCall129e2df2009-11-30 22:42:35 +00002307 /// \brief Build a new member reference expression.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002308 ///
2309 /// By default, performs semantic analysis to build the new expression.
2310 /// Subclasses may override this routine to provide different behavior.
Richard Smith9138b4e2011-10-26 19:06:56 +00002311 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2312 SourceLocation OperatorLoc,
2313 bool IsArrow,
2314 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002315 SourceLocation TemplateKWLoc,
Richard Smith9138b4e2011-10-26 19:06:56 +00002316 NamedDecl *FirstQualifierInScope,
2317 LookupResult &R,
John McCall129e2df2009-11-30 22:42:35 +00002318 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002319 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00002320 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002321
John McCall9ae2f072010-08-23 23:25:46 +00002322 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002323 OperatorLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002324 SS, TemplateKWLoc,
2325 FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00002326 R, TemplateArgs);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002327 }
Mike Stump1eb44332009-09-09 15:08:12 +00002328
Sebastian Redl2e156222010-09-10 20:55:43 +00002329 /// \brief Build a new noexcept expression.
2330 ///
2331 /// By default, performs semantic analysis to build the new expression.
2332 /// Subclasses may override this routine to provide different behavior.
2333 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2334 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2335 }
2336
Douglas Gregoree8aff02011-01-04 17:33:58 +00002337 /// \brief Build a new expression to compute the length of a parameter pack.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002338 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2339 SourceLocation PackLoc,
Douglas Gregoree8aff02011-01-04 17:33:58 +00002340 SourceLocation RParenLoc,
David Blaikiedc84cd52013-02-20 22:23:23 +00002341 Optional<unsigned> Length) {
Douglas Gregor089e8932011-10-10 18:59:29 +00002342 if (Length)
Chad Rosier4a9d7952012-08-08 18:46:20 +00002343 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2344 OperatorLoc, Pack, PackLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002345 RParenLoc, *Length);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002346
2347 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2348 OperatorLoc, Pack, PackLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002349 RParenLoc);
Douglas Gregoree8aff02011-01-04 17:33:58 +00002350 }
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002351
Patrick Beardeb382ec2012-04-19 00:25:12 +00002352 /// \brief Build a new Objective-C boxed expression.
2353 ///
2354 /// By default, performs semantic analysis to build the new expression.
2355 /// Subclasses may override this routine to provide different behavior.
2356 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2357 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2358 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002359
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002360 /// \brief Build a new Objective-C array literal.
2361 ///
2362 /// By default, performs semantic analysis to build the new expression.
2363 /// Subclasses may override this routine to provide different behavior.
2364 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2365 Expr **Elements, unsigned NumElements) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002366 return getSema().BuildObjCArrayLiteral(Range,
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002367 MultiExprArg(Elements, NumElements));
2368 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002369
2370 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002371 Expr *Base, Expr *Key,
2372 ObjCMethodDecl *getterMethod,
2373 ObjCMethodDecl *setterMethod) {
2374 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2375 getterMethod, setterMethod);
2376 }
2377
2378 /// \brief Build a new Objective-C dictionary literal.
2379 ///
2380 /// By default, performs semantic analysis to build the new expression.
2381 /// Subclasses may override this routine to provide different behavior.
2382 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
2383 ObjCDictionaryElement *Elements,
2384 unsigned NumElements) {
2385 return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements);
2386 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002387
James Dennett699c9042012-06-15 07:13:21 +00002388 /// \brief Build a new Objective-C \@encode expression.
Douglas Gregorb98b1992009-08-11 05:31:07 +00002389 ///
2390 /// By default, performs semantic analysis to build the new expression.
2391 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002392 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregor81d34662010-04-20 15:39:42 +00002393 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002394 SourceLocation RParenLoc) {
Douglas Gregor81d34662010-04-20 15:39:42 +00002395 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002396 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002397 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00002398
Douglas Gregor92e986e2010-04-22 16:44:27 +00002399 /// \brief Build a new Objective-C class message.
John McCall60d7b3a2010-08-24 06:29:42 +00002400 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002401 Selector Sel,
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002402 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002403 ObjCMethodDecl *Method,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002404 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002405 MultiExprArg Args,
2406 SourceLocation RBracLoc) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00002407 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2408 ReceiverTypeInfo->getType(),
2409 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002410 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002411 RBracLoc, Args);
Douglas Gregor92e986e2010-04-22 16:44:27 +00002412 }
2413
2414 /// \brief Build a new Objective-C instance message.
John McCall60d7b3a2010-08-24 06:29:42 +00002415 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002416 Selector Sel,
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002417 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002418 ObjCMethodDecl *Method,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002419 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002420 MultiExprArg Args,
2421 SourceLocation RBracLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00002422 return SemaRef.BuildInstanceMessage(Receiver,
2423 Receiver->getType(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00002424 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002425 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002426 RBracLoc, Args);
Douglas Gregor92e986e2010-04-22 16:44:27 +00002427 }
2428
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002429 /// \brief Build a new Objective-C ivar reference expression.
2430 ///
2431 /// By default, performs semantic analysis to build the new expression.
2432 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002433 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002434 SourceLocation IvarLoc,
2435 bool IsArrow, bool IsFreeIvar) {
2436 // FIXME: We lose track of the IsFreeIvar bit.
2437 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002438 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002439 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2440 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002441 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002442 /*FIME:*/IvarLoc,
John McCalld226f652010-08-21 09:40:31 +00002443 SS, 0,
John McCallad00b772010-06-16 08:42:20 +00002444 false);
John Wiegley429bb272011-04-08 18:41:53 +00002445 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002446 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002447
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002448 if (Result.get())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002449 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002450
John Wiegley429bb272011-04-08 18:41:53 +00002451 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002452 /*FIXME:*/IvarLoc, IsArrow,
2453 SS, SourceLocation(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002454 /*FirstQualifierInScope=*/0,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002455 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002456 /*TemplateArgs=*/0);
2457 }
Douglas Gregore3303542010-04-26 20:47:02 +00002458
2459 /// \brief Build a new Objective-C property reference expression.
2460 ///
2461 /// By default, performs semantic analysis to build the new expression.
2462 /// Subclasses may override this routine to provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002463 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall3c3b7f92011-10-25 17:37:35 +00002464 ObjCPropertyDecl *Property,
2465 SourceLocation PropertyLoc) {
Douglas Gregore3303542010-04-26 20:47:02 +00002466 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002467 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregore3303542010-04-26 20:47:02 +00002468 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2469 Sema::LookupMemberName);
2470 bool IsArrow = false;
John McCall60d7b3a2010-08-24 06:29:42 +00002471 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregore3303542010-04-26 20:47:02 +00002472 /*FIME:*/PropertyLoc,
John McCalld226f652010-08-21 09:40:31 +00002473 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002474 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002475 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002476
Douglas Gregore3303542010-04-26 20:47:02 +00002477 if (Result.get())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002478 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002479
John Wiegley429bb272011-04-08 18:41:53 +00002480 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002481 /*FIXME:*/PropertyLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002482 SS, SourceLocation(),
Douglas Gregore3303542010-04-26 20:47:02 +00002483 /*FirstQualifierInScope=*/0,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002484 R,
Douglas Gregore3303542010-04-26 20:47:02 +00002485 /*TemplateArgs=*/0);
2486 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002487
John McCall12f78a62010-12-02 01:19:52 +00002488 /// \brief Build a new Objective-C property reference expression.
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002489 ///
2490 /// By default, performs semantic analysis to build the new expression.
John McCall12f78a62010-12-02 01:19:52 +00002491 /// Subclasses may override this routine to provide different behavior.
2492 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2493 ObjCMethodDecl *Getter,
2494 ObjCMethodDecl *Setter,
2495 SourceLocation PropertyLoc) {
2496 // Since these expressions can only be value-dependent, we do not
2497 // need to perform semantic analysis again.
2498 return Owned(
2499 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2500 VK_LValue, OK_ObjCProperty,
2501 PropertyLoc, Base));
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002502 }
2503
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002504 /// \brief Build a new Objective-C "isa" expression.
2505 ///
2506 /// By default, performs semantic analysis to build the new expression.
2507 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002508 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Fariborz Jahanianec8deba2013-03-28 19:50:55 +00002509 SourceLocation OpLoc,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002510 bool IsArrow) {
2511 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002512 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002513 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2514 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002515 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Fariborz Jahanianec8deba2013-03-28 19:50:55 +00002516 OpLoc,
John McCalld226f652010-08-21 09:40:31 +00002517 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002518 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002519 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002520
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002521 if (Result.get())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002522 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002523
John Wiegley429bb272011-04-08 18:41:53 +00002524 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Fariborz Jahanianec8deba2013-03-28 19:50:55 +00002525 OpLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002526 SS, SourceLocation(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002527 /*FirstQualifierInScope=*/0,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002528 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002529 /*TemplateArgs=*/0);
2530 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002531
Douglas Gregorb98b1992009-08-11 05:31:07 +00002532 /// \brief Build a new shuffle vector expression.
2533 ///
2534 /// By default, performs semantic analysis to build the new expression.
2535 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002536 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCallf89e55a2010-11-18 06:31:45 +00002537 MultiExprArg SubExprs,
2538 SourceLocation RParenLoc) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002539 // Find the declaration for __builtin_shufflevector
Mike Stump1eb44332009-09-09 15:08:12 +00002540 const IdentifierInfo &Name
Douglas Gregorb98b1992009-08-11 05:31:07 +00002541 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2542 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2543 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
David Blaikie3bc93e32012-12-19 00:45:41 +00002544 assert(!Lookup.empty() && "No __builtin_shufflevector?");
Mike Stump1eb44332009-09-09 15:08:12 +00002545
Douglas Gregorb98b1992009-08-11 05:31:07 +00002546 // Build a reference to the __builtin_shufflevector builtin
David Blaikie3bc93e32012-12-19 00:45:41 +00002547 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
Eli Friedmana6c66ce2012-08-31 00:14:07 +00002548 Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false,
2549 SemaRef.Context.BuiltinFnTy,
2550 VK_RValue, BuiltinLoc);
2551 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
2552 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
2553 CK_BuiltinFnToFnPtr).take();
Mike Stump1eb44332009-09-09 15:08:12 +00002554
2555 // Build the CallExpr
John Wiegley429bb272011-04-08 18:41:53 +00002556 ExprResult TheCall = SemaRef.Owned(
Eli Friedmana6c66ce2012-08-31 00:14:07 +00002557 new (SemaRef.Context) CallExpr(SemaRef.Context, Callee, SubExprs,
Benjamin Kramer3b6bef92012-08-24 11:54:20 +00002558 Builtin->getCallResultType(),
John McCallf89e55a2010-11-18 06:31:45 +00002559 Expr::getValueKindForType(Builtin->getResultType()),
John Wiegley429bb272011-04-08 18:41:53 +00002560 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002561
Douglas Gregorb98b1992009-08-11 05:31:07 +00002562 // Type-check the __builtin_shufflevector expression.
John Wiegley429bb272011-04-08 18:41:53 +00002563 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.take()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00002564 }
John McCall43fed0d2010-11-12 08:19:04 +00002565
Hal Finkel414a1bd2013-09-18 03:29:45 +00002566 /// \brief Build a new convert vector expression.
2567 ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc,
2568 Expr *SrcExpr, TypeSourceInfo *DstTInfo,
2569 SourceLocation RParenLoc) {
2570 return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo,
2571 BuiltinLoc, RParenLoc);
2572 }
2573
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002574 /// \brief Build a new template argument pack expansion.
2575 ///
2576 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier4a9d7952012-08-08 18:46:20 +00002577 /// for a template argument. Subclasses may override this routine to provide
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002578 /// different behavior.
2579 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregorcded4f62011-01-14 17:04:44 +00002580 SourceLocation EllipsisLoc,
David Blaikiedc84cd52013-02-20 22:23:23 +00002581 Optional<unsigned> NumExpansions) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002582 switch (Pattern.getArgument().getKind()) {
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002583 case TemplateArgument::Expression: {
2584 ExprResult Result
Douglas Gregor67fd1252011-01-14 21:20:45 +00002585 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2586 EllipsisLoc, NumExpansions);
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002587 if (Result.isInvalid())
2588 return TemplateArgumentLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002589
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002590 return TemplateArgumentLoc(Result.get(), Result.get());
2591 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002592
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002593 case TemplateArgument::Template:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002594 return TemplateArgumentLoc(TemplateArgument(
2595 Pattern.getArgument().getAsTemplate(),
Douglas Gregor2be29f42011-01-14 23:41:42 +00002596 NumExpansions),
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002597 Pattern.getTemplateQualifierLoc(),
Douglas Gregora7fc9012011-01-05 18:58:31 +00002598 Pattern.getTemplateNameLoc(),
2599 EllipsisLoc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002600
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002601 case TemplateArgument::Null:
2602 case TemplateArgument::Integral:
2603 case TemplateArgument::Declaration:
2604 case TemplateArgument::Pack:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002605 case TemplateArgument::TemplateExpansion:
Eli Friedmand7a6b162012-09-26 02:36:12 +00002606 case TemplateArgument::NullPtr:
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002607 llvm_unreachable("Pack expansion pattern has no parameter packs");
Chad Rosier4a9d7952012-08-08 18:46:20 +00002608
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002609 case TemplateArgument::Type:
Chad Rosier4a9d7952012-08-08 18:46:20 +00002610 if (TypeSourceInfo *Expansion
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002611 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00002612 EllipsisLoc,
2613 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002614 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2615 Expansion);
2616 break;
2617 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002618
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002619 return TemplateArgumentLoc();
2620 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002621
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002622 /// \brief Build a new expression pack expansion.
2623 ///
2624 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier4a9d7952012-08-08 18:46:20 +00002625 /// for an expression. Subclasses may override this routine to provide
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002626 /// different behavior.
Douglas Gregor67fd1252011-01-14 21:20:45 +00002627 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
David Blaikiedc84cd52013-02-20 22:23:23 +00002628 Optional<unsigned> NumExpansions) {
Douglas Gregor67fd1252011-01-14 21:20:45 +00002629 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002630 }
Eli Friedmandfa64ba2011-10-14 22:48:56 +00002631
2632 /// \brief Build a new atomic operation expression.
2633 ///
2634 /// By default, performs semantic analysis to build the new expression.
2635 /// Subclasses may override this routine to provide different behavior.
2636 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2637 MultiExprArg SubExprs,
2638 QualType RetTy,
2639 AtomicExpr::AtomicOp Op,
2640 SourceLocation RParenLoc) {
2641 // Just create the expression; there is not any interesting semantic
2642 // analysis here because we can't actually build an AtomicExpr until
2643 // we are sure it is semantically sound.
Benjamin Kramer3b6bef92012-08-24 11:54:20 +00002644 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
Eli Friedmandfa64ba2011-10-14 22:48:56 +00002645 RParenLoc);
2646 }
2647
John McCall43fed0d2010-11-12 08:19:04 +00002648private:
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002649 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2650 QualType ObjectType,
2651 NamedDecl *FirstQualifierInScope,
2652 CXXScopeSpec &SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00002653
2654 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2655 QualType ObjectType,
2656 NamedDecl *FirstQualifierInScope,
2657 CXXScopeSpec &SS);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002658};
Douglas Gregorb98b1992009-08-11 05:31:07 +00002659
Douglas Gregor43959a92009-08-20 07:17:43 +00002660template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002661StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00002662 if (!S)
2663 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00002664
Douglas Gregor43959a92009-08-20 07:17:43 +00002665 switch (S->getStmtClass()) {
2666 case Stmt::NoStmtClass: break;
Mike Stump1eb44332009-09-09 15:08:12 +00002667
Douglas Gregor43959a92009-08-20 07:17:43 +00002668 // Transform individual statement nodes
2669#define STMT(Node, Parent) \
2670 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCall63c00d72011-02-09 08:16:59 +00002671#define ABSTRACT_STMT(Node)
Douglas Gregor43959a92009-08-20 07:17:43 +00002672#define EXPR(Node, Parent)
Sean Hunt4bfe1962010-05-05 15:24:00 +00002673#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002674
Douglas Gregor43959a92009-08-20 07:17:43 +00002675 // Transform expressions by calling TransformExpr.
2676#define STMT(Node, Parent)
Sean Hunt7381d5c2010-05-18 06:22:21 +00002677#define ABSTRACT_STMT(Stmt)
Douglas Gregor43959a92009-08-20 07:17:43 +00002678#define EXPR(Node, Parent) case Stmt::Node##Class:
Sean Hunt4bfe1962010-05-05 15:24:00 +00002679#include "clang/AST/StmtNodes.inc"
Douglas Gregor43959a92009-08-20 07:17:43 +00002680 {
John McCall60d7b3a2010-08-24 06:29:42 +00002681 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregor43959a92009-08-20 07:17:43 +00002682 if (E.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002683 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00002684
Richard Smith41956372013-01-14 22:39:08 +00002685 return getSema().ActOnExprStmt(E);
Douglas Gregor43959a92009-08-20 07:17:43 +00002686 }
Mike Stump1eb44332009-09-09 15:08:12 +00002687 }
2688
John McCall3fa5cae2010-10-26 07:05:15 +00002689 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00002690}
Mike Stump1eb44332009-09-09 15:08:12 +00002691
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00002692template<typename Derived>
2693OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) {
2694 if (!S)
2695 return S;
2696
2697 switch (S->getClauseKind()) {
2698 default: break;
2699 // Transform individual clause nodes
2700#define OPENMP_CLAUSE(Name, Class) \
2701 case OMPC_ ## Name : \
2702 return getDerived().Transform ## Class(cast<Class>(S));
2703#include "clang/Basic/OpenMPKinds.def"
2704 }
2705
2706 return S;
2707}
2708
Mike Stump1eb44332009-09-09 15:08:12 +00002709
Douglas Gregor670444e2009-08-04 22:27:00 +00002710template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002711ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002712 if (!E)
2713 return SemaRef.Owned(E);
2714
2715 switch (E->getStmtClass()) {
2716 case Stmt::NoStmtClass: break;
2717#define STMT(Node, Parent) case Stmt::Node##Class: break;
Sean Hunt7381d5c2010-05-18 06:22:21 +00002718#define ABSTRACT_STMT(Stmt)
Douglas Gregorb98b1992009-08-11 05:31:07 +00002719#define EXPR(Node, Parent) \
John McCall454feb92009-12-08 09:21:05 +00002720 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Sean Hunt4bfe1962010-05-05 15:24:00 +00002721#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002722 }
2723
John McCall3fa5cae2010-10-26 07:05:15 +00002724 return SemaRef.Owned(E);
Douglas Gregor657c1ac2009-08-06 22:17:10 +00002725}
2726
2727template<typename Derived>
Richard Smithc83c2302012-12-19 01:39:02 +00002728ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
2729 bool CXXDirectInit) {
2730 // Initializers are instantiated like expressions, except that various outer
2731 // layers are stripped.
2732 if (!Init)
2733 return SemaRef.Owned(Init);
2734
2735 if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init))
2736 Init = ExprTemp->getSubExpr();
2737
Richard Smith858c2c32013-05-30 22:40:16 +00002738 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
2739 Init = MTE->GetTemporaryExpr();
2740
Richard Smithc83c2302012-12-19 01:39:02 +00002741 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
2742 Init = Binder->getSubExpr();
2743
2744 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
2745 Init = ICE->getSubExprAsWritten();
2746
Richard Smith7c3e6152013-06-12 22:31:48 +00002747 if (CXXStdInitializerListExpr *ILE =
2748 dyn_cast<CXXStdInitializerListExpr>(Init))
2749 return TransformInitializer(ILE->getSubExpr(), CXXDirectInit);
2750
Richard Smith5cf15892012-12-21 08:13:35 +00002751 // If this is not a direct-initializer, we only need to reconstruct
2752 // InitListExprs. Other forms of copy-initialization will be a no-op if
2753 // the initializer is already the right type.
2754 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
2755 if (!CXXDirectInit && !(Construct && Construct->isListInitialization()))
2756 return getDerived().TransformExpr(Init);
2757
2758 // Revert value-initialization back to empty parens.
2759 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
2760 SourceRange Parens = VIE->getSourceRange();
Dmitri Gribenko62ed8892013-05-05 20:40:26 +00002761 return getDerived().RebuildParenListExpr(Parens.getBegin(), None,
Richard Smith5cf15892012-12-21 08:13:35 +00002762 Parens.getEnd());
2763 }
2764
2765 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
2766 if (isa<ImplicitValueInitExpr>(Init))
Dmitri Gribenko62ed8892013-05-05 20:40:26 +00002767 return getDerived().RebuildParenListExpr(SourceLocation(), None,
Richard Smith5cf15892012-12-21 08:13:35 +00002768 SourceLocation());
2769
2770 // Revert initialization by constructor back to a parenthesized or braced list
2771 // of expressions. Any other form of initializer can just be reused directly.
2772 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
Richard Smithc83c2302012-12-19 01:39:02 +00002773 return getDerived().TransformExpr(Init);
2774
2775 SmallVector<Expr*, 8> NewArgs;
2776 bool ArgChanged = false;
2777 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
2778 /*IsCall*/true, NewArgs, &ArgChanged))
2779 return ExprError();
2780
2781 // If this was list initialization, revert to list form.
2782 if (Construct->isListInitialization())
2783 return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs,
2784 Construct->getLocEnd(),
2785 Construct->getType());
2786
Richard Smithc83c2302012-12-19 01:39:02 +00002787 // Build a ParenListExpr to represent anything else.
Enea Zaffanella1245a542013-09-07 05:49:53 +00002788 SourceRange Parens = Construct->getParenOrBraceRange();
Richard Smithc83c2302012-12-19 01:39:02 +00002789 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
2790 Parens.getEnd());
2791}
2792
2793template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00002794bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2795 unsigned NumInputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +00002796 bool IsCall,
Chris Lattner686775d2011-07-20 06:58:45 +00002797 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +00002798 bool *ArgChanged) {
2799 for (unsigned I = 0; I != NumInputs; ++I) {
2800 // If requested, drop call arguments that need to be dropped.
2801 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2802 if (ArgChanged)
2803 *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002804
Douglas Gregoraa165f82011-01-03 19:04:46 +00002805 break;
2806 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002807
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002808 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2809 Expr *Pattern = Expansion->getPattern();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002810
Chris Lattner686775d2011-07-20 06:58:45 +00002811 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002812 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2813 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier4a9d7952012-08-08 18:46:20 +00002814
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002815 // Determine whether the set of unexpanded parameter packs can and should
2816 // be expanded.
2817 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00002818 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00002819 Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
2820 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002821 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2822 Pattern->getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00002823 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00002824 Expand, RetainExpansion,
2825 NumExpansions))
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002826 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002827
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002828 if (!Expand) {
2829 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00002830 // transformation on the pack expansion, producing another pack
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002831 // expansion.
2832 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2833 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2834 if (OutPattern.isInvalid())
2835 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002836
2837 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregor67fd1252011-01-14 21:20:45 +00002838 Expansion->getEllipsisLoc(),
2839 NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002840 if (Out.isInvalid())
2841 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002842
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002843 if (ArgChanged)
2844 *ArgChanged = true;
2845 Outputs.push_back(Out.get());
2846 continue;
2847 }
John McCallc8fc90a2011-07-06 07:30:07 +00002848
2849 // Record right away that the argument was changed. This needs
2850 // to happen even if the array expands to nothing.
2851 if (ArgChanged) *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002852
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002853 // The transform has determined that we should perform an elementwise
2854 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00002855 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002856 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2857 ExprResult Out = getDerived().TransformExpr(Pattern);
2858 if (Out.isInvalid())
2859 return true;
2860
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002861 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregor67fd1252011-01-14 21:20:45 +00002862 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2863 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002864 if (Out.isInvalid())
2865 return true;
2866 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002867
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002868 Outputs.push_back(Out.get());
2869 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002870
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002871 continue;
2872 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002873
Richard Smithc83c2302012-12-19 01:39:02 +00002874 ExprResult Result =
2875 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
2876 : getDerived().TransformExpr(Inputs[I]);
Douglas Gregoraa165f82011-01-03 19:04:46 +00002877 if (Result.isInvalid())
2878 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002879
Douglas Gregoraa165f82011-01-03 19:04:46 +00002880 if (Result.get() != Inputs[I] && ArgChanged)
2881 *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002882
2883 Outputs.push_back(Result.get());
Douglas Gregoraa165f82011-01-03 19:04:46 +00002884 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002885
Douglas Gregoraa165f82011-01-03 19:04:46 +00002886 return false;
2887}
2888
2889template<typename Derived>
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002890NestedNameSpecifierLoc
2891TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2892 NestedNameSpecifierLoc NNS,
2893 QualType ObjectType,
2894 NamedDecl *FirstQualifierInScope) {
Chris Lattner686775d2011-07-20 06:58:45 +00002895 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002896 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002897 Qualifier = Qualifier.getPrefix())
2898 Qualifiers.push_back(Qualifier);
2899
2900 CXXScopeSpec SS;
2901 while (!Qualifiers.empty()) {
2902 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2903 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002904
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002905 switch (QNNS->getKind()) {
2906 case NestedNameSpecifier::Identifier:
Chad Rosier4a9d7952012-08-08 18:46:20 +00002907 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002908 *QNNS->getAsIdentifier(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002909 Q.getLocalBeginLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002910 Q.getLocalEndLoc(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002911 ObjectType, false, SS,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002912 FirstQualifierInScope, false))
2913 return NestedNameSpecifierLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002914
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002915 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002916
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002917 case NestedNameSpecifier::Namespace: {
2918 NamespaceDecl *NS
2919 = cast_or_null<NamespaceDecl>(
2920 getDerived().TransformDecl(
2921 Q.getLocalBeginLoc(),
2922 QNNS->getAsNamespace()));
2923 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2924 break;
2925 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002926
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002927 case NestedNameSpecifier::NamespaceAlias: {
2928 NamespaceAliasDecl *Alias
2929 = cast_or_null<NamespaceAliasDecl>(
2930 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2931 QNNS->getAsNamespaceAlias()));
Chad Rosier4a9d7952012-08-08 18:46:20 +00002932 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002933 Q.getLocalEndLoc());
2934 break;
2935 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002936
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002937 case NestedNameSpecifier::Global:
2938 // There is no meaningful transformation that one could perform on the
2939 // global scope.
2940 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2941 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002942
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002943 case NestedNameSpecifier::TypeSpecWithTemplate:
2944 case NestedNameSpecifier::TypeSpec: {
2945 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2946 FirstQualifierInScope, SS);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002947
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002948 if (!TL)
2949 return NestedNameSpecifierLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002950
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002951 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Richard Smith80ad52f2013-01-02 11:42:31 +00002952 (SemaRef.getLangOpts().CPlusPlus11 &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002953 TL.getType()->isEnumeralType())) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002954 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002955 "Can't get cv-qualifiers here");
Richard Smith95aafb22011-10-20 03:28:47 +00002956 if (TL.getType()->isEnumeralType())
2957 SemaRef.Diag(TL.getBeginLoc(),
2958 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002959 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2960 Q.getLocalEndLoc());
2961 break;
2962 }
Richard Trieu00c93a12011-05-07 01:36:37 +00002963 // If the nested-name-specifier is an invalid type def, don't emit an
2964 // error because a previous error should have already been emitted.
David Blaikie39e6ab42013-02-18 22:06:02 +00002965 TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
2966 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002967 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieu00c93a12011-05-07 01:36:37 +00002968 << TL.getType() << SS.getRange();
2969 }
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002970 return NestedNameSpecifierLoc();
2971 }
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002972 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002973
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002974 // The qualifier-in-scope and object type only apply to the leftmost entity.
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002975 FirstQualifierInScope = 0;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002976 ObjectType = QualType();
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002977 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002978
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002979 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002980 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002981 !getDerived().AlwaysRebuild())
2982 return NNS;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002983
2984 // If we can re-use the source-location data from the original
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002985 // nested-name-specifier, do so.
2986 if (SS.location_size() == NNS.getDataLength() &&
2987 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2988 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
2989
2990 // Allocate new nested-name-specifier location information.
2991 return SS.getWithLocInContext(SemaRef.Context);
2992}
2993
2994template<typename Derived>
Abramo Bagnara25777432010-08-11 22:01:17 +00002995DeclarationNameInfo
2996TreeTransform<Derived>
John McCall43fed0d2010-11-12 08:19:04 +00002997::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnara25777432010-08-11 22:01:17 +00002998 DeclarationName Name = NameInfo.getName();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002999 if (!Name)
Abramo Bagnara25777432010-08-11 22:01:17 +00003000 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00003001
3002 switch (Name.getNameKind()) {
3003 case DeclarationName::Identifier:
3004 case DeclarationName::ObjCZeroArgSelector:
3005 case DeclarationName::ObjCOneArgSelector:
3006 case DeclarationName::ObjCMultiArgSelector:
3007 case DeclarationName::CXXOperatorName:
Sean Hunt3e518bd2009-11-29 07:34:05 +00003008 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregor81499bb2009-09-03 22:13:48 +00003009 case DeclarationName::CXXUsingDirective:
Abramo Bagnara25777432010-08-11 22:01:17 +00003010 return NameInfo;
Mike Stump1eb44332009-09-09 15:08:12 +00003011
Douglas Gregor81499bb2009-09-03 22:13:48 +00003012 case DeclarationName::CXXConstructorName:
3013 case DeclarationName::CXXDestructorName:
3014 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnara25777432010-08-11 22:01:17 +00003015 TypeSourceInfo *NewTInfo;
3016 CanQualType NewCanTy;
3017 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00003018 NewTInfo = getDerived().TransformType(OldTInfo);
3019 if (!NewTInfo)
3020 return DeclarationNameInfo();
3021 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnara25777432010-08-11 22:01:17 +00003022 }
3023 else {
3024 NewTInfo = 0;
3025 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall43fed0d2010-11-12 08:19:04 +00003026 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnara25777432010-08-11 22:01:17 +00003027 if (NewT.isNull())
3028 return DeclarationNameInfo();
3029 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
3030 }
Mike Stump1eb44332009-09-09 15:08:12 +00003031
Abramo Bagnara25777432010-08-11 22:01:17 +00003032 DeclarationName NewName
3033 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
3034 NewCanTy);
3035 DeclarationNameInfo NewNameInfo(NameInfo);
3036 NewNameInfo.setName(NewName);
3037 NewNameInfo.setNamedTypeInfo(NewTInfo);
3038 return NewNameInfo;
Douglas Gregor81499bb2009-09-03 22:13:48 +00003039 }
Mike Stump1eb44332009-09-09 15:08:12 +00003040 }
3041
David Blaikieb219cfc2011-09-23 05:06:16 +00003042 llvm_unreachable("Unknown name kind.");
Douglas Gregor81499bb2009-09-03 22:13:48 +00003043}
3044
3045template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003046TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003047TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
3048 TemplateName Name,
3049 SourceLocation NameLoc,
3050 QualType ObjectType,
3051 NamedDecl *FirstQualifierInScope) {
3052 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
3053 TemplateDecl *Template = QTN->getTemplateDecl();
3054 assert(Template && "qualified template name must refer to a template");
Chad Rosier4a9d7952012-08-08 18:46:20 +00003055
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003056 TemplateDecl *TransTemplate
Chad Rosier4a9d7952012-08-08 18:46:20 +00003057 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003058 Template));
3059 if (!TransTemplate)
3060 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003061
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003062 if (!getDerived().AlwaysRebuild() &&
3063 SS.getScopeRep() == QTN->getQualifier() &&
3064 TransTemplate == Template)
3065 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003066
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003067 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
3068 TransTemplate);
3069 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003070
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003071 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
3072 if (SS.getScopeRep()) {
3073 // These apply to the scope specifier, not the template.
3074 ObjectType = QualType();
3075 FirstQualifierInScope = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003076 }
3077
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003078 if (!getDerived().AlwaysRebuild() &&
3079 SS.getScopeRep() == DTN->getQualifier() &&
3080 ObjectType.isNull())
3081 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003082
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003083 if (DTN->isIdentifier()) {
3084 return getDerived().RebuildTemplateName(SS,
Chad Rosier4a9d7952012-08-08 18:46:20 +00003085 *DTN->getIdentifier(),
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003086 NameLoc,
3087 ObjectType,
3088 FirstQualifierInScope);
3089 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003090
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003091 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
3092 ObjectType);
3093 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003094
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003095 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
3096 TemplateDecl *TransTemplate
Chad Rosier4a9d7952012-08-08 18:46:20 +00003097 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003098 Template));
3099 if (!TransTemplate)
3100 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003101
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003102 if (!getDerived().AlwaysRebuild() &&
3103 TransTemplate == Template)
3104 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003105
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003106 return TemplateName(TransTemplate);
3107 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003108
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003109 if (SubstTemplateTemplateParmPackStorage *SubstPack
3110 = Name.getAsSubstTemplateTemplateParmPack()) {
3111 TemplateTemplateParmDecl *TransParam
3112 = cast_or_null<TemplateTemplateParmDecl>(
3113 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
3114 if (!TransParam)
3115 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003116
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003117 if (!getDerived().AlwaysRebuild() &&
3118 TransParam == SubstPack->getParameterPack())
3119 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003120
3121 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003122 SubstPack->getArgumentPack());
3123 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003124
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003125 // These should be getting filtered out before they reach the AST.
3126 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003127}
3128
3129template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00003130void TreeTransform<Derived>::InventTemplateArgumentLoc(
3131 const TemplateArgument &Arg,
3132 TemplateArgumentLoc &Output) {
3133 SourceLocation Loc = getDerived().getBaseLocation();
3134 switch (Arg.getKind()) {
3135 case TemplateArgument::Null:
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00003136 llvm_unreachable("null template argument in TreeTransform");
John McCall833ca992009-10-29 08:12:44 +00003137 break;
3138
3139 case TemplateArgument::Type:
3140 Output = TemplateArgumentLoc(Arg,
John McCalla93c9342009-12-07 02:54:59 +00003141 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier4a9d7952012-08-08 18:46:20 +00003142
John McCall833ca992009-10-29 08:12:44 +00003143 break;
3144
Douglas Gregor788cd062009-11-11 01:00:40 +00003145 case TemplateArgument::Template:
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003146 case TemplateArgument::TemplateExpansion: {
3147 NestedNameSpecifierLocBuilder Builder;
3148 TemplateName Template = Arg.getAsTemplate();
3149 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3150 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3151 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3152 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003153
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003154 if (Arg.getKind() == TemplateArgument::Template)
Chad Rosier4a9d7952012-08-08 18:46:20 +00003155 Output = TemplateArgumentLoc(Arg,
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003156 Builder.getWithLocInContext(SemaRef.Context),
3157 Loc);
3158 else
Chad Rosier4a9d7952012-08-08 18:46:20 +00003159 Output = TemplateArgumentLoc(Arg,
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003160 Builder.getWithLocInContext(SemaRef.Context),
3161 Loc, Loc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003162
Douglas Gregor788cd062009-11-11 01:00:40 +00003163 break;
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003164 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00003165
John McCall833ca992009-10-29 08:12:44 +00003166 case TemplateArgument::Expression:
3167 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3168 break;
3169
3170 case TemplateArgument::Declaration:
3171 case TemplateArgument::Integral:
3172 case TemplateArgument::Pack:
Eli Friedmand7a6b162012-09-26 02:36:12 +00003173 case TemplateArgument::NullPtr:
John McCall828bff22009-10-29 18:45:58 +00003174 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall833ca992009-10-29 08:12:44 +00003175 break;
3176 }
3177}
3178
3179template<typename Derived>
3180bool TreeTransform<Derived>::TransformTemplateArgument(
3181 const TemplateArgumentLoc &Input,
3182 TemplateArgumentLoc &Output) {
3183 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregor670444e2009-08-04 22:27:00 +00003184 switch (Arg.getKind()) {
3185 case TemplateArgument::Null:
3186 case TemplateArgument::Integral:
Eli Friedman511e3ae2012-09-25 01:02:42 +00003187 case TemplateArgument::Pack:
3188 case TemplateArgument::Declaration:
Eli Friedmand7a6b162012-09-26 02:36:12 +00003189 case TemplateArgument::NullPtr:
3190 llvm_unreachable("Unexpected TemplateArgument");
Mike Stump1eb44332009-09-09 15:08:12 +00003191
Douglas Gregor670444e2009-08-04 22:27:00 +00003192 case TemplateArgument::Type: {
John McCalla93c9342009-12-07 02:54:59 +00003193 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall833ca992009-10-29 08:12:44 +00003194 if (DI == NULL)
John McCalla93c9342009-12-07 02:54:59 +00003195 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall833ca992009-10-29 08:12:44 +00003196
3197 DI = getDerived().TransformType(DI);
3198 if (!DI) return true;
3199
3200 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3201 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00003202 }
Mike Stump1eb44332009-09-09 15:08:12 +00003203
Douglas Gregor788cd062009-11-11 01:00:40 +00003204 case TemplateArgument::Template: {
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003205 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3206 if (QualifierLoc) {
3207 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3208 if (!QualifierLoc)
3209 return true;
3210 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003211
Douglas Gregor1d752d72011-03-02 18:46:51 +00003212 CXXScopeSpec SS;
3213 SS.Adopt(QualifierLoc);
Douglas Gregor788cd062009-11-11 01:00:40 +00003214 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00003215 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3216 Input.getTemplateNameLoc());
Douglas Gregor788cd062009-11-11 01:00:40 +00003217 if (Template.isNull())
3218 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003219
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003220 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor788cd062009-11-11 01:00:40 +00003221 Input.getTemplateNameLoc());
3222 return false;
3223 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00003224
3225 case TemplateArgument::TemplateExpansion:
3226 llvm_unreachable("Caller should expand pack expansions");
3227
Douglas Gregor670444e2009-08-04 22:27:00 +00003228 case TemplateArgument::Expression: {
Richard Smithf6702a32011-12-20 02:08:33 +00003229 // Template argument expressions are constant expressions.
Mike Stump1eb44332009-09-09 15:08:12 +00003230 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smithf6702a32011-12-20 02:08:33 +00003231 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003232
John McCall833ca992009-10-29 08:12:44 +00003233 Expr *InputExpr = Input.getSourceExpression();
3234 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3235
Chris Lattner223de242011-04-25 20:37:58 +00003236 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanac626012012-02-29 03:16:56 +00003237 E = SemaRef.ActOnConstantExpression(E);
John McCall833ca992009-10-29 08:12:44 +00003238 if (E.isInvalid()) return true;
John McCall9ae2f072010-08-23 23:25:46 +00003239 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall833ca992009-10-29 08:12:44 +00003240 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00003241 }
Douglas Gregor670444e2009-08-04 22:27:00 +00003242 }
Mike Stump1eb44332009-09-09 15:08:12 +00003243
Douglas Gregor670444e2009-08-04 22:27:00 +00003244 // Work around bogus GCC warning
John McCall833ca992009-10-29 08:12:44 +00003245 return true;
Douglas Gregor670444e2009-08-04 22:27:00 +00003246}
3247
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003248/// \brief Iterator adaptor that invents template argument location information
3249/// for each of the template arguments in its underlying iterator.
3250template<typename Derived, typename InputIterator>
3251class TemplateArgumentLocInventIterator {
3252 TreeTransform<Derived> &Self;
3253 InputIterator Iter;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003254
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003255public:
3256 typedef TemplateArgumentLoc value_type;
3257 typedef TemplateArgumentLoc reference;
3258 typedef typename std::iterator_traits<InputIterator>::difference_type
3259 difference_type;
3260 typedef std::input_iterator_tag iterator_category;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003261
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003262 class pointer {
3263 TemplateArgumentLoc Arg;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003264
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003265 public:
3266 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003267
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003268 const TemplateArgumentLoc *operator->() const { return &Arg; }
3269 };
Chad Rosier4a9d7952012-08-08 18:46:20 +00003270
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003271 TemplateArgumentLocInventIterator() { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003272
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003273 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3274 InputIterator Iter)
3275 : Self(Self), Iter(Iter) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003276
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003277 TemplateArgumentLocInventIterator &operator++() {
3278 ++Iter;
3279 return *this;
Douglas Gregorfcc12532010-12-20 17:31:10 +00003280 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003281
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003282 TemplateArgumentLocInventIterator operator++(int) {
3283 TemplateArgumentLocInventIterator Old(*this);
3284 ++(*this);
3285 return Old;
3286 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003287
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003288 reference operator*() const {
3289 TemplateArgumentLoc Result;
3290 Self.InventTemplateArgumentLoc(*Iter, Result);
3291 return Result;
3292 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003293
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003294 pointer operator->() const { return pointer(**this); }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003295
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003296 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3297 const TemplateArgumentLocInventIterator &Y) {
3298 return X.Iter == Y.Iter;
3299 }
Douglas Gregorfcc12532010-12-20 17:31:10 +00003300
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003301 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3302 const TemplateArgumentLocInventIterator &Y) {
3303 return X.Iter != Y.Iter;
3304 }
3305};
Chad Rosier4a9d7952012-08-08 18:46:20 +00003306
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003307template<typename Derived>
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003308template<typename InputIterator>
3309bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3310 InputIterator Last,
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003311 TemplateArgumentListInfo &Outputs) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003312 for (; First != Last; ++First) {
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003313 TemplateArgumentLoc Out;
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003314 TemplateArgumentLoc In = *First;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003315
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003316 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3317 // Unpack argument packs, which we translate them into separate
3318 // arguments.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003319 // FIXME: We could do much better if we could guarantee that the
3320 // TemplateArgumentLocInfo for the pack expansion would be usable for
3321 // all of the template arguments in the argument pack.
Chad Rosier4a9d7952012-08-08 18:46:20 +00003322 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003323 TemplateArgument::pack_iterator>
3324 PackLocIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003325 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003326 In.getArgument().pack_begin()),
3327 PackLocIterator(*this,
3328 In.getArgument().pack_end()),
3329 Outputs))
3330 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003331
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003332 continue;
3333 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003334
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003335 if (In.getArgument().isPackExpansion()) {
3336 // We have a pack expansion, for which we will be substituting into
3337 // the pattern.
3338 SourceLocation Ellipsis;
David Blaikiedc84cd52013-02-20 22:23:23 +00003339 Optional<unsigned> OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003340 TemplateArgumentLoc Pattern
Eli Friedman850cf512013-06-20 04:11:21 +00003341 = getSema().getTemplateArgumentPackExpansionPattern(
3342 In, Ellipsis, OrigNumExpansions);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003343
Chris Lattner686775d2011-07-20 06:58:45 +00003344 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003345 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3346 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier4a9d7952012-08-08 18:46:20 +00003347
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003348 // Determine whether the set of unexpanded parameter packs can and should
3349 // be expanded.
3350 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00003351 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00003352 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003353 if (getDerived().TryExpandParameterPacks(Ellipsis,
3354 Pattern.getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00003355 Unexpanded,
Chad Rosier4a9d7952012-08-08 18:46:20 +00003356 Expand,
Douglas Gregord3731192011-01-10 07:32:04 +00003357 RetainExpansion,
3358 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003359 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003360
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003361 if (!Expand) {
3362 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00003363 // transformation on the pack expansion, producing another pack
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003364 // expansion.
3365 TemplateArgumentLoc OutPattern;
3366 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3367 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3368 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003369
Douglas Gregorcded4f62011-01-14 17:04:44 +00003370 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3371 NumExpansions);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003372 if (Out.getArgument().isNull())
3373 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003374
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003375 Outputs.addArgument(Out);
3376 continue;
3377 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003378
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003379 // The transform has determined that we should perform an elementwise
3380 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00003381 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003382 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3383
3384 if (getDerived().TransformTemplateArgument(Pattern, Out))
3385 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003386
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003387 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregorcded4f62011-01-14 17:04:44 +00003388 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3389 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003390 if (Out.getArgument().isNull())
3391 return true;
3392 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003393
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003394 Outputs.addArgument(Out);
3395 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003396
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003397 // If we're supposed to retain a pack expansion, do so by temporarily
3398 // forgetting the partially-substituted parameter pack.
3399 if (RetainExpansion) {
3400 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003401
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003402 if (getDerived().TransformTemplateArgument(Pattern, Out))
3403 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003404
Douglas Gregorcded4f62011-01-14 17:04:44 +00003405 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3406 OrigNumExpansions);
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003407 if (Out.getArgument().isNull())
3408 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003409
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003410 Outputs.addArgument(Out);
3411 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003412
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003413 continue;
3414 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003415
3416 // The simple case:
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003417 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003418 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003419
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003420 Outputs.addArgument(Out);
3421 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003422
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003423 return false;
3424
3425}
3426
Douglas Gregor577f75a2009-08-04 16:50:30 +00003427//===----------------------------------------------------------------------===//
3428// Type transformation
3429//===----------------------------------------------------------------------===//
3430
3431template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003432QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00003433 if (getDerived().AlreadyTransformed(T))
3434 return T;
Mike Stump1eb44332009-09-09 15:08:12 +00003435
John McCalla2becad2009-10-21 00:40:46 +00003436 // Temporary workaround. All of these transformations should
3437 // eventually turn into transformations on TypeLocs.
Douglas Gregorc21c7e92011-01-25 19:13:18 +00003438 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3439 getDerived().getBaseLocation());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003440
John McCall43fed0d2010-11-12 08:19:04 +00003441 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall0953e762009-09-24 19:53:00 +00003442
John McCalla2becad2009-10-21 00:40:46 +00003443 if (!NewDI)
3444 return QualType();
3445
3446 return NewDI->getType();
3447}
3448
3449template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003450TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smithf6702a32011-12-20 02:08:33 +00003451 // Refine the base location to the type's location.
3452 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3453 getDerived().getBaseEntity());
John McCalla2becad2009-10-21 00:40:46 +00003454 if (getDerived().AlreadyTransformed(DI->getType()))
3455 return DI;
3456
3457 TypeLocBuilder TLB;
3458
3459 TypeLoc TL = DI->getTypeLoc();
3460 TLB.reserve(TL.getFullDataSize());
3461
John McCall43fed0d2010-11-12 08:19:04 +00003462 QualType Result = getDerived().TransformType(TLB, TL);
John McCalla2becad2009-10-21 00:40:46 +00003463 if (Result.isNull())
3464 return 0;
3465
John McCalla93c9342009-12-07 02:54:59 +00003466 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCalla2becad2009-10-21 00:40:46 +00003467}
3468
3469template<typename Derived>
3470QualType
John McCall43fed0d2010-11-12 08:19:04 +00003471TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003472 switch (T.getTypeLocClass()) {
3473#define ABSTRACT_TYPELOC(CLASS, PARENT)
David Blaikie39e6ab42013-02-18 22:06:02 +00003474#define TYPELOC(CLASS, PARENT) \
3475 case TypeLoc::CLASS: \
3476 return getDerived().Transform##CLASS##Type(TLB, \
3477 T.castAs<CLASS##TypeLoc>());
John McCalla2becad2009-10-21 00:40:46 +00003478#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +00003479 }
Mike Stump1eb44332009-09-09 15:08:12 +00003480
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00003481 llvm_unreachable("unhandled type loc!");
John McCalla2becad2009-10-21 00:40:46 +00003482}
3483
3484/// FIXME: By default, this routine adds type qualifiers only to types
3485/// that can have qualifiers, and silently suppresses those qualifiers
3486/// that are not permitted (e.g., qualifiers on reference or function
3487/// types). This is the right thing for template instantiation, but
3488/// probably not for other clients.
3489template<typename Derived>
3490QualType
3491TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003492 QualifiedTypeLoc T) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00003493 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCalla2becad2009-10-21 00:40:46 +00003494
John McCall43fed0d2010-11-12 08:19:04 +00003495 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCalla2becad2009-10-21 00:40:46 +00003496 if (Result.isNull())
3497 return QualType();
3498
3499 // Silently suppress qualifiers if the result type can't be qualified.
3500 // FIXME: this is the right thing for template instantiation, but
3501 // probably not for other clients.
3502 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregor577f75a2009-08-04 16:50:30 +00003503 return Result;
Mike Stump1eb44332009-09-09 15:08:12 +00003504
John McCallf85e1932011-06-15 23:02:42 +00003505 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore559ca12011-06-17 22:11:49 +00003506 // resulting type.
3507 if (Quals.hasObjCLifetime()) {
3508 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3509 Quals.removeObjCLifetime();
Douglas Gregor4020cae2011-06-17 23:16:24 +00003510 else if (Result.getObjCLifetime()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00003511 // Objective-C ARC:
Douglas Gregore559ca12011-06-17 22:11:49 +00003512 // A lifetime qualifier applied to a substituted template parameter
3513 // overrides the lifetime qualifier from the template argument.
Douglas Gregor92d13872013-01-17 23:59:28 +00003514 const AutoType *AutoTy;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003515 if (const SubstTemplateTypeParmType *SubstTypeParam
Douglas Gregore559ca12011-06-17 22:11:49 +00003516 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3517 QualType Replacement = SubstTypeParam->getReplacementType();
3518 Qualifiers Qs = Replacement.getQualifiers();
3519 Qs.removeObjCLifetime();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003520 Replacement
Douglas Gregore559ca12011-06-17 22:11:49 +00003521 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3522 Qs);
3523 Result = SemaRef.Context.getSubstTemplateTypeParmType(
Chad Rosier4a9d7952012-08-08 18:46:20 +00003524 SubstTypeParam->getReplacedParameter(),
Douglas Gregore559ca12011-06-17 22:11:49 +00003525 Replacement);
3526 TLB.TypeWasModifiedSafely(Result);
Douglas Gregor92d13872013-01-17 23:59:28 +00003527 } else if ((AutoTy = dyn_cast<AutoType>(Result)) && AutoTy->isDeduced()) {
3528 // 'auto' types behave the same way as template parameters.
3529 QualType Deduced = AutoTy->getDeducedType();
3530 Qualifiers Qs = Deduced.getQualifiers();
3531 Qs.removeObjCLifetime();
3532 Deduced = SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(),
3533 Qs);
Faisal Valifad9e132013-09-26 19:54:12 +00003534 Result = SemaRef.Context.getAutoType(Deduced, AutoTy->isDecltypeAuto(),
3535 AutoTy->isDependentType());
Douglas Gregor92d13872013-01-17 23:59:28 +00003536 TLB.TypeWasModifiedSafely(Result);
Douglas Gregore559ca12011-06-17 22:11:49 +00003537 } else {
Douglas Gregor4020cae2011-06-17 23:16:24 +00003538 // Otherwise, complain about the addition of a qualifier to an
3539 // already-qualified type.
Eli Friedman44ee0a72013-06-07 20:31:48 +00003540 SourceRange R = T.getUnqualifiedLoc().getSourceRange();
Argyrios Kyrtzidisb8b03132011-06-24 00:08:59 +00003541 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregor4020cae2011-06-17 23:16:24 +00003542 << Result << R;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003543
Douglas Gregore559ca12011-06-17 22:11:49 +00003544 Quals.removeObjCLifetime();
3545 }
3546 }
3547 }
John McCall28654742010-06-05 06:41:15 +00003548 if (!Quals.empty()) {
3549 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
Richard Smith9807a2e2013-03-27 23:36:39 +00003550 // BuildQualifiedType might not add qualifiers if they are invalid.
3551 if (Result.hasLocalQualifiers())
3552 TLB.push<QualifiedTypeLoc>(Result);
John McCall28654742010-06-05 06:41:15 +00003553 // No location information to preserve.
3554 }
John McCalla2becad2009-10-21 00:40:46 +00003555
3556 return Result;
3557}
3558
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003559template<typename Derived>
3560TypeLoc
3561TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3562 QualType ObjectType,
3563 NamedDecl *UnqualLookup,
3564 CXXScopeSpec &SS) {
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003565 QualType T = TL.getType();
3566 if (getDerived().AlreadyTransformed(T))
3567 return TL;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003568
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003569 TypeLocBuilder TLB;
3570 QualType Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003571
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003572 if (isa<TemplateSpecializationType>(T)) {
David Blaikie39e6ab42013-02-18 22:06:02 +00003573 TemplateSpecializationTypeLoc SpecTL =
3574 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003575
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003576 TemplateName Template =
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003577 getDerived().TransformTemplateName(SS,
3578 SpecTL.getTypePtr()->getTemplateName(),
3579 SpecTL.getTemplateNameLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003580 ObjectType, UnqualLookup);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003581 if (Template.isNull())
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003582 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003583
3584 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003585 Template);
3586 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie39e6ab42013-02-18 22:06:02 +00003587 DependentTemplateSpecializationTypeLoc SpecTL =
3588 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003589
Douglas Gregora88f09f2011-02-28 17:23:35 +00003590 TemplateName Template
Chad Rosier4a9d7952012-08-08 18:46:20 +00003591 = getDerived().RebuildTemplateName(SS,
3592 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00003593 SpecTL.getTemplateNameLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00003594 ObjectType, UnqualLookup);
Douglas Gregora88f09f2011-02-28 17:23:35 +00003595 if (Template.isNull())
3596 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003597
3598 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregora88f09f2011-02-28 17:23:35 +00003599 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003600 Template,
3601 SS);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003602 } else {
3603 // Nothing special needs to be done for these.
3604 Result = getDerived().TransformType(TLB, TL);
3605 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003606
3607 if (Result.isNull())
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003608 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003609
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003610 return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc();
3611}
3612
Douglas Gregorb71d8212011-03-02 18:32:08 +00003613template<typename Derived>
3614TypeSourceInfo *
3615TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3616 QualType ObjectType,
3617 NamedDecl *UnqualLookup,
3618 CXXScopeSpec &SS) {
3619 // FIXME: Painfully copy-paste from the above!
Chad Rosier4a9d7952012-08-08 18:46:20 +00003620
Douglas Gregorb71d8212011-03-02 18:32:08 +00003621 QualType T = TSInfo->getType();
3622 if (getDerived().AlreadyTransformed(T))
3623 return TSInfo;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003624
Douglas Gregorb71d8212011-03-02 18:32:08 +00003625 TypeLocBuilder TLB;
3626 QualType Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003627
Douglas Gregorb71d8212011-03-02 18:32:08 +00003628 TypeLoc TL = TSInfo->getTypeLoc();
3629 if (isa<TemplateSpecializationType>(T)) {
David Blaikie39e6ab42013-02-18 22:06:02 +00003630 TemplateSpecializationTypeLoc SpecTL =
3631 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003632
Douglas Gregorb71d8212011-03-02 18:32:08 +00003633 TemplateName Template
3634 = getDerived().TransformTemplateName(SS,
3635 SpecTL.getTypePtr()->getTemplateName(),
3636 SpecTL.getTemplateNameLoc(),
3637 ObjectType, UnqualLookup);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003638 if (Template.isNull())
Douglas Gregorb71d8212011-03-02 18:32:08 +00003639 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003640
3641 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregorb71d8212011-03-02 18:32:08 +00003642 Template);
3643 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie39e6ab42013-02-18 22:06:02 +00003644 DependentTemplateSpecializationTypeLoc SpecTL =
3645 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003646
Douglas Gregorb71d8212011-03-02 18:32:08 +00003647 TemplateName Template
Chad Rosier4a9d7952012-08-08 18:46:20 +00003648 = getDerived().RebuildTemplateName(SS,
3649 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00003650 SpecTL.getTemplateNameLoc(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00003651 ObjectType, UnqualLookup);
3652 if (Template.isNull())
3653 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003654
3655 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregorb71d8212011-03-02 18:32:08 +00003656 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003657 Template,
3658 SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00003659 } else {
3660 // Nothing special needs to be done for these.
3661 Result = getDerived().TransformType(TLB, TL);
3662 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003663
3664 if (Result.isNull())
Douglas Gregorb71d8212011-03-02 18:32:08 +00003665 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003666
Douglas Gregorb71d8212011-03-02 18:32:08 +00003667 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3668}
3669
John McCalla2becad2009-10-21 00:40:46 +00003670template <class TyLoc> static inline
3671QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3672 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3673 NewT.setNameLoc(T.getNameLoc());
3674 return T.getType();
3675}
3676
John McCalla2becad2009-10-21 00:40:46 +00003677template<typename Derived>
3678QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003679 BuiltinTypeLoc T) {
Douglas Gregorddf889a2010-01-18 18:04:31 +00003680 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3681 NewT.setBuiltinLoc(T.getBuiltinLoc());
3682 if (T.needsExtraLocalData())
3683 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3684 return T.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003685}
Mike Stump1eb44332009-09-09 15:08:12 +00003686
Douglas Gregor577f75a2009-08-04 16:50:30 +00003687template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003688QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003689 ComplexTypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003690 // FIXME: recurse?
3691 return TransformTypeSpecType(TLB, T);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003692}
Mike Stump1eb44332009-09-09 15:08:12 +00003693
Douglas Gregor577f75a2009-08-04 16:50:30 +00003694template<typename Derived>
Reid Kleckner12df2462013-06-24 17:51:48 +00003695QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
3696 DecayedTypeLoc TL) {
3697 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
3698 if (OriginalType.isNull())
3699 return QualType();
3700
3701 QualType Result = TL.getType();
3702 if (getDerived().AlwaysRebuild() ||
3703 OriginalType != TL.getOriginalLoc().getType())
3704 Result = SemaRef.Context.getDecayedType(OriginalType);
3705 TLB.push<DecayedTypeLoc>(Result);
3706 // Nothing to set for DecayedTypeLoc.
3707 return Result;
3708}
3709
3710template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003711QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003712 PointerTypeLoc TL) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00003713 QualType PointeeType
3714 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003715 if (PointeeType.isNull())
3716 return QualType();
3717
3718 QualType Result = TL.getType();
John McCallc12c5bb2010-05-15 11:32:37 +00003719 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00003720 // A dependent pointer type 'T *' has is being transformed such
3721 // that an Objective-C class type is being replaced for 'T'. The
3722 // resulting pointer type is an ObjCObjectPointerType, not a
3723 // PointerType.
John McCallc12c5bb2010-05-15 11:32:37 +00003724 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003725
John McCallc12c5bb2010-05-15 11:32:37 +00003726 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3727 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003728 return Result;
3729 }
John McCall43fed0d2010-11-12 08:19:04 +00003730
Douglas Gregor92e986e2010-04-22 16:44:27 +00003731 if (getDerived().AlwaysRebuild() ||
3732 PointeeType != TL.getPointeeLoc().getType()) {
3733 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3734 if (Result.isNull())
3735 return QualType();
3736 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003737
John McCallf85e1932011-06-15 23:02:42 +00003738 // Objective-C ARC can add lifetime qualifiers to the type that we're
3739 // pointing to.
3740 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003741
Douglas Gregor92e986e2010-04-22 16:44:27 +00003742 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3743 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003744 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003745}
Mike Stump1eb44332009-09-09 15:08:12 +00003746
3747template<typename Derived>
3748QualType
John McCalla2becad2009-10-21 00:40:46 +00003749TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003750 BlockPointerTypeLoc TL) {
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003751 QualType PointeeType
Chad Rosier4a9d7952012-08-08 18:46:20 +00003752 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3753 if (PointeeType.isNull())
3754 return QualType();
3755
3756 QualType Result = TL.getType();
3757 if (getDerived().AlwaysRebuild() ||
3758 PointeeType != TL.getPointeeLoc().getType()) {
3759 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003760 TL.getSigilLoc());
3761 if (Result.isNull())
3762 return QualType();
3763 }
3764
Douglas Gregor39968ad2010-04-22 16:50:51 +00003765 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003766 NewT.setSigilLoc(TL.getSigilLoc());
3767 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003768}
3769
John McCall85737a72009-10-30 00:06:24 +00003770/// Transforms a reference type. Note that somewhat paradoxically we
3771/// don't care whether the type itself is an l-value type or an r-value
3772/// type; we only care if the type was *written* as an l-value type
3773/// or an r-value type.
3774template<typename Derived>
3775QualType
3776TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003777 ReferenceTypeLoc TL) {
John McCall85737a72009-10-30 00:06:24 +00003778 const ReferenceType *T = TL.getTypePtr();
3779
3780 // Note that this works with the pointee-as-written.
3781 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3782 if (PointeeType.isNull())
3783 return QualType();
3784
3785 QualType Result = TL.getType();
3786 if (getDerived().AlwaysRebuild() ||
3787 PointeeType != T->getPointeeTypeAsWritten()) {
3788 Result = getDerived().RebuildReferenceType(PointeeType,
3789 T->isSpelledAsLValue(),
3790 TL.getSigilLoc());
3791 if (Result.isNull())
3792 return QualType();
3793 }
3794
John McCallf85e1932011-06-15 23:02:42 +00003795 // Objective-C ARC can add lifetime qualifiers to the type that we're
3796 // referring to.
3797 TLB.TypeWasModifiedSafely(
3798 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3799
John McCall85737a72009-10-30 00:06:24 +00003800 // r-value references can be rebuilt as l-value references.
3801 ReferenceTypeLoc NewTL;
3802 if (isa<LValueReferenceType>(Result))
3803 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3804 else
3805 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3806 NewTL.setSigilLoc(TL.getSigilLoc());
3807
3808 return Result;
3809}
3810
Mike Stump1eb44332009-09-09 15:08:12 +00003811template<typename Derived>
3812QualType
John McCalla2becad2009-10-21 00:40:46 +00003813TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003814 LValueReferenceTypeLoc TL) {
3815 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003816}
3817
Mike Stump1eb44332009-09-09 15:08:12 +00003818template<typename Derived>
3819QualType
John McCalla2becad2009-10-21 00:40:46 +00003820TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003821 RValueReferenceTypeLoc TL) {
3822 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003823}
Mike Stump1eb44332009-09-09 15:08:12 +00003824
Douglas Gregor577f75a2009-08-04 16:50:30 +00003825template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003826QualType
John McCalla2becad2009-10-21 00:40:46 +00003827TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003828 MemberPointerTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003829 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003830 if (PointeeType.isNull())
3831 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003832
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003833 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
3834 TypeSourceInfo* NewClsTInfo = 0;
3835 if (OldClsTInfo) {
3836 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3837 if (!NewClsTInfo)
3838 return QualType();
3839 }
3840
3841 const MemberPointerType *T = TL.getTypePtr();
3842 QualType OldClsType = QualType(T->getClass(), 0);
3843 QualType NewClsType;
3844 if (NewClsTInfo)
3845 NewClsType = NewClsTInfo->getType();
3846 else {
3847 NewClsType = getDerived().TransformType(OldClsType);
3848 if (NewClsType.isNull())
3849 return QualType();
3850 }
Mike Stump1eb44332009-09-09 15:08:12 +00003851
John McCalla2becad2009-10-21 00:40:46 +00003852 QualType Result = TL.getType();
3853 if (getDerived().AlwaysRebuild() ||
3854 PointeeType != T->getPointeeType() ||
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003855 NewClsType != OldClsType) {
3856 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall85737a72009-10-30 00:06:24 +00003857 TL.getStarLoc());
John McCalla2becad2009-10-21 00:40:46 +00003858 if (Result.isNull())
3859 return QualType();
3860 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00003861
John McCalla2becad2009-10-21 00:40:46 +00003862 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3863 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003864 NewTL.setClassTInfo(NewClsTInfo);
John McCalla2becad2009-10-21 00:40:46 +00003865
3866 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003867}
3868
Mike Stump1eb44332009-09-09 15:08:12 +00003869template<typename Derived>
3870QualType
John McCalla2becad2009-10-21 00:40:46 +00003871TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003872 ConstantArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003873 const ConstantArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003874 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003875 if (ElementType.isNull())
3876 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003877
John McCalla2becad2009-10-21 00:40:46 +00003878 QualType Result = TL.getType();
3879 if (getDerived().AlwaysRebuild() ||
3880 ElementType != T->getElementType()) {
3881 Result = getDerived().RebuildConstantArrayType(ElementType,
3882 T->getSizeModifier(),
3883 T->getSize(),
John McCall85737a72009-10-30 00:06:24 +00003884 T->getIndexTypeCVRQualifiers(),
3885 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003886 if (Result.isNull())
3887 return QualType();
3888 }
Eli Friedman457a3772012-01-25 22:19:07 +00003889
3890 // We might have either a ConstantArrayType or a VariableArrayType now:
3891 // a ConstantArrayType is allowed to have an element type which is a
3892 // VariableArrayType if the type is dependent. Fortunately, all array
3893 // types have the same location layout.
3894 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCalla2becad2009-10-21 00:40:46 +00003895 NewTL.setLBracketLoc(TL.getLBracketLoc());
3896 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003897
John McCalla2becad2009-10-21 00:40:46 +00003898 Expr *Size = TL.getSizeExpr();
3899 if (Size) {
Richard Smithf6702a32011-12-20 02:08:33 +00003900 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3901 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003902 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
Eli Friedmanac626012012-02-29 03:16:56 +00003903 Size = SemaRef.ActOnConstantExpression(Size).take();
John McCalla2becad2009-10-21 00:40:46 +00003904 }
3905 NewTL.setSizeExpr(Size);
3906
3907 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003908}
Mike Stump1eb44332009-09-09 15:08:12 +00003909
Douglas Gregor577f75a2009-08-04 16:50:30 +00003910template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003911QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCalla2becad2009-10-21 00:40:46 +00003912 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003913 IncompleteArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003914 const IncompleteArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003915 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003916 if (ElementType.isNull())
3917 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003918
John McCalla2becad2009-10-21 00:40:46 +00003919 QualType Result = TL.getType();
3920 if (getDerived().AlwaysRebuild() ||
3921 ElementType != T->getElementType()) {
3922 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00003923 T->getSizeModifier(),
John McCall85737a72009-10-30 00:06:24 +00003924 T->getIndexTypeCVRQualifiers(),
3925 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003926 if (Result.isNull())
3927 return QualType();
3928 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003929
John McCalla2becad2009-10-21 00:40:46 +00003930 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3931 NewTL.setLBracketLoc(TL.getLBracketLoc());
3932 NewTL.setRBracketLoc(TL.getRBracketLoc());
3933 NewTL.setSizeExpr(0);
3934
3935 return Result;
3936}
3937
3938template<typename Derived>
3939QualType
3940TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003941 VariableArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003942 const VariableArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003943 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3944 if (ElementType.isNull())
3945 return QualType();
3946
John McCall60d7b3a2010-08-24 06:29:42 +00003947 ExprResult SizeResult
John McCalla2becad2009-10-21 00:40:46 +00003948 = getDerived().TransformExpr(T->getSizeExpr());
3949 if (SizeResult.isInvalid())
3950 return QualType();
3951
John McCall9ae2f072010-08-23 23:25:46 +00003952 Expr *Size = SizeResult.take();
John McCalla2becad2009-10-21 00:40:46 +00003953
3954 QualType Result = TL.getType();
3955 if (getDerived().AlwaysRebuild() ||
3956 ElementType != T->getElementType() ||
3957 Size != T->getSizeExpr()) {
3958 Result = getDerived().RebuildVariableArrayType(ElementType,
3959 T->getSizeModifier(),
John McCall9ae2f072010-08-23 23:25:46 +00003960 Size,
John McCalla2becad2009-10-21 00:40:46 +00003961 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003962 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003963 if (Result.isNull())
3964 return QualType();
3965 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003966
John McCalla2becad2009-10-21 00:40:46 +00003967 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3968 NewTL.setLBracketLoc(TL.getLBracketLoc());
3969 NewTL.setRBracketLoc(TL.getRBracketLoc());
3970 NewTL.setSizeExpr(Size);
3971
3972 return Result;
3973}
3974
3975template<typename Derived>
3976QualType
3977TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003978 DependentSizedArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003979 const DependentSizedArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003980 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3981 if (ElementType.isNull())
3982 return QualType();
3983
Richard Smithf6702a32011-12-20 02:08:33 +00003984 // Array bounds are constant expressions.
3985 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3986 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003987
John McCall3b657512011-01-19 10:06:00 +00003988 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3989 Expr *origSize = TL.getSizeExpr();
3990 if (!origSize) origSize = T->getSizeExpr();
3991
3992 ExprResult sizeResult
3993 = getDerived().TransformExpr(origSize);
Eli Friedmanac626012012-02-29 03:16:56 +00003994 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall3b657512011-01-19 10:06:00 +00003995 if (sizeResult.isInvalid())
John McCalla2becad2009-10-21 00:40:46 +00003996 return QualType();
3997
John McCall3b657512011-01-19 10:06:00 +00003998 Expr *size = sizeResult.get();
John McCalla2becad2009-10-21 00:40:46 +00003999
4000 QualType Result = TL.getType();
4001 if (getDerived().AlwaysRebuild() ||
4002 ElementType != T->getElementType() ||
John McCall3b657512011-01-19 10:06:00 +00004003 size != origSize) {
John McCalla2becad2009-10-21 00:40:46 +00004004 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
4005 T->getSizeModifier(),
John McCall3b657512011-01-19 10:06:00 +00004006 size,
John McCalla2becad2009-10-21 00:40:46 +00004007 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00004008 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00004009 if (Result.isNull())
4010 return QualType();
4011 }
John McCalla2becad2009-10-21 00:40:46 +00004012
4013 // We might have any sort of array type now, but fortunately they
4014 // all have the same location layout.
4015 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4016 NewTL.setLBracketLoc(TL.getLBracketLoc());
4017 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall3b657512011-01-19 10:06:00 +00004018 NewTL.setSizeExpr(size);
John McCalla2becad2009-10-21 00:40:46 +00004019
4020 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004021}
Mike Stump1eb44332009-09-09 15:08:12 +00004022
4023template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00004024QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCalla2becad2009-10-21 00:40:46 +00004025 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004026 DependentSizedExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004027 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004028
4029 // FIXME: ext vector locs should be nested
Douglas Gregor577f75a2009-08-04 16:50:30 +00004030 QualType ElementType = getDerived().TransformType(T->getElementType());
4031 if (ElementType.isNull())
4032 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004033
Richard Smithf6702a32011-12-20 02:08:33 +00004034 // Vector sizes are constant expressions.
4035 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4036 Sema::ConstantEvaluated);
Douglas Gregor670444e2009-08-04 22:27:00 +00004037
John McCall60d7b3a2010-08-24 06:29:42 +00004038 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanac626012012-02-29 03:16:56 +00004039 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregor577f75a2009-08-04 16:50:30 +00004040 if (Size.isInvalid())
4041 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004042
John McCalla2becad2009-10-21 00:40:46 +00004043 QualType Result = TL.getType();
4044 if (getDerived().AlwaysRebuild() ||
John McCalleee91c32009-10-23 17:55:45 +00004045 ElementType != T->getElementType() ||
4046 Size.get() != T->getSizeExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00004047 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00004048 Size.take(),
Douglas Gregor577f75a2009-08-04 16:50:30 +00004049 T->getAttributeLoc());
John McCalla2becad2009-10-21 00:40:46 +00004050 if (Result.isNull())
4051 return QualType();
4052 }
John McCalla2becad2009-10-21 00:40:46 +00004053
4054 // Result might be dependent or not.
4055 if (isa<DependentSizedExtVectorType>(Result)) {
4056 DependentSizedExtVectorTypeLoc NewTL
4057 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
4058 NewTL.setNameLoc(TL.getNameLoc());
4059 } else {
4060 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4061 NewTL.setNameLoc(TL.getNameLoc());
4062 }
4063
4064 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004065}
Mike Stump1eb44332009-09-09 15:08:12 +00004066
4067template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004068QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004069 VectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004070 const VectorType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004071 QualType ElementType = getDerived().TransformType(T->getElementType());
4072 if (ElementType.isNull())
4073 return QualType();
4074
John McCalla2becad2009-10-21 00:40:46 +00004075 QualType Result = TL.getType();
4076 if (getDerived().AlwaysRebuild() ||
4077 ElementType != T->getElementType()) {
John Thompson82287d12010-02-05 00:12:22 +00004078 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsone86d78c2010-11-10 21:56:12 +00004079 T->getVectorKind());
John McCalla2becad2009-10-21 00:40:46 +00004080 if (Result.isNull())
4081 return QualType();
4082 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004083
John McCalla2becad2009-10-21 00:40:46 +00004084 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
4085 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00004086
John McCalla2becad2009-10-21 00:40:46 +00004087 return Result;
4088}
4089
4090template<typename Derived>
4091QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004092 ExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004093 const VectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004094 QualType ElementType = getDerived().TransformType(T->getElementType());
4095 if (ElementType.isNull())
4096 return QualType();
4097
4098 QualType Result = TL.getType();
4099 if (getDerived().AlwaysRebuild() ||
4100 ElementType != T->getElementType()) {
4101 Result = getDerived().RebuildExtVectorType(ElementType,
4102 T->getNumElements(),
4103 /*FIXME*/ SourceLocation());
4104 if (Result.isNull())
4105 return QualType();
4106 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004107
John McCalla2becad2009-10-21 00:40:46 +00004108 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4109 NewTL.setNameLoc(TL.getNameLoc());
4110
4111 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004112}
Mike Stump1eb44332009-09-09 15:08:12 +00004113
David Blaikiedc84cd52013-02-20 22:23:23 +00004114template <typename Derived>
4115ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
4116 ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
4117 bool ExpectParameterPack) {
John McCall21ef0fa2010-03-11 09:03:00 +00004118 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004119 TypeSourceInfo *NewDI = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004120
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004121 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004122 // If we're substituting into a pack expansion type and we know the
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004123 // length we want to expand to, just substitute for the pattern.
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004124 TypeLoc OldTL = OldDI->getTypeLoc();
David Blaikie39e6ab42013-02-18 22:06:02 +00004125 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004126
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004127 TypeLocBuilder TLB;
4128 TypeLoc NewTL = OldDI->getTypeLoc();
4129 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier4a9d7952012-08-08 18:46:20 +00004130
4131 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004132 OldExpansionTL.getPatternLoc());
4133 if (Result.isNull())
4134 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004135
4136 Result = RebuildPackExpansionType(Result,
4137 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004138 OldExpansionTL.getEllipsisLoc(),
4139 NumExpansions);
4140 if (Result.isNull())
4141 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004142
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004143 PackExpansionTypeLoc NewExpansionTL
4144 = TLB.push<PackExpansionTypeLoc>(Result);
4145 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
4146 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
4147 } else
4148 NewDI = getDerived().TransformType(OldDI);
John McCall21ef0fa2010-03-11 09:03:00 +00004149 if (!NewDI)
4150 return 0;
4151
John McCallfb44de92011-05-01 22:35:37 +00004152 if (NewDI == OldDI && indexAdjustment == 0)
John McCall21ef0fa2010-03-11 09:03:00 +00004153 return OldParm;
John McCallfb44de92011-05-01 22:35:37 +00004154
4155 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
4156 OldParm->getDeclContext(),
4157 OldParm->getInnerLocStart(),
4158 OldParm->getLocation(),
4159 OldParm->getIdentifier(),
4160 NewDI->getType(),
4161 NewDI,
4162 OldParm->getStorageClass(),
John McCallfb44de92011-05-01 22:35:37 +00004163 /* DefArg */ NULL);
4164 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
4165 OldParm->getFunctionScopeIndex() + indexAdjustment);
4166 return newParm;
John McCall21ef0fa2010-03-11 09:03:00 +00004167}
4168
4169template<typename Derived>
4170bool TreeTransform<Derived>::
Douglas Gregora009b592011-01-07 00:20:55 +00004171 TransformFunctionTypeParams(SourceLocation Loc,
4172 ParmVarDecl **Params, unsigned NumParams,
4173 const QualType *ParamTypes,
Chris Lattner686775d2011-07-20 06:58:45 +00004174 SmallVectorImpl<QualType> &OutParamTypes,
4175 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCallfb44de92011-05-01 22:35:37 +00004176 int indexAdjustment = 0;
4177
Douglas Gregora009b592011-01-07 00:20:55 +00004178 for (unsigned i = 0; i != NumParams; ++i) {
4179 if (ParmVarDecl *OldParm = Params[i]) {
John McCallfb44de92011-05-01 22:35:37 +00004180 assert(OldParm->getFunctionScopeIndex() == i);
4181
David Blaikiedc84cd52013-02-20 22:23:23 +00004182 Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004183 ParmVarDecl *NewParm = 0;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004184 if (OldParm->isParameterPack()) {
4185 // We have a function parameter pack that may need to be expanded.
Chris Lattner686775d2011-07-20 06:58:45 +00004186 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall21ef0fa2010-03-11 09:03:00 +00004187
Douglas Gregor603cfb42011-01-05 23:12:31 +00004188 // Find the parameter packs that could be expanded.
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00004189 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
David Blaikie39e6ab42013-02-18 22:06:02 +00004190 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00004191 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4192 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregor406f98f2011-03-02 02:04:06 +00004193 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4194
Douglas Gregor603cfb42011-01-05 23:12:31 +00004195 // Determine whether we should expand the parameter packs.
4196 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00004197 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00004198 Optional<unsigned> OrigNumExpansions =
4199 ExpansionTL.getTypePtr()->getNumExpansions();
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004200 NumExpansions = OrigNumExpansions;
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00004201 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4202 Pattern.getSourceRange(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004203 Unexpanded,
4204 ShouldExpand,
Douglas Gregord3731192011-01-10 07:32:04 +00004205 RetainExpansion,
4206 NumExpansions)) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004207 return true;
4208 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004209
Douglas Gregor603cfb42011-01-05 23:12:31 +00004210 if (ShouldExpand) {
4211 // Expand the function parameter pack into multiple, separate
4212 // parameters.
Douglas Gregor12c9c002011-01-07 16:43:16 +00004213 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregorcded4f62011-01-14 17:04:44 +00004214 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004215 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004216 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004217 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004218 indexAdjustment++,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004219 OrigNumExpansions,
4220 /*ExpectParameterPack=*/false);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004221 if (!NewParm)
4222 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004223
Douglas Gregora009b592011-01-07 00:20:55 +00004224 OutParamTypes.push_back(NewParm->getType());
4225 if (PVars)
4226 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004227 }
Douglas Gregord3731192011-01-10 07:32:04 +00004228
4229 // If we're supposed to retain a pack expansion, do so by temporarily
4230 // forgetting the partially-substituted parameter pack.
4231 if (RetainExpansion) {
4232 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier4a9d7952012-08-08 18:46:20 +00004233 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004234 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004235 indexAdjustment++,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004236 OrigNumExpansions,
4237 /*ExpectParameterPack=*/false);
Douglas Gregord3731192011-01-10 07:32:04 +00004238 if (!NewParm)
4239 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004240
Douglas Gregord3731192011-01-10 07:32:04 +00004241 OutParamTypes.push_back(NewParm->getType());
4242 if (PVars)
4243 PVars->push_back(NewParm);
4244 }
4245
John McCallfb44de92011-05-01 22:35:37 +00004246 // The next parameter should have the same adjustment as the
4247 // last thing we pushed, but we post-incremented indexAdjustment
4248 // on every push. Also, if we push nothing, the adjustment should
4249 // go down by one.
4250 indexAdjustment--;
4251
Douglas Gregor603cfb42011-01-05 23:12:31 +00004252 // We're done with the pack expansion.
4253 continue;
4254 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004255
4256 // We'll substitute the parameter now without expanding the pack
Douglas Gregor603cfb42011-01-05 23:12:31 +00004257 // expansion.
Douglas Gregor406f98f2011-03-02 02:04:06 +00004258 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4259 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004260 indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004261 NumExpansions,
4262 /*ExpectParameterPack=*/true);
Douglas Gregor406f98f2011-03-02 02:04:06 +00004263 } else {
David Blaikiedc84cd52013-02-20 22:23:23 +00004264 NewParm = getDerived().TransformFunctionTypeParam(
David Blaikie66874fb2013-02-21 01:47:18 +00004265 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004266 }
Douglas Gregor406f98f2011-03-02 02:04:06 +00004267
John McCall21ef0fa2010-03-11 09:03:00 +00004268 if (!NewParm)
4269 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004270
Douglas Gregora009b592011-01-07 00:20:55 +00004271 OutParamTypes.push_back(NewParm->getType());
4272 if (PVars)
4273 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004274 continue;
4275 }
John McCall21ef0fa2010-03-11 09:03:00 +00004276
4277 // Deal with the possibility that we don't have a parameter
4278 // declaration for this parameter.
Douglas Gregora009b592011-01-07 00:20:55 +00004279 QualType OldType = ParamTypes[i];
Douglas Gregor603cfb42011-01-05 23:12:31 +00004280 bool IsPackExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00004281 Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004282 QualType NewType;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004283 if (const PackExpansionType *Expansion
Douglas Gregor603cfb42011-01-05 23:12:31 +00004284 = dyn_cast<PackExpansionType>(OldType)) {
4285 // We have a function parameter pack that may need to be expanded.
4286 QualType Pattern = Expansion->getPattern();
Chris Lattner686775d2011-07-20 06:58:45 +00004287 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004288 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004289
Douglas Gregor603cfb42011-01-05 23:12:31 +00004290 // Determine whether we should expand the parameter packs.
4291 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00004292 bool RetainExpansion = false;
Douglas Gregora009b592011-01-07 00:20:55 +00004293 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004294 Unexpanded,
4295 ShouldExpand,
Douglas Gregord3731192011-01-10 07:32:04 +00004296 RetainExpansion,
4297 NumExpansions)) {
John McCall21ef0fa2010-03-11 09:03:00 +00004298 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004299 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004300
Douglas Gregor603cfb42011-01-05 23:12:31 +00004301 if (ShouldExpand) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004302 // Expand the function parameter pack into multiple, separate
Douglas Gregor603cfb42011-01-05 23:12:31 +00004303 // parameters.
Douglas Gregorcded4f62011-01-14 17:04:44 +00004304 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004305 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4306 QualType NewType = getDerived().TransformType(Pattern);
4307 if (NewType.isNull())
4308 return true;
John McCall21ef0fa2010-03-11 09:03:00 +00004309
Douglas Gregora009b592011-01-07 00:20:55 +00004310 OutParamTypes.push_back(NewType);
4311 if (PVars)
4312 PVars->push_back(0);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004313 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004314
Douglas Gregor603cfb42011-01-05 23:12:31 +00004315 // We're done with the pack expansion.
4316 continue;
4317 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004318
Douglas Gregor3cae5c92011-01-10 20:53:55 +00004319 // If we're supposed to retain a pack expansion, do so by temporarily
4320 // forgetting the partially-substituted parameter pack.
4321 if (RetainExpansion) {
4322 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4323 QualType NewType = getDerived().TransformType(Pattern);
4324 if (NewType.isNull())
4325 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004326
Douglas Gregor3cae5c92011-01-10 20:53:55 +00004327 OutParamTypes.push_back(NewType);
4328 if (PVars)
4329 PVars->push_back(0);
4330 }
Douglas Gregord3731192011-01-10 07:32:04 +00004331
Chad Rosier4a9d7952012-08-08 18:46:20 +00004332 // We'll substitute the parameter now without expanding the pack
Douglas Gregor603cfb42011-01-05 23:12:31 +00004333 // expansion.
4334 OldType = Expansion->getPattern();
4335 IsPackExpansion = true;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004336 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4337 NewType = getDerived().TransformType(OldType);
4338 } else {
4339 NewType = getDerived().TransformType(OldType);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004340 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004341
Douglas Gregor603cfb42011-01-05 23:12:31 +00004342 if (NewType.isNull())
4343 return true;
4344
4345 if (IsPackExpansion)
Douglas Gregorcded4f62011-01-14 17:04:44 +00004346 NewType = getSema().Context.getPackExpansionType(NewType,
4347 NumExpansions);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004348
Douglas Gregora009b592011-01-07 00:20:55 +00004349 OutParamTypes.push_back(NewType);
4350 if (PVars)
4351 PVars->push_back(0);
John McCall21ef0fa2010-03-11 09:03:00 +00004352 }
4353
John McCallfb44de92011-05-01 22:35:37 +00004354#ifndef NDEBUG
4355 if (PVars) {
4356 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4357 if (ParmVarDecl *parm = (*PVars)[i])
4358 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004359 }
John McCallfb44de92011-05-01 22:35:37 +00004360#endif
4361
4362 return false;
4363}
John McCall21ef0fa2010-03-11 09:03:00 +00004364
4365template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004366QualType
John McCalla2becad2009-10-21 00:40:46 +00004367TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004368 FunctionProtoTypeLoc TL) {
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004369 return getDerived().TransformFunctionProtoType(TLB, TL, 0, 0);
4370}
4371
4372template<typename Derived>
4373QualType
4374TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
4375 FunctionProtoTypeLoc TL,
4376 CXXRecordDecl *ThisContext,
4377 unsigned ThisTypeQuals) {
Douglas Gregor7e010a02010-08-31 00:26:14 +00004378 // Transform the parameters and return type.
4379 //
Richard Smithe6975e92012-04-17 00:58:00 +00004380 // We are required to instantiate the params and return type in source order.
Douglas Gregordab60ad2010-10-01 18:44:50 +00004381 // When the function has a trailing return type, we instantiate the
4382 // parameters before the return type, since the return type can then refer
4383 // to the parameters themselves (via decltype, sizeof, etc.).
4384 //
Chris Lattner686775d2011-07-20 06:58:45 +00004385 SmallVector<QualType, 4> ParamTypes;
4386 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCallf4c73712011-01-19 06:33:43 +00004387 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor7e010a02010-08-31 00:26:14 +00004388
Douglas Gregordab60ad2010-10-01 18:44:50 +00004389 QualType ResultType;
4390
Richard Smith9fbf3272012-08-14 22:51:13 +00004391 if (T->hasTrailingReturn()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004392 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
Douglas Gregora009b592011-01-07 00:20:55 +00004393 TL.getParmArray(),
4394 TL.getNumArgs(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004395 TL.getTypePtr()->arg_type_begin(),
Douglas Gregora009b592011-01-07 00:20:55 +00004396 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004397 return QualType();
4398
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004399 {
4400 // C++11 [expr.prim.general]p3:
Chad Rosier4a9d7952012-08-08 18:46:20 +00004401 // If a declaration declares a member function or member function
4402 // template of a class X, the expression this is a prvalue of type
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004403 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier4a9d7952012-08-08 18:46:20 +00004404 // and the end of the function-definition, member-declarator, or
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004405 // declarator.
4406 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004407
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004408 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4409 if (ResultType.isNull())
4410 return QualType();
4411 }
Douglas Gregordab60ad2010-10-01 18:44:50 +00004412 }
4413 else {
4414 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4415 if (ResultType.isNull())
4416 return QualType();
4417
Chad Rosier4a9d7952012-08-08 18:46:20 +00004418 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
Douglas Gregora009b592011-01-07 00:20:55 +00004419 TL.getParmArray(),
4420 TL.getNumArgs(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004421 TL.getTypePtr()->arg_type_begin(),
Douglas Gregora009b592011-01-07 00:20:55 +00004422 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004423 return QualType();
4424 }
4425
Richard Smithe6975e92012-04-17 00:58:00 +00004426 // FIXME: Need to transform the exception-specification too.
4427
John McCalla2becad2009-10-21 00:40:46 +00004428 QualType Result = TL.getType();
4429 if (getDerived().AlwaysRebuild() ||
4430 ResultType != T->getResultType() ||
Douglas Gregorbd5f9f72011-01-07 19:27:47 +00004431 T->getNumArgs() != ParamTypes.size() ||
John McCalla2becad2009-10-21 00:40:46 +00004432 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
Jordan Rosebea522f2013-03-08 21:51:21 +00004433 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes,
Jordan Rose09189892013-03-08 22:25:36 +00004434 T->getExtProtoInfo());
John McCalla2becad2009-10-21 00:40:46 +00004435 if (Result.isNull())
4436 return QualType();
4437 }
Mike Stump1eb44332009-09-09 15:08:12 +00004438
John McCalla2becad2009-10-21 00:40:46 +00004439 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004440 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnara59c0a812012-10-04 21:42:10 +00004441 NewTL.setLParenLoc(TL.getLParenLoc());
4442 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnara796aa442011-03-12 11:17:06 +00004443 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCalla2becad2009-10-21 00:40:46 +00004444 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
4445 NewTL.setArg(i, ParamDecls[i]);
4446
4447 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004448}
Mike Stump1eb44332009-09-09 15:08:12 +00004449
Douglas Gregor577f75a2009-08-04 16:50:30 +00004450template<typename Derived>
4451QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCalla2becad2009-10-21 00:40:46 +00004452 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004453 FunctionNoProtoTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004454 const FunctionNoProtoType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004455 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4456 if (ResultType.isNull())
4457 return QualType();
4458
4459 QualType Result = TL.getType();
4460 if (getDerived().AlwaysRebuild() ||
4461 ResultType != T->getResultType())
4462 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4463
4464 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004465 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnara59c0a812012-10-04 21:42:10 +00004466 NewTL.setLParenLoc(TL.getLParenLoc());
4467 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnara796aa442011-03-12 11:17:06 +00004468 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCalla2becad2009-10-21 00:40:46 +00004469
4470 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004471}
Mike Stump1eb44332009-09-09 15:08:12 +00004472
John McCalled976492009-12-04 22:46:56 +00004473template<typename Derived> QualType
4474TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004475 UnresolvedUsingTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004476 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004477 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCalled976492009-12-04 22:46:56 +00004478 if (!D)
4479 return QualType();
4480
4481 QualType Result = TL.getType();
4482 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4483 Result = getDerived().RebuildUnresolvedUsingType(D);
4484 if (Result.isNull())
4485 return QualType();
4486 }
4487
4488 // We might get an arbitrary type spec type back. We should at
4489 // least always get a type spec type, though.
4490 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4491 NewTL.setNameLoc(TL.getNameLoc());
4492
4493 return Result;
4494}
4495
Douglas Gregor577f75a2009-08-04 16:50:30 +00004496template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004497QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004498 TypedefTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004499 const TypedefType *T = TL.getTypePtr();
Richard Smith162e1c12011-04-15 14:24:37 +00004500 TypedefNameDecl *Typedef
4501 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4502 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004503 if (!Typedef)
4504 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004505
John McCalla2becad2009-10-21 00:40:46 +00004506 QualType Result = TL.getType();
4507 if (getDerived().AlwaysRebuild() ||
4508 Typedef != T->getDecl()) {
4509 Result = getDerived().RebuildTypedefType(Typedef);
4510 if (Result.isNull())
4511 return QualType();
4512 }
Mike Stump1eb44332009-09-09 15:08:12 +00004513
John McCalla2becad2009-10-21 00:40:46 +00004514 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4515 NewTL.setNameLoc(TL.getNameLoc());
4516
4517 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004518}
Mike Stump1eb44332009-09-09 15:08:12 +00004519
Douglas Gregor577f75a2009-08-04 16:50:30 +00004520template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004521QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004522 TypeOfExprTypeLoc TL) {
Douglas Gregor670444e2009-08-04 22:27:00 +00004523 // typeof expressions are not potentially evaluated contexts
Eli Friedman80bfa3d2012-09-26 04:34:21 +00004524 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4525 Sema::ReuseLambdaContextDecl);
Mike Stump1eb44332009-09-09 15:08:12 +00004526
John McCall60d7b3a2010-08-24 06:29:42 +00004527 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004528 if (E.isInvalid())
4529 return QualType();
4530
Eli Friedman72b8b1e2012-02-29 04:03:55 +00004531 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
4532 if (E.isInvalid())
4533 return QualType();
4534
John McCalla2becad2009-10-21 00:40:46 +00004535 QualType Result = TL.getType();
4536 if (getDerived().AlwaysRebuild() ||
John McCallcfb708c2010-01-13 20:03:27 +00004537 E.get() != TL.getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004538 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCalla2becad2009-10-21 00:40:46 +00004539 if (Result.isNull())
4540 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004541 }
John McCalla2becad2009-10-21 00:40:46 +00004542 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004543
John McCalla2becad2009-10-21 00:40:46 +00004544 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004545 NewTL.setTypeofLoc(TL.getTypeofLoc());
4546 NewTL.setLParenLoc(TL.getLParenLoc());
4547 NewTL.setRParenLoc(TL.getRParenLoc());
John McCalla2becad2009-10-21 00:40:46 +00004548
4549 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004550}
Mike Stump1eb44332009-09-09 15:08:12 +00004551
4552template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004553QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004554 TypeOfTypeLoc TL) {
John McCallcfb708c2010-01-13 20:03:27 +00004555 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4556 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4557 if (!New_Under_TI)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004558 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004559
John McCalla2becad2009-10-21 00:40:46 +00004560 QualType Result = TL.getType();
John McCallcfb708c2010-01-13 20:03:27 +00004561 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4562 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCalla2becad2009-10-21 00:40:46 +00004563 if (Result.isNull())
4564 return QualType();
4565 }
Mike Stump1eb44332009-09-09 15:08:12 +00004566
John McCalla2becad2009-10-21 00:40:46 +00004567 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004568 NewTL.setTypeofLoc(TL.getTypeofLoc());
4569 NewTL.setLParenLoc(TL.getLParenLoc());
4570 NewTL.setRParenLoc(TL.getRParenLoc());
4571 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCalla2becad2009-10-21 00:40:46 +00004572
4573 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004574}
Mike Stump1eb44332009-09-09 15:08:12 +00004575
4576template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004577QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004578 DecltypeTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004579 const DecltypeType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004580
Douglas Gregor670444e2009-08-04 22:27:00 +00004581 // decltype expressions are not potentially evaluated contexts
Richard Smith76f3f692012-02-22 02:04:18 +00004582 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, 0,
4583 /*IsDecltype=*/ true);
Mike Stump1eb44332009-09-09 15:08:12 +00004584
John McCall60d7b3a2010-08-24 06:29:42 +00004585 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004586 if (E.isInvalid())
4587 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004588
Richard Smith76f3f692012-02-22 02:04:18 +00004589 E = getSema().ActOnDecltypeExpression(E.take());
4590 if (E.isInvalid())
4591 return QualType();
4592
John McCalla2becad2009-10-21 00:40:46 +00004593 QualType Result = TL.getType();
4594 if (getDerived().AlwaysRebuild() ||
4595 E.get() != T->getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004596 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004597 if (Result.isNull())
4598 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004599 }
John McCalla2becad2009-10-21 00:40:46 +00004600 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004601
John McCalla2becad2009-10-21 00:40:46 +00004602 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4603 NewTL.setNameLoc(TL.getNameLoc());
4604
4605 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004606}
4607
4608template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00004609QualType TreeTransform<Derived>::TransformUnaryTransformType(
4610 TypeLocBuilder &TLB,
4611 UnaryTransformTypeLoc TL) {
4612 QualType Result = TL.getType();
4613 if (Result->isDependentType()) {
4614 const UnaryTransformType *T = TL.getTypePtr();
4615 QualType NewBase =
4616 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4617 Result = getDerived().RebuildUnaryTransformType(NewBase,
4618 T->getUTTKind(),
4619 TL.getKWLoc());
4620 if (Result.isNull())
4621 return QualType();
4622 }
4623
4624 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4625 NewTL.setKWLoc(TL.getKWLoc());
4626 NewTL.setParensRange(TL.getParensRange());
4627 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4628 return Result;
4629}
4630
4631template<typename Derived>
Richard Smith34b41d92011-02-20 03:19:35 +00004632QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4633 AutoTypeLoc TL) {
4634 const AutoType *T = TL.getTypePtr();
4635 QualType OldDeduced = T->getDeducedType();
4636 QualType NewDeduced;
4637 if (!OldDeduced.isNull()) {
4638 NewDeduced = getDerived().TransformType(OldDeduced);
4639 if (NewDeduced.isNull())
4640 return QualType();
4641 }
4642
4643 QualType Result = TL.getType();
Richard Smithdc7a4f52013-04-30 13:56:41 +00004644 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
4645 T->isDependentType()) {
Richard Smitha2c36462013-04-26 16:15:35 +00004646 Result = getDerived().RebuildAutoType(NewDeduced, T->isDecltypeAuto());
Richard Smith34b41d92011-02-20 03:19:35 +00004647 if (Result.isNull())
4648 return QualType();
4649 }
4650
4651 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4652 NewTL.setNameLoc(TL.getNameLoc());
4653
4654 return Result;
4655}
4656
4657template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004658QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004659 RecordTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004660 const RecordType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004661 RecordDecl *Record
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004662 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4663 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004664 if (!Record)
4665 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004666
John McCalla2becad2009-10-21 00:40:46 +00004667 QualType Result = TL.getType();
4668 if (getDerived().AlwaysRebuild() ||
4669 Record != T->getDecl()) {
4670 Result = getDerived().RebuildRecordType(Record);
4671 if (Result.isNull())
4672 return QualType();
4673 }
Mike Stump1eb44332009-09-09 15:08:12 +00004674
John McCalla2becad2009-10-21 00:40:46 +00004675 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4676 NewTL.setNameLoc(TL.getNameLoc());
4677
4678 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004679}
Mike Stump1eb44332009-09-09 15:08:12 +00004680
4681template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004682QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004683 EnumTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004684 const EnumType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004685 EnumDecl *Enum
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004686 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4687 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004688 if (!Enum)
4689 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004690
John McCalla2becad2009-10-21 00:40:46 +00004691 QualType Result = TL.getType();
4692 if (getDerived().AlwaysRebuild() ||
4693 Enum != T->getDecl()) {
4694 Result = getDerived().RebuildEnumType(Enum);
4695 if (Result.isNull())
4696 return QualType();
4697 }
Mike Stump1eb44332009-09-09 15:08:12 +00004698
John McCalla2becad2009-10-21 00:40:46 +00004699 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4700 NewTL.setNameLoc(TL.getNameLoc());
4701
4702 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004703}
John McCall7da24312009-09-05 00:15:47 +00004704
John McCall3cb0ebd2010-03-10 03:28:59 +00004705template<typename Derived>
4706QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4707 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004708 InjectedClassNameTypeLoc TL) {
John McCall3cb0ebd2010-03-10 03:28:59 +00004709 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4710 TL.getTypePtr()->getDecl());
4711 if (!D) return QualType();
4712
4713 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4714 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4715 return T;
4716}
4717
Douglas Gregor577f75a2009-08-04 16:50:30 +00004718template<typename Derived>
4719QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004720 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004721 TemplateTypeParmTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00004722 return TransformTypeSpecType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00004723}
4724
Mike Stump1eb44332009-09-09 15:08:12 +00004725template<typename Derived>
John McCall49a832b2009-10-18 09:09:24 +00004726QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004727 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004728 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004729 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004730
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004731 // Substitute into the replacement type, which itself might involve something
4732 // that needs to be transformed. This only tends to occur with default
4733 // template arguments of template template parameters.
4734 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4735 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4736 if (Replacement.isNull())
4737 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004738
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004739 // Always canonicalize the replacement type.
4740 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4741 QualType Result
Chad Rosier4a9d7952012-08-08 18:46:20 +00004742 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004743 Replacement);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004744
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004745 // Propagate type-source information.
4746 SubstTemplateTypeParmTypeLoc NewTL
4747 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4748 NewTL.setNameLoc(TL.getNameLoc());
4749 return Result;
4750
John McCall49a832b2009-10-18 09:09:24 +00004751}
4752
4753template<typename Derived>
Douglas Gregorc3069d62011-01-14 02:55:32 +00004754QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4755 TypeLocBuilder &TLB,
4756 SubstTemplateTypeParmPackTypeLoc TL) {
4757 return TransformTypeSpecType(TLB, TL);
4758}
4759
4760template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00004761QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00004762 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004763 TemplateSpecializationTypeLoc TL) {
John McCall833ca992009-10-29 08:12:44 +00004764 const TemplateSpecializationType *T = TL.getTypePtr();
4765
Douglas Gregor1d752d72011-03-02 18:46:51 +00004766 // The nested-name-specifier never matters in a TemplateSpecializationType,
4767 // because we can't have a dependent nested-name-specifier anyway.
4768 CXXScopeSpec SS;
Mike Stump1eb44332009-09-09 15:08:12 +00004769 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00004770 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4771 TL.getTemplateNameLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004772 if (Template.isNull())
4773 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004774
John McCall43fed0d2010-11-12 08:19:04 +00004775 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4776}
4777
Eli Friedmanb001de72011-10-06 23:00:33 +00004778template<typename Derived>
4779QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
4780 AtomicTypeLoc TL) {
4781 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
4782 if (ValueType.isNull())
4783 return QualType();
4784
4785 QualType Result = TL.getType();
4786 if (getDerived().AlwaysRebuild() ||
4787 ValueType != TL.getValueLoc().getType()) {
4788 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
4789 if (Result.isNull())
4790 return QualType();
4791 }
4792
4793 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
4794 NewTL.setKWLoc(TL.getKWLoc());
4795 NewTL.setLParenLoc(TL.getLParenLoc());
4796 NewTL.setRParenLoc(TL.getRParenLoc());
4797
4798 return Result;
4799}
4800
Chad Rosier4a9d7952012-08-08 18:46:20 +00004801 /// \brief Simple iterator that traverses the template arguments in a
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004802 /// container that provides a \c getArgLoc() member function.
4803 ///
4804 /// This iterator is intended to be used with the iterator form of
4805 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4806 template<typename ArgLocContainer>
4807 class TemplateArgumentLocContainerIterator {
4808 ArgLocContainer *Container;
4809 unsigned Index;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004810
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004811 public:
4812 typedef TemplateArgumentLoc value_type;
4813 typedef TemplateArgumentLoc reference;
4814 typedef int difference_type;
4815 typedef std::input_iterator_tag iterator_category;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004816
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004817 class pointer {
4818 TemplateArgumentLoc Arg;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004819
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004820 public:
4821 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004822
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004823 const TemplateArgumentLoc *operator->() const {
4824 return &Arg;
4825 }
4826 };
Chad Rosier4a9d7952012-08-08 18:46:20 +00004827
4828
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004829 TemplateArgumentLocContainerIterator() {}
Chad Rosier4a9d7952012-08-08 18:46:20 +00004830
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004831 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4832 unsigned Index)
4833 : Container(&Container), Index(Index) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004834
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004835 TemplateArgumentLocContainerIterator &operator++() {
4836 ++Index;
4837 return *this;
4838 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004839
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004840 TemplateArgumentLocContainerIterator operator++(int) {
4841 TemplateArgumentLocContainerIterator Old(*this);
4842 ++(*this);
4843 return Old;
4844 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004845
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004846 TemplateArgumentLoc operator*() const {
4847 return Container->getArgLoc(Index);
4848 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004849
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004850 pointer operator->() const {
4851 return pointer(Container->getArgLoc(Index));
4852 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004853
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004854 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004855 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004856 return X.Container == Y.Container && X.Index == Y.Index;
4857 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004858
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004859 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004860 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004861 return !(X == Y);
4862 }
4863 };
Chad Rosier4a9d7952012-08-08 18:46:20 +00004864
4865
John McCall43fed0d2010-11-12 08:19:04 +00004866template <typename Derived>
4867QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4868 TypeLocBuilder &TLB,
4869 TemplateSpecializationTypeLoc TL,
4870 TemplateName Template) {
John McCalld5532b62009-11-23 01:53:49 +00004871 TemplateArgumentListInfo NewTemplateArgs;
4872 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4873 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004874 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4875 ArgIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004876 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004877 ArgIterator(TL, TL.getNumArgs()),
4878 NewTemplateArgs))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00004879 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004880
John McCall833ca992009-10-29 08:12:44 +00004881 // FIXME: maybe don't rebuild if all the template arguments are the same.
4882
4883 QualType Result =
4884 getDerived().RebuildTemplateSpecializationType(Template,
4885 TL.getTemplateNameLoc(),
John McCalld5532b62009-11-23 01:53:49 +00004886 NewTemplateArgs);
John McCall833ca992009-10-29 08:12:44 +00004887
4888 if (!Result.isNull()) {
Richard Smith3e4c6c42011-05-05 21:57:07 +00004889 // Specializations of template template parameters are represented as
4890 // TemplateSpecializationTypes, and substitution of type alias templates
4891 // within a dependent context can transform them into
4892 // DependentTemplateSpecializationTypes.
4893 if (isa<DependentTemplateSpecializationType>(Result)) {
4894 DependentTemplateSpecializationTypeLoc NewTL
4895 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004896 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3e4c6c42011-05-05 21:57:07 +00004897 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnara66581d42012-02-06 22:45:07 +00004898 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004899 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3e4c6c42011-05-05 21:57:07 +00004900 NewTL.setLAngleLoc(TL.getLAngleLoc());
4901 NewTL.setRAngleLoc(TL.getRAngleLoc());
4902 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4903 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4904 return Result;
4905 }
4906
John McCall833ca992009-10-29 08:12:44 +00004907 TemplateSpecializationTypeLoc NewTL
4908 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004909 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall833ca992009-10-29 08:12:44 +00004910 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4911 NewTL.setLAngleLoc(TL.getLAngleLoc());
4912 NewTL.setRAngleLoc(TL.getRAngleLoc());
4913 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4914 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004915 }
Mike Stump1eb44332009-09-09 15:08:12 +00004916
John McCall833ca992009-10-29 08:12:44 +00004917 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004918}
Mike Stump1eb44332009-09-09 15:08:12 +00004919
Douglas Gregora88f09f2011-02-28 17:23:35 +00004920template <typename Derived>
4921QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4922 TypeLocBuilder &TLB,
4923 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00004924 TemplateName Template,
4925 CXXScopeSpec &SS) {
Douglas Gregora88f09f2011-02-28 17:23:35 +00004926 TemplateArgumentListInfo NewTemplateArgs;
4927 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4928 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4929 typedef TemplateArgumentLocContainerIterator<
4930 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004931 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregora88f09f2011-02-28 17:23:35 +00004932 ArgIterator(TL, TL.getNumArgs()),
4933 NewTemplateArgs))
4934 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004935
Douglas Gregora88f09f2011-02-28 17:23:35 +00004936 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier4a9d7952012-08-08 18:46:20 +00004937
Douglas Gregora88f09f2011-02-28 17:23:35 +00004938 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4939 QualType Result
4940 = getSema().Context.getDependentTemplateSpecializationType(
4941 TL.getTypePtr()->getKeyword(),
4942 DTN->getQualifier(),
4943 DTN->getIdentifier(),
4944 NewTemplateArgs);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004945
Douglas Gregora88f09f2011-02-28 17:23:35 +00004946 DependentTemplateSpecializationTypeLoc NewTL
4947 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004948 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004949 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnara66581d42012-02-06 22:45:07 +00004950 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004951 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora88f09f2011-02-28 17:23:35 +00004952 NewTL.setLAngleLoc(TL.getLAngleLoc());
4953 NewTL.setRAngleLoc(TL.getRAngleLoc());
4954 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4955 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4956 return Result;
4957 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004958
4959 QualType Result
Douglas Gregora88f09f2011-02-28 17:23:35 +00004960 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004961 TL.getTemplateNameLoc(),
Douglas Gregora88f09f2011-02-28 17:23:35 +00004962 NewTemplateArgs);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004963
Douglas Gregora88f09f2011-02-28 17:23:35 +00004964 if (!Result.isNull()) {
4965 /// FIXME: Wrap this in an elaborated-type-specifier?
4966 TemplateSpecializationTypeLoc NewTL
4967 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara66581d42012-02-06 22:45:07 +00004968 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004969 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora88f09f2011-02-28 17:23:35 +00004970 NewTL.setLAngleLoc(TL.getLAngleLoc());
4971 NewTL.setRAngleLoc(TL.getRAngleLoc());
4972 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4973 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4974 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004975
Douglas Gregora88f09f2011-02-28 17:23:35 +00004976 return Result;
4977}
4978
Mike Stump1eb44332009-09-09 15:08:12 +00004979template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004980QualType
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004981TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004982 ElaboratedTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004983 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004984
Douglas Gregor9e876872011-03-01 18:12:44 +00004985 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004986 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor9e876872011-03-01 18:12:44 +00004987 if (TL.getQualifierLoc()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004988 QualifierLoc
Douglas Gregor9e876872011-03-01 18:12:44 +00004989 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4990 if (!QualifierLoc)
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004991 return QualType();
4992 }
Mike Stump1eb44332009-09-09 15:08:12 +00004993
John McCall43fed0d2010-11-12 08:19:04 +00004994 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4995 if (NamedT.isNull())
4996 return QualType();
Daniel Dunbara63db842010-05-14 16:34:09 +00004997
Richard Smith3e4c6c42011-05-05 21:57:07 +00004998 // C++0x [dcl.type.elab]p2:
4999 // If the identifier resolves to a typedef-name or the simple-template-id
5000 // resolves to an alias template specialization, the
5001 // elaborated-type-specifier is ill-formed.
Richard Smith18041742011-05-14 15:04:18 +00005002 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
5003 if (const TemplateSpecializationType *TST =
5004 NamedT->getAs<TemplateSpecializationType>()) {
5005 TemplateName Template = TST->getTemplateName();
5006 if (TypeAliasTemplateDecl *TAT =
5007 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
5008 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
5009 diag::err_tag_reference_non_tag) << 4;
5010 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
5011 }
Richard Smith3e4c6c42011-05-05 21:57:07 +00005012 }
5013 }
5014
John McCalla2becad2009-10-21 00:40:46 +00005015 QualType Result = TL.getType();
5016 if (getDerived().AlwaysRebuild() ||
Douglas Gregor9e876872011-03-01 18:12:44 +00005017 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00005018 NamedT != T->getNamedType()) {
Abramo Bagnara38a42912012-02-06 19:09:27 +00005019 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00005020 T->getKeyword(),
Douglas Gregor9e876872011-03-01 18:12:44 +00005021 QualifierLoc, NamedT);
John McCalla2becad2009-10-21 00:40:46 +00005022 if (Result.isNull())
5023 return QualType();
5024 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00005025
Abramo Bagnara465d41b2010-05-11 21:36:43 +00005026 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00005027 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00005028 NewTL.setQualifierLoc(QualifierLoc);
John McCalla2becad2009-10-21 00:40:46 +00005029 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00005030}
Mike Stump1eb44332009-09-09 15:08:12 +00005031
5032template<typename Derived>
John McCall9d156a72011-01-06 01:58:22 +00005033QualType TreeTransform<Derived>::TransformAttributedType(
5034 TypeLocBuilder &TLB,
5035 AttributedTypeLoc TL) {
5036 const AttributedType *oldType = TL.getTypePtr();
5037 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
5038 if (modifiedType.isNull())
5039 return QualType();
5040
5041 QualType result = TL.getType();
5042
5043 // FIXME: dependent operand expressions?
5044 if (getDerived().AlwaysRebuild() ||
5045 modifiedType != oldType->getModifiedType()) {
5046 // TODO: this is really lame; we should really be rebuilding the
5047 // equivalent type from first principles.
5048 QualType equivalentType
5049 = getDerived().TransformType(oldType->getEquivalentType());
5050 if (equivalentType.isNull())
5051 return QualType();
5052 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
5053 modifiedType,
5054 equivalentType);
5055 }
5056
5057 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
5058 newTL.setAttrNameLoc(TL.getAttrNameLoc());
5059 if (TL.hasAttrOperand())
5060 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5061 if (TL.hasAttrExprOperand())
5062 newTL.setAttrExprOperand(TL.getAttrExprOperand());
5063 else if (TL.hasAttrEnumOperand())
5064 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
5065
5066 return result;
5067}
5068
5069template<typename Derived>
Abramo Bagnara075f8f12010-12-10 16:29:40 +00005070QualType
5071TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
5072 ParenTypeLoc TL) {
5073 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
5074 if (Inner.isNull())
5075 return QualType();
5076
5077 QualType Result = TL.getType();
5078 if (getDerived().AlwaysRebuild() ||
5079 Inner != TL.getInnerLoc().getType()) {
5080 Result = getDerived().RebuildParenType(Inner);
5081 if (Result.isNull())
5082 return QualType();
5083 }
5084
5085 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
5086 NewTL.setLParenLoc(TL.getLParenLoc());
5087 NewTL.setRParenLoc(TL.getRParenLoc());
5088 return Result;
5089}
5090
5091template<typename Derived>
Douglas Gregor4714c122010-03-31 17:34:00 +00005092QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005093 DependentNameTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00005094 const DependentNameType *T = TL.getTypePtr();
John McCall833ca992009-10-29 08:12:44 +00005095
Douglas Gregor2494dd02011-03-01 01:34:45 +00005096 NestedNameSpecifierLoc QualifierLoc
5097 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5098 if (!QualifierLoc)
Douglas Gregor577f75a2009-08-04 16:50:30 +00005099 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00005100
John McCall33500952010-06-11 00:33:02 +00005101 QualType Result
Douglas Gregor2494dd02011-03-01 01:34:45 +00005102 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara38a42912012-02-06 19:09:27 +00005103 TL.getElaboratedKeywordLoc(),
Douglas Gregor2494dd02011-03-01 01:34:45 +00005104 QualifierLoc,
5105 T->getIdentifier(),
John McCall33500952010-06-11 00:33:02 +00005106 TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00005107 if (Result.isNull())
5108 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00005109
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00005110 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
5111 QualType NamedT = ElabT->getNamedType();
John McCall33500952010-06-11 00:33:02 +00005112 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
5113
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00005114 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00005115 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00005116 NewTL.setQualifierLoc(QualifierLoc);
John McCall33500952010-06-11 00:33:02 +00005117 } else {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00005118 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00005119 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor2494dd02011-03-01 01:34:45 +00005120 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00005121 NewTL.setNameLoc(TL.getNameLoc());
5122 }
John McCalla2becad2009-10-21 00:40:46 +00005123 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00005124}
Mike Stump1eb44332009-09-09 15:08:12 +00005125
Douglas Gregor577f75a2009-08-04 16:50:30 +00005126template<typename Derived>
John McCall33500952010-06-11 00:33:02 +00005127QualType TreeTransform<Derived>::
5128 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005129 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005130 NestedNameSpecifierLoc QualifierLoc;
5131 if (TL.getQualifierLoc()) {
5132 QualifierLoc
5133 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5134 if (!QualifierLoc)
Douglas Gregora88f09f2011-02-28 17:23:35 +00005135 return QualType();
5136 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005137
John McCall43fed0d2010-11-12 08:19:04 +00005138 return getDerived()
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005139 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall43fed0d2010-11-12 08:19:04 +00005140}
5141
5142template<typename Derived>
5143QualType TreeTransform<Derived>::
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005144TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
5145 DependentTemplateSpecializationTypeLoc TL,
5146 NestedNameSpecifierLoc QualifierLoc) {
5147 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005148
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005149 TemplateArgumentListInfo NewTemplateArgs;
5150 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5151 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005152
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005153 typedef TemplateArgumentLocContainerIterator<
5154 DependentTemplateSpecializationTypeLoc> ArgIterator;
5155 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5156 ArgIterator(TL, TL.getNumArgs()),
5157 NewTemplateArgs))
5158 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005159
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005160 QualType Result
5161 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
5162 QualifierLoc,
5163 T->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005164 TL.getTemplateNameLoc(),
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005165 NewTemplateArgs);
5166 if (Result.isNull())
5167 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005168
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005169 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
5170 QualType NamedT = ElabT->getNamedType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005171
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005172 // Copy information relevant to the template specialization.
5173 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005174 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005175 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005176 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005177 NamedTL.setLAngleLoc(TL.getLAngleLoc());
5178 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005179 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005180 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005181
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005182 // Copy information relevant to the elaborated type.
5183 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00005184 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005185 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005186 } else if (isa<DependentTemplateSpecializationType>(Result)) {
5187 DependentTemplateSpecializationTypeLoc SpecTL
5188 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005189 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005190 SpecTL.setQualifierLoc(QualifierLoc);
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 } else {
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005198 TemplateSpecializationTypeLoc SpecTL
5199 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005200 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005201 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005202 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5203 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005204 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005205 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005206 }
5207 return Result;
5208}
5209
5210template<typename Derived>
Douglas Gregor7536dd52010-12-20 02:24:11 +00005211QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5212 PackExpansionTypeLoc TL) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005213 QualType Pattern
5214 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005215 if (Pattern.isNull())
5216 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005217
5218 QualType Result = TL.getType();
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005219 if (getDerived().AlwaysRebuild() ||
5220 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005221 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005222 TL.getPatternLoc().getSourceRange(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00005223 TL.getEllipsisLoc(),
5224 TL.getTypePtr()->getNumExpansions());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005225 if (Result.isNull())
5226 return QualType();
5227 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005228
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005229 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5230 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5231 return Result;
Douglas Gregor7536dd52010-12-20 02:24:11 +00005232}
5233
5234template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00005235QualType
5236TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005237 ObjCInterfaceTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00005238 // ObjCInterfaceType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00005239 TLB.pushFullCopy(TL);
5240 return TL.getType();
5241}
5242
5243template<typename Derived>
5244QualType
5245TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005246 ObjCObjectTypeLoc TL) {
John McCallc12c5bb2010-05-15 11:32:37 +00005247 // ObjCObjectType is never dependent.
5248 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00005249 return TL.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00005250}
Mike Stump1eb44332009-09-09 15:08:12 +00005251
5252template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00005253QualType
5254TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005255 ObjCObjectPointerTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00005256 // ObjCObjectPointerType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00005257 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00005258 return TL.getType();
Argyrios Kyrtzidis24fab412009-09-29 19:42:55 +00005259}
5260
Douglas Gregor577f75a2009-08-04 16:50:30 +00005261//===----------------------------------------------------------------------===//
Douglas Gregor43959a92009-08-20 07:17:43 +00005262// Statement transformation
5263//===----------------------------------------------------------------------===//
5264template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005265StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005266TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005267 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005268}
5269
5270template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005271StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005272TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
5273 return getDerived().TransformCompoundStmt(S, false);
5274}
5275
5276template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005277StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005278TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregor43959a92009-08-20 07:17:43 +00005279 bool IsStmtExpr) {
Dmitri Gribenko625bb562012-02-14 22:14:32 +00005280 Sema::CompoundScopeRAII CompoundScope(getSema());
5281
John McCall7114cba2010-08-27 19:56:05 +00005282 bool SubStmtInvalid = false;
Douglas Gregor43959a92009-08-20 07:17:43 +00005283 bool SubStmtChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005284 SmallVector<Stmt*, 8> Statements;
Douglas Gregor43959a92009-08-20 07:17:43 +00005285 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
5286 B != BEnd; ++B) {
John McCall60d7b3a2010-08-24 06:29:42 +00005287 StmtResult Result = getDerived().TransformStmt(*B);
John McCall7114cba2010-08-27 19:56:05 +00005288 if (Result.isInvalid()) {
5289 // Immediately fail if this was a DeclStmt, since it's very
5290 // likely that this will cause problems for future statements.
5291 if (isa<DeclStmt>(*B))
5292 return StmtError();
5293
5294 // Otherwise, just keep processing substatements and fail later.
5295 SubStmtInvalid = true;
5296 continue;
5297 }
Mike Stump1eb44332009-09-09 15:08:12 +00005298
Douglas Gregor43959a92009-08-20 07:17:43 +00005299 SubStmtChanged = SubStmtChanged || Result.get() != *B;
5300 Statements.push_back(Result.takeAs<Stmt>());
5301 }
Mike Stump1eb44332009-09-09 15:08:12 +00005302
John McCall7114cba2010-08-27 19:56:05 +00005303 if (SubStmtInvalid)
5304 return StmtError();
5305
Douglas Gregor43959a92009-08-20 07:17:43 +00005306 if (!getDerived().AlwaysRebuild() &&
5307 !SubStmtChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005308 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005309
5310 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00005311 Statements,
Douglas Gregor43959a92009-08-20 07:17:43 +00005312 S->getRBracLoc(),
5313 IsStmtExpr);
5314}
Mike Stump1eb44332009-09-09 15:08:12 +00005315
Douglas Gregor43959a92009-08-20 07:17:43 +00005316template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005317StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005318TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005319 ExprResult LHS, RHS;
Eli Friedman264c1f82009-11-19 03:14:00 +00005320 {
Eli Friedman6b3014b2012-01-18 02:54:10 +00005321 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5322 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00005323
Eli Friedman264c1f82009-11-19 03:14:00 +00005324 // Transform the left-hand case value.
5325 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanac626012012-02-29 03:16:56 +00005326 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman264c1f82009-11-19 03:14:00 +00005327 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005328 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005329
Eli Friedman264c1f82009-11-19 03:14:00 +00005330 // Transform the right-hand case value (for the GNU case-range extension).
5331 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanac626012012-02-29 03:16:56 +00005332 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman264c1f82009-11-19 03:14:00 +00005333 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005334 return StmtError();
Eli Friedman264c1f82009-11-19 03:14:00 +00005335 }
Mike Stump1eb44332009-09-09 15:08:12 +00005336
Douglas Gregor43959a92009-08-20 07:17:43 +00005337 // Build the case statement.
5338 // Case statements are always rebuilt so that they will attached to their
5339 // transformed switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005340 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005341 LHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005342 S->getEllipsisLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005343 RHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005344 S->getColonLoc());
5345 if (Case.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005346 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005347
Douglas Gregor43959a92009-08-20 07:17:43 +00005348 // Transform the statement following the case
John McCall60d7b3a2010-08-24 06:29:42 +00005349 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005350 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005351 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005352
Douglas Gregor43959a92009-08-20 07:17:43 +00005353 // Attach the body to the case statement
John McCall9ae2f072010-08-23 23:25:46 +00005354 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005355}
5356
5357template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005358StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005359TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005360 // Transform the statement following the default case
John McCall60d7b3a2010-08-24 06:29:42 +00005361 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005362 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005363 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005364
Douglas Gregor43959a92009-08-20 07:17:43 +00005365 // Default statements are always rebuilt
5366 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005367 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005368}
Mike Stump1eb44332009-09-09 15:08:12 +00005369
Douglas Gregor43959a92009-08-20 07:17:43 +00005370template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005371StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005372TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005373 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005374 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005375 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005376
Chris Lattner57ad3782011-02-17 20:34:02 +00005377 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5378 S->getDecl());
5379 if (!LD)
5380 return StmtError();
Richard Smith534986f2012-04-14 00:33:13 +00005381
5382
Douglas Gregor43959a92009-08-20 07:17:43 +00005383 // FIXME: Pass the real colon location in.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00005384 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005385 cast<LabelDecl>(LD), SourceLocation(),
5386 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005387}
Mike Stump1eb44332009-09-09 15:08:12 +00005388
Douglas Gregor43959a92009-08-20 07:17:43 +00005389template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005390StmtResult
Richard Smith534986f2012-04-14 00:33:13 +00005391TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
5392 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5393 if (SubStmt.isInvalid())
5394 return StmtError();
5395
5396 // TODO: transform attributes
5397 if (SubStmt.get() == S->getSubStmt() /* && attrs are the same */)
5398 return S;
5399
5400 return getDerived().RebuildAttributedStmt(S->getAttrLoc(),
5401 S->getAttrs(),
5402 SubStmt.get());
5403}
5404
5405template<typename Derived>
5406StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005407TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005408 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005409 ExprResult Cond;
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005410 VarDecl *ConditionVar = 0;
5411 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005412 ConditionVar
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005413 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005414 getDerived().TransformDefinition(
5415 S->getConditionVariable()->getLocation(),
5416 S->getConditionVariable()));
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005417 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005418 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005419 } else {
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005420 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005421
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005422 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005423 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005424
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005425 // Convert the condition to a boolean value.
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005426 if (S->getCond()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005427 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005428 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005429 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005430 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005431
John McCall9ae2f072010-08-23 23:25:46 +00005432 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005433 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005434 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005435
John McCall9ae2f072010-08-23 23:25:46 +00005436 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5437 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005438 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005439
Douglas Gregor43959a92009-08-20 07:17:43 +00005440 // Transform the "then" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005441 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregor43959a92009-08-20 07:17:43 +00005442 if (Then.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005443 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005444
Douglas Gregor43959a92009-08-20 07:17:43 +00005445 // Transform the "else" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005446 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregor43959a92009-08-20 07:17:43 +00005447 if (Else.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005448 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005449
Douglas Gregor43959a92009-08-20 07:17:43 +00005450 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005451 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005452 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005453 Then.get() == S->getThen() &&
5454 Else.get() == S->getElse())
John McCall3fa5cae2010-10-26 07:05:15 +00005455 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005456
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005457 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00005458 Then.get(),
John McCall9ae2f072010-08-23 23:25:46 +00005459 S->getElseLoc(), Else.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005460}
5461
5462template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005463StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005464TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005465 // Transform the condition.
John McCall60d7b3a2010-08-24 06:29:42 +00005466 ExprResult Cond;
Douglas Gregord3d53012009-11-24 17:07:59 +00005467 VarDecl *ConditionVar = 0;
5468 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005469 ConditionVar
Douglas Gregord3d53012009-11-24 17:07:59 +00005470 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005471 getDerived().TransformDefinition(
5472 S->getConditionVariable()->getLocation(),
5473 S->getConditionVariable()));
Douglas Gregord3d53012009-11-24 17:07:59 +00005474 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005475 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005476 } else {
Douglas Gregord3d53012009-11-24 17:07:59 +00005477 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005478
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005479 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005480 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005481 }
Mike Stump1eb44332009-09-09 15:08:12 +00005482
Douglas Gregor43959a92009-08-20 07:17:43 +00005483 // Rebuild the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005484 StmtResult Switch
John McCall9ae2f072010-08-23 23:25:46 +00005485 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregor586596f2010-05-06 17:25:47 +00005486 ConditionVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00005487 if (Switch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005488 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005489
Douglas Gregor43959a92009-08-20 07:17:43 +00005490 // Transform the body of the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005491 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005492 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005493 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005494
Douglas Gregor43959a92009-08-20 07:17:43 +00005495 // Complete the switch statement.
John McCall9ae2f072010-08-23 23:25:46 +00005496 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5497 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005498}
Mike Stump1eb44332009-09-09 15:08:12 +00005499
Douglas Gregor43959a92009-08-20 07:17:43 +00005500template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005501StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005502TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005503 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005504 ExprResult Cond;
Douglas Gregor5656e142009-11-24 21:15:44 +00005505 VarDecl *ConditionVar = 0;
5506 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005507 ConditionVar
Douglas Gregor5656e142009-11-24 21:15:44 +00005508 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005509 getDerived().TransformDefinition(
5510 S->getConditionVariable()->getLocation(),
5511 S->getConditionVariable()));
Douglas Gregor5656e142009-11-24 21:15:44 +00005512 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005513 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005514 } else {
Douglas Gregor5656e142009-11-24 21:15:44 +00005515 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005516
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005517 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005518 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005519
5520 if (S->getCond()) {
5521 // Convert the condition to a boolean value.
Chad Rosier4a9d7952012-08-08 18:46:20 +00005522 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005523 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005524 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005525 return StmtError();
John McCall9ae2f072010-08-23 23:25:46 +00005526 Cond = CondE;
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005527 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005528 }
Mike Stump1eb44332009-09-09 15:08:12 +00005529
John McCall9ae2f072010-08-23 23:25:46 +00005530 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5531 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005532 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005533
Douglas Gregor43959a92009-08-20 07:17:43 +00005534 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005535 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005536 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005537 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005538
Douglas Gregor43959a92009-08-20 07:17:43 +00005539 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005540 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005541 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005542 Body.get() == S->getBody())
John McCall9ae2f072010-08-23 23:25:46 +00005543 return Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005544
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005545 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCall9ae2f072010-08-23 23:25:46 +00005546 ConditionVar, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005547}
Mike Stump1eb44332009-09-09 15:08:12 +00005548
Douglas Gregor43959a92009-08-20 07:17:43 +00005549template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005550StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005551TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005552 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005553 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005554 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005555 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005556
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005557 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005558 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005559 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005560 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005561
Douglas Gregor43959a92009-08-20 07:17:43 +00005562 if (!getDerived().AlwaysRebuild() &&
5563 Cond.get() == S->getCond() &&
5564 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005565 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005566
John McCall9ae2f072010-08-23 23:25:46 +00005567 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5568 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005569 S->getRParenLoc());
5570}
Mike Stump1eb44332009-09-09 15:08:12 +00005571
Douglas Gregor43959a92009-08-20 07:17:43 +00005572template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005573StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005574TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005575 // Transform the initialization statement
John McCall60d7b3a2010-08-24 06:29:42 +00005576 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregor43959a92009-08-20 07:17:43 +00005577 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005578 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005579
Douglas Gregor43959a92009-08-20 07:17:43 +00005580 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005581 ExprResult Cond;
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005582 VarDecl *ConditionVar = 0;
5583 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005584 ConditionVar
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005585 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005586 getDerived().TransformDefinition(
5587 S->getConditionVariable()->getLocation(),
5588 S->getConditionVariable()));
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005589 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005590 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005591 } else {
5592 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005593
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005594 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005595 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005596
5597 if (S->getCond()) {
5598 // Convert the condition to a boolean value.
Chad Rosier4a9d7952012-08-08 18:46:20 +00005599 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005600 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005601 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005602 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005603
John McCall9ae2f072010-08-23 23:25:46 +00005604 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005605 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005606 }
Mike Stump1eb44332009-09-09 15:08:12 +00005607
Chad Rosier4a9d7952012-08-08 18:46:20 +00005608 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
John McCall9ae2f072010-08-23 23:25:46 +00005609 if (!S->getConditionVariable() && S->getCond() && !FullCond.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 increment
John McCall60d7b3a2010-08-24 06:29:42 +00005613 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005614 if (Inc.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005615 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005616
Richard Smith41956372013-01-14 22:39:08 +00005617 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
John McCall9ae2f072010-08-23 23:25:46 +00005618 if (S->getInc() && !FullInc.get())
John McCallf312b1e2010-08-26 23:41:50 +00005619 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005620
Douglas Gregor43959a92009-08-20 07:17:43 +00005621 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005622 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005623 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005624 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005625
Douglas Gregor43959a92009-08-20 07:17:43 +00005626 if (!getDerived().AlwaysRebuild() &&
5627 Init.get() == S->getInit() &&
John McCall9ae2f072010-08-23 23:25:46 +00005628 FullCond.get() == S->getCond() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005629 Inc.get() == S->getInc() &&
5630 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005631 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005632
Douglas Gregor43959a92009-08-20 07:17:43 +00005633 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005634 Init.get(), FullCond, ConditionVar,
5635 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005636}
5637
5638template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005639StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005640TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattner57ad3782011-02-17 20:34:02 +00005641 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5642 S->getLabel());
5643 if (!LD)
5644 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005645
Douglas Gregor43959a92009-08-20 07:17:43 +00005646 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump1eb44332009-09-09 15:08:12 +00005647 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005648 cast<LabelDecl>(LD));
Douglas Gregor43959a92009-08-20 07:17:43 +00005649}
5650
5651template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005652StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005653TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005654 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregor43959a92009-08-20 07:17:43 +00005655 if (Target.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005656 return StmtError();
Eli Friedmand29975f2012-01-31 22:47:07 +00005657 Target = SemaRef.MaybeCreateExprWithCleanups(Target.take());
Mike Stump1eb44332009-09-09 15:08:12 +00005658
Douglas Gregor43959a92009-08-20 07:17:43 +00005659 if (!getDerived().AlwaysRebuild() &&
5660 Target.get() == S->getTarget())
John McCall3fa5cae2010-10-26 07:05:15 +00005661 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005662
5663 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005664 Target.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005665}
5666
5667template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005668StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005669TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005670 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005671}
Mike Stump1eb44332009-09-09 15:08:12 +00005672
Douglas Gregor43959a92009-08-20 07:17:43 +00005673template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005674StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005675TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005676 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005677}
Mike Stump1eb44332009-09-09 15:08:12 +00005678
Douglas Gregor43959a92009-08-20 07:17:43 +00005679template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005680StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005681TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005682 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregor43959a92009-08-20 07:17:43 +00005683 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005684 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005685
Mike Stump1eb44332009-09-09 15:08:12 +00005686 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregor43959a92009-08-20 07:17:43 +00005687 // to tell whether the return type of the function has changed.
John McCall9ae2f072010-08-23 23:25:46 +00005688 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005689}
Mike Stump1eb44332009-09-09 15:08:12 +00005690
Douglas Gregor43959a92009-08-20 07:17:43 +00005691template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005692StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005693TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005694 bool DeclChanged = false;
Chris Lattner686775d2011-07-20 06:58:45 +00005695 SmallVector<Decl *, 4> Decls;
Douglas Gregor43959a92009-08-20 07:17:43 +00005696 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5697 D != DEnd; ++D) {
Douglas Gregoraac571c2010-03-01 17:25:41 +00005698 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5699 *D);
Douglas Gregor43959a92009-08-20 07:17:43 +00005700 if (!Transformed)
John McCallf312b1e2010-08-26 23:41:50 +00005701 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005702
Douglas Gregor43959a92009-08-20 07:17:43 +00005703 if (Transformed != *D)
5704 DeclChanged = true;
Mike Stump1eb44332009-09-09 15:08:12 +00005705
Douglas Gregor43959a92009-08-20 07:17:43 +00005706 Decls.push_back(Transformed);
5707 }
Mike Stump1eb44332009-09-09 15:08:12 +00005708
Douglas Gregor43959a92009-08-20 07:17:43 +00005709 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005710 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005711
Rafael Espindola4549d7f2013-07-09 12:05:01 +00005712 return getDerived().RebuildDeclStmt(Decls, S->getStartLoc(), S->getEndLoc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005713}
Mike Stump1eb44332009-09-09 15:08:12 +00005714
Douglas Gregor43959a92009-08-20 07:17:43 +00005715template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005716StmtResult
Chad Rosierdf5faf52012-08-25 00:11:56 +00005717TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005718
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005719 SmallVector<Expr*, 8> Constraints;
5720 SmallVector<Expr*, 8> Exprs;
Chris Lattner686775d2011-07-20 06:58:45 +00005721 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlssona5a79f72010-01-30 20:05:21 +00005722
John McCall60d7b3a2010-08-24 06:29:42 +00005723 ExprResult AsmString;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005724 SmallVector<Expr*, 8> Clobbers;
Anders Carlsson703e3942010-01-24 05:50:09 +00005725
5726 bool ExprsChanged = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005727
Anders Carlsson703e3942010-01-24 05:50:09 +00005728 // Go through the outputs.
5729 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005730 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005731
Anders Carlsson703e3942010-01-24 05:50:09 +00005732 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005733 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005734
Anders Carlsson703e3942010-01-24 05:50:09 +00005735 // Transform the output expr.
5736 Expr *OutputExpr = S->getOutputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005737 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005738 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005739 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005740
Anders Carlsson703e3942010-01-24 05:50:09 +00005741 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005742
John McCall9ae2f072010-08-23 23:25:46 +00005743 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005744 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005745
Anders Carlsson703e3942010-01-24 05:50:09 +00005746 // Go through the inputs.
5747 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005748 Names.push_back(S->getInputIdentifier(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005749
Anders Carlsson703e3942010-01-24 05:50:09 +00005750 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005751 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005752
Anders Carlsson703e3942010-01-24 05:50:09 +00005753 // Transform the input expr.
5754 Expr *InputExpr = S->getInputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005755 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005756 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005757 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005758
Anders Carlsson703e3942010-01-24 05:50:09 +00005759 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005760
John McCall9ae2f072010-08-23 23:25:46 +00005761 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005762 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005763
Anders Carlsson703e3942010-01-24 05:50:09 +00005764 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005765 return SemaRef.Owned(S);
Anders Carlsson703e3942010-01-24 05:50:09 +00005766
5767 // Go through the clobbers.
5768 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosier5c7f5942012-08-27 23:28:41 +00005769 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlsson703e3942010-01-24 05:50:09 +00005770
5771 // No need to transform the asm string literal.
5772 AsmString = SemaRef.Owned(S->getAsmString());
Chad Rosierdf5faf52012-08-25 00:11:56 +00005773 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
5774 S->isVolatile(), S->getNumOutputs(),
5775 S->getNumInputs(), Names.data(),
5776 Constraints, Exprs, AsmString.get(),
5777 Clobbers, S->getRParenLoc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005778}
5779
Chad Rosier8cd64b42012-06-11 20:47:18 +00005780template<typename Derived>
5781StmtResult
5782TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier79efe242012-08-07 00:29:06 +00005783 ArrayRef<Token> AsmToks =
5784 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier62f22b82012-08-08 19:48:07 +00005785
John McCallaeeacf72013-05-03 00:10:13 +00005786 bool HadError = false, HadChange = false;
5787
5788 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
5789 SmallVector<Expr*, 8> TransformedExprs;
5790 TransformedExprs.reserve(SrcExprs.size());
5791 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
5792 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
5793 if (!Result.isUsable()) {
5794 HadError = true;
5795 } else {
5796 HadChange |= (Result.get() != SrcExprs[i]);
5797 TransformedExprs.push_back(Result.take());
5798 }
5799 }
5800
5801 if (HadError) return StmtError();
5802 if (!HadChange && !getDerived().AlwaysRebuild())
5803 return Owned(S);
5804
Chad Rosier7bd092b2012-08-15 16:53:30 +00005805 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
John McCallaeeacf72013-05-03 00:10:13 +00005806 AsmToks, S->getAsmString(),
5807 S->getNumOutputs(), S->getNumInputs(),
5808 S->getAllConstraints(), S->getClobbers(),
5809 TransformedExprs, S->getEndLoc());
Chad Rosier8cd64b42012-06-11 20:47:18 +00005810}
Douglas Gregor43959a92009-08-20 07:17:43 +00005811
5812template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005813StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005814TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005815 // Transform the body of the @try.
John McCall60d7b3a2010-08-24 06:29:42 +00005816 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005817 if (TryBody.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005818 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005819
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005820 // Transform the @catch statements (if present).
5821 bool AnyCatchChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005822 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005823 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005824 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005825 if (Catch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005826 return StmtError();
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005827 if (Catch.get() != S->getCatchStmt(I))
5828 AnyCatchChanged = true;
5829 CatchStmts.push_back(Catch.release());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005830 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005831
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005832 // Transform the @finally statement (if present).
John McCall60d7b3a2010-08-24 06:29:42 +00005833 StmtResult Finally;
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005834 if (S->getFinallyStmt()) {
5835 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5836 if (Finally.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005837 return StmtError();
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005838 }
5839
5840 // If nothing changed, just retain this statement.
5841 if (!getDerived().AlwaysRebuild() &&
5842 TryBody.get() == S->getTryBody() &&
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005843 !AnyCatchChanged &&
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005844 Finally.get() == S->getFinallyStmt())
John McCall3fa5cae2010-10-26 07:05:15 +00005845 return SemaRef.Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005846
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005847 // Build a new statement.
John McCall9ae2f072010-08-23 23:25:46 +00005848 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00005849 CatchStmts, Finally.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005850}
Mike Stump1eb44332009-09-09 15:08:12 +00005851
Douglas Gregor43959a92009-08-20 07:17:43 +00005852template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005853StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005854TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00005855 // Transform the @catch parameter, if there is one.
5856 VarDecl *Var = 0;
5857 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5858 TypeSourceInfo *TSInfo = 0;
5859 if (FromVar->getTypeSourceInfo()) {
5860 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5861 if (!TSInfo)
John McCallf312b1e2010-08-26 23:41:50 +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 QualType T;
5866 if (TSInfo)
5867 T = TSInfo->getType();
5868 else {
5869 T = getDerived().TransformType(FromVar->getType());
5870 if (T.isNull())
Chad Rosier4a9d7952012-08-08 18:46:20 +00005871 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005872 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005873
Douglas Gregorbe270a02010-04-26 17:57:08 +00005874 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5875 if (!Var)
John McCallf312b1e2010-08-26 23:41:50 +00005876 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005877 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005878
John McCall60d7b3a2010-08-24 06:29:42 +00005879 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorbe270a02010-04-26 17:57:08 +00005880 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005881 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005882
5883 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorbe270a02010-04-26 17:57:08 +00005884 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005885 Var, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005886}
Mike Stump1eb44332009-09-09 15:08:12 +00005887
Douglas Gregor43959a92009-08-20 07:17:43 +00005888template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005889StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005890TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005891 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005892 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005893 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005894 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005895
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005896 // If nothing changed, just retain this statement.
5897 if (!getDerived().AlwaysRebuild() &&
5898 Body.get() == S->getFinallyBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005899 return SemaRef.Owned(S);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005900
5901 // Build a new statement.
5902 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005903 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005904}
Mike Stump1eb44332009-09-09 15:08:12 +00005905
Douglas Gregor43959a92009-08-20 07:17:43 +00005906template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005907StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005908TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005909 ExprResult Operand;
Douglas Gregord1377b22010-04-22 21:44:01 +00005910 if (S->getThrowExpr()) {
5911 Operand = getDerived().TransformExpr(S->getThrowExpr());
5912 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005913 return StmtError();
Douglas Gregord1377b22010-04-22 21:44:01 +00005914 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005915
Douglas Gregord1377b22010-04-22 21:44:01 +00005916 if (!getDerived().AlwaysRebuild() &&
5917 Operand.get() == S->getThrowExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005918 return getSema().Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005919
John McCall9ae2f072010-08-23 23:25:46 +00005920 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005921}
Mike Stump1eb44332009-09-09 15:08:12 +00005922
Douglas Gregor43959a92009-08-20 07:17:43 +00005923template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005924StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005925TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005926 ObjCAtSynchronizedStmt *S) {
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005927 // Transform the object we are locking.
John McCall60d7b3a2010-08-24 06:29:42 +00005928 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005929 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005930 return StmtError();
John McCall07524032011-07-27 21:50:02 +00005931 Object =
5932 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
5933 Object.get());
5934 if (Object.isInvalid())
5935 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005936
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005937 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005938 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005939 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005940 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005941
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005942 // If nothing change, just retain the current statement.
5943 if (!getDerived().AlwaysRebuild() &&
5944 Object.get() == S->getSynchExpr() &&
5945 Body.get() == S->getSynchBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005946 return SemaRef.Owned(S);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005947
5948 // Build a new statement.
5949 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005950 Object.get(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005951}
5952
5953template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005954StmtResult
John McCallf85e1932011-06-15 23:02:42 +00005955TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
5956 ObjCAutoreleasePoolStmt *S) {
5957 // Transform the body.
5958 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
5959 if (Body.isInvalid())
5960 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005961
John McCallf85e1932011-06-15 23:02:42 +00005962 // If nothing changed, just retain this statement.
5963 if (!getDerived().AlwaysRebuild() &&
5964 Body.get() == S->getSubStmt())
5965 return SemaRef.Owned(S);
5966
5967 // Build a new statement.
5968 return getDerived().RebuildObjCAutoreleasePoolStmt(
5969 S->getAtLoc(), Body.get());
5970}
5971
5972template<typename Derived>
5973StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005974TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005975 ObjCForCollectionStmt *S) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00005976 // Transform the element statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005977 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005978 if (Element.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005979 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005980
Douglas Gregorc3203e72010-04-22 23:10:45 +00005981 // Transform the collection expression.
John McCall60d7b3a2010-08-24 06:29:42 +00005982 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005983 if (Collection.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005984 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005985
Douglas Gregorc3203e72010-04-22 23:10:45 +00005986 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005987 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005988 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005989 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005990
Douglas Gregorc3203e72010-04-22 23:10:45 +00005991 // If nothing changed, just retain this statement.
5992 if (!getDerived().AlwaysRebuild() &&
5993 Element.get() == S->getElement() &&
5994 Collection.get() == S->getCollection() &&
5995 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005996 return SemaRef.Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005997
Douglas Gregorc3203e72010-04-22 23:10:45 +00005998 // Build a new statement.
5999 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006000 Element.get(),
6001 Collection.get(),
Douglas Gregorc3203e72010-04-22 23:10:45 +00006002 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006003 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00006004}
6005
David Majnemer2c4a01d2013-10-15 09:50:08 +00006006template <typename Derived>
6007StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00006008 // Transform the exception declaration, if any.
6009 VarDecl *Var = 0;
David Majnemer2c4a01d2013-10-15 09:50:08 +00006010 if (VarDecl *ExceptionDecl = S->getExceptionDecl()) {
6011 TypeSourceInfo *T =
6012 getDerived().TransformType(ExceptionDecl->getTypeSourceInfo());
Douglas Gregor83cb9422010-09-09 17:09:21 +00006013 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00006014 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00006015
David Majnemer2c4a01d2013-10-15 09:50:08 +00006016 Var = getDerived().RebuildExceptionDecl(
6017 ExceptionDecl, T, ExceptionDecl->getInnerLocStart(),
6018 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
Douglas Gregorff331c12010-07-25 18:17:45 +00006019 if (!Var || Var->isInvalidDecl())
John McCallf312b1e2010-08-26 23:41:50 +00006020 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00006021 }
Mike Stump1eb44332009-09-09 15:08:12 +00006022
Douglas Gregor43959a92009-08-20 07:17:43 +00006023 // Transform the actual exception handler.
John McCall60d7b3a2010-08-24 06:29:42 +00006024 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorff331c12010-07-25 18:17:45 +00006025 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006026 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00006027
David Majnemer2c4a01d2013-10-15 09:50:08 +00006028 if (!getDerived().AlwaysRebuild() && !Var &&
Douglas Gregor43959a92009-08-20 07:17:43 +00006029 Handler.get() == S->getHandlerBlock())
John McCall3fa5cae2010-10-26 07:05:15 +00006030 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00006031
David Majnemer2c4a01d2013-10-15 09:50:08 +00006032 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00006033}
Mike Stump1eb44332009-09-09 15:08:12 +00006034
David Majnemer2c4a01d2013-10-15 09:50:08 +00006035template <typename Derived>
6036StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00006037 // Transform the try block itself.
David Majnemer2c4a01d2013-10-15 09:50:08 +00006038 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
Douglas Gregor43959a92009-08-20 07:17:43 +00006039 if (TryBlock.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006040 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00006041
Douglas Gregor43959a92009-08-20 07:17:43 +00006042 // Transform the handlers.
6043 bool HandlerChanged = false;
David Majnemer2c4a01d2013-10-15 09:50:08 +00006044 SmallVector<Stmt *, 8> Handlers;
Douglas Gregor43959a92009-08-20 07:17:43 +00006045 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
David Majnemer2c4a01d2013-10-15 09:50:08 +00006046 StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I));
Douglas Gregor43959a92009-08-20 07:17:43 +00006047 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006048 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00006049
Douglas Gregor43959a92009-08-20 07:17:43 +00006050 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
6051 Handlers.push_back(Handler.takeAs<Stmt>());
6052 }
Mike Stump1eb44332009-09-09 15:08:12 +00006053
David Majnemer2c4a01d2013-10-15 09:50:08 +00006054 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00006055 !HandlerChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006056 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00006057
John McCall9ae2f072010-08-23 23:25:46 +00006058 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006059 Handlers);
Douglas Gregor43959a92009-08-20 07:17:43 +00006060}
Mike Stump1eb44332009-09-09 15:08:12 +00006061
Richard Smithad762fc2011-04-14 22:09:26 +00006062template<typename Derived>
6063StmtResult
6064TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
6065 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
6066 if (Range.isInvalid())
6067 return StmtError();
6068
6069 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
6070 if (BeginEnd.isInvalid())
6071 return StmtError();
6072
6073 ExprResult Cond = getDerived().TransformExpr(S->getCond());
6074 if (Cond.isInvalid())
6075 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00006076 if (Cond.get())
6077 Cond = SemaRef.CheckBooleanCondition(Cond.take(), S->getColonLoc());
6078 if (Cond.isInvalid())
6079 return StmtError();
6080 if (Cond.get())
6081 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.take());
Richard Smithad762fc2011-04-14 22:09:26 +00006082
6083 ExprResult Inc = getDerived().TransformExpr(S->getInc());
6084 if (Inc.isInvalid())
6085 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00006086 if (Inc.get())
6087 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.take());
Richard Smithad762fc2011-04-14 22:09:26 +00006088
6089 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
6090 if (LoopVar.isInvalid())
6091 return StmtError();
6092
6093 StmtResult NewStmt = S;
6094 if (getDerived().AlwaysRebuild() ||
6095 Range.get() != S->getRangeStmt() ||
6096 BeginEnd.get() != S->getBeginEndStmt() ||
6097 Cond.get() != S->getCond() ||
6098 Inc.get() != S->getInc() ||
Douglas Gregor39b60dc2013-05-02 18:35:56 +00006099 LoopVar.get() != S->getLoopVarStmt()) {
Richard Smithad762fc2011-04-14 22:09:26 +00006100 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6101 S->getColonLoc(), Range.get(),
6102 BeginEnd.get(), Cond.get(),
6103 Inc.get(), LoopVar.get(),
6104 S->getRParenLoc());
Douglas Gregor39b60dc2013-05-02 18:35:56 +00006105 if (NewStmt.isInvalid())
6106 return StmtError();
6107 }
Richard Smithad762fc2011-04-14 22:09:26 +00006108
6109 StmtResult Body = getDerived().TransformStmt(S->getBody());
6110 if (Body.isInvalid())
6111 return StmtError();
6112
6113 // Body has changed but we didn't rebuild the for-range statement. Rebuild
6114 // it now so we have a new statement to attach the body to.
Douglas Gregor39b60dc2013-05-02 18:35:56 +00006115 if (Body.get() != S->getBody() && NewStmt.get() == S) {
Richard Smithad762fc2011-04-14 22:09:26 +00006116 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6117 S->getColonLoc(), Range.get(),
6118 BeginEnd.get(), Cond.get(),
6119 Inc.get(), LoopVar.get(),
6120 S->getRParenLoc());
Douglas Gregor39b60dc2013-05-02 18:35:56 +00006121 if (NewStmt.isInvalid())
6122 return StmtError();
6123 }
Richard Smithad762fc2011-04-14 22:09:26 +00006124
6125 if (NewStmt.get() == S)
6126 return SemaRef.Owned(S);
6127
6128 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
6129}
6130
John Wiegley28bbe4b2011-04-28 01:08:34 +00006131template<typename Derived>
6132StmtResult
Douglas Gregorba0513d2011-10-25 01:33:02 +00006133TreeTransform<Derived>::TransformMSDependentExistsStmt(
6134 MSDependentExistsStmt *S) {
6135 // Transform the nested-name-specifier, if any.
6136 NestedNameSpecifierLoc QualifierLoc;
6137 if (S->getQualifierLoc()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00006138 QualifierLoc
Douglas Gregorba0513d2011-10-25 01:33:02 +00006139 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
6140 if (!QualifierLoc)
6141 return StmtError();
6142 }
6143
6144 // Transform the declaration name.
6145 DeclarationNameInfo NameInfo = S->getNameInfo();
6146 if (NameInfo.getName()) {
6147 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6148 if (!NameInfo.getName())
6149 return StmtError();
6150 }
6151
6152 // Check whether anything changed.
6153 if (!getDerived().AlwaysRebuild() &&
6154 QualifierLoc == S->getQualifierLoc() &&
6155 NameInfo.getName() == S->getNameInfo().getName())
6156 return S;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006157
Douglas Gregorba0513d2011-10-25 01:33:02 +00006158 // Determine whether this name exists, if we can.
6159 CXXScopeSpec SS;
6160 SS.Adopt(QualifierLoc);
6161 bool Dependent = false;
6162 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/0, SS, NameInfo)) {
6163 case Sema::IER_Exists:
6164 if (S->isIfExists())
6165 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006166
Douglas Gregorba0513d2011-10-25 01:33:02 +00006167 return new (getSema().Context) NullStmt(S->getKeywordLoc());
6168
6169 case Sema::IER_DoesNotExist:
6170 if (S->isIfNotExists())
6171 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006172
Douglas Gregorba0513d2011-10-25 01:33:02 +00006173 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00006174
Douglas Gregorba0513d2011-10-25 01:33:02 +00006175 case Sema::IER_Dependent:
6176 Dependent = true;
6177 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006178
Douglas Gregor65019ac2011-10-25 03:44:56 +00006179 case Sema::IER_Error:
6180 return StmtError();
Douglas Gregorba0513d2011-10-25 01:33:02 +00006181 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006182
Douglas Gregorba0513d2011-10-25 01:33:02 +00006183 // We need to continue with the instantiation, so do so now.
6184 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
6185 if (SubStmt.isInvalid())
6186 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006187
Douglas Gregorba0513d2011-10-25 01:33:02 +00006188 // If we have resolved the name, just transform to the substatement.
6189 if (!Dependent)
6190 return SubStmt;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006191
Douglas Gregorba0513d2011-10-25 01:33:02 +00006192 // The name is still dependent, so build a dependent expression again.
6193 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
6194 S->isIfExists(),
6195 QualifierLoc,
6196 NameInfo,
6197 SubStmt.get());
6198}
6199
6200template<typename Derived>
John McCall76da55d2013-04-16 07:28:30 +00006201ExprResult
6202TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
6203 NestedNameSpecifierLoc QualifierLoc;
6204 if (E->getQualifierLoc()) {
6205 QualifierLoc
6206 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6207 if (!QualifierLoc)
6208 return ExprError();
6209 }
6210
6211 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
6212 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
6213 if (!PD)
6214 return ExprError();
6215
6216 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
6217 if (Base.isInvalid())
6218 return ExprError();
6219
6220 return new (SemaRef.getASTContext())
6221 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
6222 SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
6223 QualifierLoc, E->getMemberLoc());
6224}
6225
David Majnemerfc210492013-10-15 09:33:02 +00006226template <typename Derived>
6227StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
David Majnemer7752a742013-10-15 09:30:14 +00006228 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
David Majnemerfc210492013-10-15 09:33:02 +00006229 if (TryBlock.isInvalid())
6230 return StmtError();
John Wiegley28bbe4b2011-04-28 01:08:34 +00006231
6232 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
David Majnemer7752a742013-10-15 09:30:14 +00006233 if (Handler.isInvalid())
6234 return StmtError();
6235
David Majnemerfc210492013-10-15 09:33:02 +00006236 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
6237 Handler.get() == S->getHandler())
John Wiegley28bbe4b2011-04-28 01:08:34 +00006238 return SemaRef.Owned(S);
6239
David Majnemerfc210492013-10-15 09:33:02 +00006240 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(),
6241 TryBlock.take(), Handler.take());
John Wiegley28bbe4b2011-04-28 01:08:34 +00006242}
6243
David Majnemerfc210492013-10-15 09:33:02 +00006244template <typename Derived>
6245StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
David Majnemer7752a742013-10-15 09:30:14 +00006246 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfc210492013-10-15 09:33:02 +00006247 if (Block.isInvalid())
6248 return StmtError();
John Wiegley28bbe4b2011-04-28 01:08:34 +00006249
David Majnemerfc210492013-10-15 09:33:02 +00006250 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.take());
John Wiegley28bbe4b2011-04-28 01:08:34 +00006251}
6252
David Majnemerfc210492013-10-15 09:33:02 +00006253template <typename Derived>
6254StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
John Wiegley28bbe4b2011-04-28 01:08:34 +00006255 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
David Majnemerfc210492013-10-15 09:33:02 +00006256 if (FilterExpr.isInvalid())
6257 return StmtError();
John Wiegley28bbe4b2011-04-28 01:08:34 +00006258
David Majnemer7752a742013-10-15 09:30:14 +00006259 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfc210492013-10-15 09:33:02 +00006260 if (Block.isInvalid())
6261 return StmtError();
John Wiegley28bbe4b2011-04-28 01:08:34 +00006262
David Majnemerfc210492013-10-15 09:33:02 +00006263 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.take(),
John Wiegley28bbe4b2011-04-28 01:08:34 +00006264 Block.take());
6265}
6266
David Majnemerfc210492013-10-15 09:33:02 +00006267template <typename Derived>
6268StmtResult TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
6269 if (isa<SEHFinallyStmt>(Handler))
John Wiegley28bbe4b2011-04-28 01:08:34 +00006270 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
6271 else
6272 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
6273}
6274
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006275template<typename Derived>
6276StmtResult
6277TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
Alexey Bataev0c018352013-09-06 18:03:48 +00006278 DeclarationNameInfo DirName;
6279 getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, 0);
6280
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006281 // Transform the clauses
Alexey Bataev0c018352013-09-06 18:03:48 +00006282 llvm::SmallVector<OMPClause *, 16> TClauses;
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006283 ArrayRef<OMPClause *> Clauses = D->clauses();
6284 TClauses.reserve(Clauses.size());
6285 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
6286 I != E; ++I) {
6287 if (*I) {
6288 OMPClause *Clause = getDerived().TransformOMPClause(*I);
Alexey Bataev0c018352013-09-06 18:03:48 +00006289 if (!Clause) {
6290 getSema().EndOpenMPDSABlock(0);
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006291 return StmtError();
Alexey Bataev0c018352013-09-06 18:03:48 +00006292 }
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006293 TClauses.push_back(Clause);
6294 }
6295 else {
6296 TClauses.push_back(0);
6297 }
6298 }
Alexey Bataev0c018352013-09-06 18:03:48 +00006299 if (!D->getAssociatedStmt()) {
6300 getSema().EndOpenMPDSABlock(0);
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006301 return StmtError();
Alexey Bataev0c018352013-09-06 18:03:48 +00006302 }
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006303 StmtResult AssociatedStmt =
6304 getDerived().TransformStmt(D->getAssociatedStmt());
Alexey Bataev0c018352013-09-06 18:03:48 +00006305 if (AssociatedStmt.isInvalid()) {
6306 getSema().EndOpenMPDSABlock(0);
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006307 return StmtError();
Alexey Bataev0c018352013-09-06 18:03:48 +00006308 }
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006309
Alexey Bataev0c018352013-09-06 18:03:48 +00006310 StmtResult Res = getDerived().RebuildOMPParallelDirective(TClauses,
6311 AssociatedStmt.take(),
6312 D->getLocStart(),
6313 D->getLocEnd());
6314 getSema().EndOpenMPDSABlock(Res.get());
6315 return Res;
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006316}
6317
6318template<typename Derived>
6319OMPClause *
6320TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
6321 return getDerived().RebuildOMPDefaultClause(C->getDefaultKind(),
6322 C->getDefaultKindKwLoc(),
6323 C->getLocStart(),
6324 C->getLParenLoc(),
6325 C->getLocEnd());
6326}
6327
6328template<typename Derived>
6329OMPClause *
6330TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
Alexey Bataev0c018352013-09-06 18:03:48 +00006331 llvm::SmallVector<Expr *, 16> Vars;
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006332 Vars.reserve(C->varlist_size());
Alexey Bataev543c4ae2013-09-24 03:17:45 +00006333 for (OMPPrivateClause::varlist_iterator I = C->varlist_begin(),
6334 E = C->varlist_end();
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006335 I != E; ++I) {
6336 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(*I));
6337 if (EVar.isInvalid())
6338 return 0;
6339 Vars.push_back(EVar.take());
6340 }
6341 return getDerived().RebuildOMPPrivateClause(Vars,
6342 C->getLocStart(),
6343 C->getLParenLoc(),
6344 C->getLocEnd());
6345}
6346
Alexey Bataev0c018352013-09-06 18:03:48 +00006347template<typename Derived>
6348OMPClause *
Alexey Bataevd195bc32013-10-01 05:32:34 +00006349TreeTransform<Derived>::TransformOMPFirstprivateClause(
6350 OMPFirstprivateClause *C) {
6351 llvm::SmallVector<Expr *, 16> Vars;
6352 Vars.reserve(C->varlist_size());
6353 for (OMPFirstprivateClause::varlist_iterator I = C->varlist_begin(),
6354 E = C->varlist_end();
6355 I != E; ++I) {
6356 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(*I));
6357 if (EVar.isInvalid())
6358 return 0;
6359 Vars.push_back(EVar.take());
6360 }
6361 return getDerived().RebuildOMPFirstprivateClause(Vars,
6362 C->getLocStart(),
6363 C->getLParenLoc(),
6364 C->getLocEnd());
6365}
6366
6367template<typename Derived>
6368OMPClause *
Alexey Bataev0c018352013-09-06 18:03:48 +00006369TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
6370 llvm::SmallVector<Expr *, 16> Vars;
6371 Vars.reserve(C->varlist_size());
Alexey Bataev543c4ae2013-09-24 03:17:45 +00006372 for (OMPSharedClause::varlist_iterator I = C->varlist_begin(),
6373 E = C->varlist_end();
Alexey Bataev0c018352013-09-06 18:03:48 +00006374 I != E; ++I) {
6375 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(*I));
6376 if (EVar.isInvalid())
6377 return 0;
6378 Vars.push_back(EVar.take());
6379 }
6380 return getDerived().RebuildOMPSharedClause(Vars,
6381 C->getLocStart(),
6382 C->getLParenLoc(),
6383 C->getLocEnd());
6384}
6385
Douglas Gregor43959a92009-08-20 07:17:43 +00006386//===----------------------------------------------------------------------===//
Douglas Gregorb98b1992009-08-11 05:31:07 +00006387// Expression transformation
6388//===----------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +00006389template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006390ExprResult
John McCall454feb92009-12-08 09:21:05 +00006391TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006392 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006393}
Mike Stump1eb44332009-09-09 15:08:12 +00006394
6395template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006396ExprResult
John McCall454feb92009-12-08 09:21:05 +00006397TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006398 NestedNameSpecifierLoc QualifierLoc;
6399 if (E->getQualifierLoc()) {
6400 QualifierLoc
6401 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6402 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006403 return ExprError();
Douglas Gregora2813ce2009-10-23 18:54:35 +00006404 }
John McCalldbd872f2009-12-08 09:08:17 +00006405
6406 ValueDecl *ND
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006407 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6408 E->getDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006409 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00006410 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006411
John McCallec8045d2010-08-17 21:27:17 +00006412 DeclarationNameInfo NameInfo = E->getNameInfo();
6413 if (NameInfo.getName()) {
6414 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6415 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00006416 return ExprError();
John McCallec8045d2010-08-17 21:27:17 +00006417 }
Abramo Bagnara25777432010-08-11 22:01:17 +00006418
6419 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006420 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregora2813ce2009-10-23 18:54:35 +00006421 ND == E->getDecl() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00006422 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCall096832c2010-08-19 23:49:38 +00006423 !E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00006424
6425 // Mark it referenced in the new context regardless.
6426 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00006427 SemaRef.MarkDeclRefReferenced(E);
John McCalldbd872f2009-12-08 09:08:17 +00006428
John McCall3fa5cae2010-10-26 07:05:15 +00006429 return SemaRef.Owned(E);
Douglas Gregora2813ce2009-10-23 18:54:35 +00006430 }
John McCalldbd872f2009-12-08 09:08:17 +00006431
6432 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCall096832c2010-08-19 23:49:38 +00006433 if (E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00006434 TemplateArgs = &TransArgs;
6435 TransArgs.setLAngleLoc(E->getLAngleLoc());
6436 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006437 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6438 E->getNumTemplateArgs(),
6439 TransArgs))
6440 return ExprError();
John McCalldbd872f2009-12-08 09:08:17 +00006441 }
6442
Chad Rosier4a9d7952012-08-08 18:46:20 +00006443 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregor40d96a62011-02-28 21:54:11 +00006444 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006445}
Mike Stump1eb44332009-09-09 15:08:12 +00006446
Douglas Gregorb98b1992009-08-11 05:31:07 +00006447template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006448ExprResult
John McCall454feb92009-12-08 09:21:05 +00006449TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006450 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006451}
Mike Stump1eb44332009-09-09 15:08:12 +00006452
Douglas Gregorb98b1992009-08-11 05:31:07 +00006453template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006454ExprResult
John McCall454feb92009-12-08 09:21:05 +00006455TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006456 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006457}
Mike Stump1eb44332009-09-09 15:08:12 +00006458
Douglas Gregorb98b1992009-08-11 05:31:07 +00006459template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006460ExprResult
John McCall454feb92009-12-08 09:21:05 +00006461TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006462 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006463}
Mike Stump1eb44332009-09-09 15:08:12 +00006464
Douglas Gregorb98b1992009-08-11 05:31:07 +00006465template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006466ExprResult
John McCall454feb92009-12-08 09:21:05 +00006467TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006468 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006469}
Mike Stump1eb44332009-09-09 15:08:12 +00006470
Douglas Gregorb98b1992009-08-11 05:31:07 +00006471template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006472ExprResult
John McCall454feb92009-12-08 09:21:05 +00006473TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006474 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006475}
6476
6477template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006478ExprResult
Richard Smith9fcce652012-03-07 08:35:16 +00006479TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
Argyrios Kyrtzidis391ca9f2013-04-09 01:17:02 +00006480 if (FunctionDecl *FD = E->getDirectCallee())
6481 SemaRef.MarkFunctionReferenced(E->getLocStart(), FD);
Richard Smith9fcce652012-03-07 08:35:16 +00006482 return SemaRef.MaybeBindToTemporary(E);
6483}
6484
6485template<typename Derived>
6486ExprResult
Peter Collingbournef111d932011-04-15 00:35:48 +00006487TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
6488 ExprResult ControllingExpr =
6489 getDerived().TransformExpr(E->getControllingExpr());
6490 if (ControllingExpr.isInvalid())
6491 return ExprError();
6492
Chris Lattner686775d2011-07-20 06:58:45 +00006493 SmallVector<Expr *, 4> AssocExprs;
6494 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbournef111d932011-04-15 00:35:48 +00006495 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
6496 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
6497 if (TS) {
6498 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
6499 if (!AssocType)
6500 return ExprError();
6501 AssocTypes.push_back(AssocType);
6502 } else {
6503 AssocTypes.push_back(0);
6504 }
6505
6506 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
6507 if (AssocExpr.isInvalid())
6508 return ExprError();
6509 AssocExprs.push_back(AssocExpr.release());
6510 }
6511
6512 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
6513 E->getDefaultLoc(),
6514 E->getRParenLoc(),
6515 ControllingExpr.release(),
Dmitri Gribenko80613222013-05-10 13:06:58 +00006516 AssocTypes,
6517 AssocExprs);
Peter Collingbournef111d932011-04-15 00:35:48 +00006518}
6519
6520template<typename Derived>
6521ExprResult
John McCall454feb92009-12-08 09:21:05 +00006522TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006523 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006524 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006525 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006526
Douglas Gregorb98b1992009-08-11 05:31:07 +00006527 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006528 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006529
John McCall9ae2f072010-08-23 23:25:46 +00006530 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006531 E->getRParen());
6532}
6533
Richard Smithefeeccf2012-10-21 03:28:35 +00006534/// \brief The operand of a unary address-of operator has special rules: it's
6535/// allowed to refer to a non-static member of a class even if there's no 'this'
6536/// object available.
6537template<typename Derived>
6538ExprResult
6539TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
6540 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
6541 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true);
6542 else
6543 return getDerived().TransformExpr(E);
6544}
6545
Mike Stump1eb44332009-09-09 15:08:12 +00006546template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006547ExprResult
John McCall454feb92009-12-08 09:21:05 +00006548TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smith82b00012013-05-21 23:29:46 +00006549 ExprResult SubExpr;
6550 if (E->getOpcode() == UO_AddrOf)
6551 SubExpr = TransformAddressOfOperand(E->getSubExpr());
6552 else
6553 SubExpr = TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006554 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006555 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006556
Douglas Gregorb98b1992009-08-11 05:31:07 +00006557 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006558 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006559
Douglas Gregorb98b1992009-08-11 05:31:07 +00006560 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
6561 E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006562 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006563}
Mike Stump1eb44332009-09-09 15:08:12 +00006564
Douglas Gregorb98b1992009-08-11 05:31:07 +00006565template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006566ExprResult
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006567TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
6568 // Transform the type.
6569 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
6570 if (!Type)
John McCallf312b1e2010-08-26 23:41:50 +00006571 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006572
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006573 // Transform all of the components into components similar to what the
6574 // parser uses.
Chad Rosier4a9d7952012-08-08 18:46:20 +00006575 // FIXME: It would be slightly more efficient in the non-dependent case to
6576 // just map FieldDecls, rather than requiring the rebuilder to look for
6577 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006578 // template code that we don't care.
6579 bool ExprChanged = false;
John McCallf312b1e2010-08-26 23:41:50 +00006580 typedef Sema::OffsetOfComponent Component;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006581 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner686775d2011-07-20 06:58:45 +00006582 SmallVector<Component, 4> Components;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006583 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
6584 const Node &ON = E->getComponent(I);
6585 Component Comp;
Douglas Gregor72be24f2010-04-30 20:35:01 +00006586 Comp.isBrackets = true;
Abramo Bagnara06dec892011-03-12 09:45:03 +00006587 Comp.LocStart = ON.getSourceRange().getBegin();
6588 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006589 switch (ON.getKind()) {
6590 case Node::Array: {
6591 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCall60d7b3a2010-08-24 06:29:42 +00006592 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006593 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006594 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006595
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006596 ExprChanged = ExprChanged || Index.get() != FromIndex;
6597 Comp.isBrackets = true;
John McCall9ae2f072010-08-23 23:25:46 +00006598 Comp.U.E = Index.get();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006599 break;
6600 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006601
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006602 case Node::Field:
6603 case Node::Identifier:
6604 Comp.isBrackets = false;
6605 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregor29d2fd52010-04-28 22:43:14 +00006606 if (!Comp.U.IdentInfo)
6607 continue;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006608
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006609 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006610
Douglas Gregorcc8a5d52010-04-29 00:18:15 +00006611 case Node::Base:
6612 // Will be recomputed during the rebuild.
6613 continue;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006614 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006615
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006616 Components.push_back(Comp);
6617 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006618
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006619 // If nothing changed, retain the existing expression.
6620 if (!getDerived().AlwaysRebuild() &&
6621 Type == E->getTypeSourceInfo() &&
6622 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006623 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00006624
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006625 // Build a new offsetof expression.
6626 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
6627 Components.data(), Components.size(),
6628 E->getRParenLoc());
6629}
6630
6631template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006632ExprResult
John McCall7cd7d1a2010-11-15 23:31:06 +00006633TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
6634 assert(getDerived().AlreadyTransformed(E->getType()) &&
6635 "opaque value expression requires transformation");
6636 return SemaRef.Owned(E);
6637}
6638
6639template<typename Derived>
6640ExprResult
John McCall4b9c2d22011-11-06 09:01:30 +00006641TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCall01e19be2011-11-30 04:42:31 +00006642 // Rebuild the syntactic form. The original syntactic form has
6643 // opaque-value expressions in it, so strip those away and rebuild
6644 // the result. This is a really awful way of doing this, but the
6645 // better solution (rebuilding the semantic expressions and
6646 // rebinding OVEs as necessary) doesn't work; we'd need
6647 // TreeTransform to not strip away implicit conversions.
6648 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
6649 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCall4b9c2d22011-11-06 09:01:30 +00006650 if (result.isInvalid()) return ExprError();
6651
6652 // If that gives us a pseudo-object result back, the pseudo-object
6653 // expression must have been an lvalue-to-rvalue conversion which we
6654 // should reapply.
6655 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
6656 result = SemaRef.checkPseudoObjectRValue(result.take());
6657
6658 return result;
6659}
6660
6661template<typename Derived>
6662ExprResult
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006663TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
6664 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006665 if (E->isArgumentType()) {
John McCalla93c9342009-12-07 02:54:59 +00006666 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor5557b252009-10-28 00:29:27 +00006667
John McCalla93c9342009-12-07 02:54:59 +00006668 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall5ab75172009-11-04 07:28:41 +00006669 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006670 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006671
John McCall5ab75172009-11-04 07:28:41 +00006672 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCall3fa5cae2010-10-26 07:05:15 +00006673 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006674
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006675 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
6676 E->getKind(),
6677 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006678 }
Mike Stump1eb44332009-09-09 15:08:12 +00006679
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006680 // C++0x [expr.sizeof]p1:
6681 // The operand is either an expression, which is an unevaluated operand
6682 // [...]
Eli Friedman80bfa3d2012-09-26 04:34:21 +00006683 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
6684 Sema::ReuseLambdaContextDecl);
Mike Stump1eb44332009-09-09 15:08:12 +00006685
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006686 ExprResult SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
6687 if (SubExpr.isInvalid())
6688 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006689
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006690 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
6691 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006692
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006693 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
6694 E->getOperatorLoc(),
6695 E->getKind(),
6696 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006697}
Mike Stump1eb44332009-09-09 15:08:12 +00006698
Douglas Gregorb98b1992009-08-11 05:31:07 +00006699template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006700ExprResult
John McCall454feb92009-12-08 09:21:05 +00006701TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006702 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006703 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006704 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006705
John McCall60d7b3a2010-08-24 06:29:42 +00006706 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006707 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006708 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006709
6710
Douglas Gregorb98b1992009-08-11 05:31:07 +00006711 if (!getDerived().AlwaysRebuild() &&
6712 LHS.get() == E->getLHS() &&
6713 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006714 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006715
John McCall9ae2f072010-08-23 23:25:46 +00006716 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006717 /*FIXME:*/E->getLHS()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006718 RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006719 E->getRBracketLoc());
6720}
Mike Stump1eb44332009-09-09 15:08:12 +00006721
6722template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006723ExprResult
John McCall454feb92009-12-08 09:21:05 +00006724TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006725 // Transform the callee.
John McCall60d7b3a2010-08-24 06:29:42 +00006726 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006727 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006728 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006729
6730 // Transform arguments.
6731 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006732 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006733 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00006734 &ArgChanged))
6735 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006736
Douglas Gregorb98b1992009-08-11 05:31:07 +00006737 if (!getDerived().AlwaysRebuild() &&
6738 Callee.get() == E->getCallee() &&
6739 !ArgChanged)
Dmitri Gribenko1ad23d62012-09-10 21:20:09 +00006740 return SemaRef.MaybeBindToTemporary(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006741
Douglas Gregorb98b1992009-08-11 05:31:07 +00006742 // FIXME: Wrong source location information for the '('.
Mike Stump1eb44332009-09-09 15:08:12 +00006743 SourceLocation FakeLParenLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006744 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCall9ae2f072010-08-23 23:25:46 +00006745 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006746 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006747 E->getRParenLoc());
6748}
Mike Stump1eb44332009-09-09 15:08:12 +00006749
6750template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006751ExprResult
John McCall454feb92009-12-08 09:21:05 +00006752TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006753 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006754 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006755 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006756
Douglas Gregor40d96a62011-02-28 21:54:11 +00006757 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006758 if (E->hasQualifier()) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006759 QualifierLoc
6760 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00006761
Douglas Gregor40d96a62011-02-28 21:54:11 +00006762 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006763 return ExprError();
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006764 }
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006765 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00006766
Eli Friedmanf595cc42009-12-04 06:40:45 +00006767 ValueDecl *Member
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006768 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
6769 E->getMemberDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006770 if (!Member)
John McCallf312b1e2010-08-26 23:41:50 +00006771 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006772
John McCall6bb80172010-03-30 21:47:33 +00006773 NamedDecl *FoundDecl = E->getFoundDecl();
6774 if (FoundDecl == E->getMemberDecl()) {
6775 FoundDecl = Member;
6776 } else {
6777 FoundDecl = cast_or_null<NamedDecl>(
6778 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
6779 if (!FoundDecl)
John McCallf312b1e2010-08-26 23:41:50 +00006780 return ExprError();
John McCall6bb80172010-03-30 21:47:33 +00006781 }
6782
Douglas Gregorb98b1992009-08-11 05:31:07 +00006783 if (!getDerived().AlwaysRebuild() &&
6784 Base.get() == E->getBase() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006785 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006786 Member == E->getMemberDecl() &&
John McCall6bb80172010-03-30 21:47:33 +00006787 FoundDecl == E->getFoundDecl() &&
John McCall096832c2010-08-19 23:49:38 +00006788 !E->hasExplicitTemplateArgs()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00006789
Anders Carlsson1f240322009-12-22 05:24:09 +00006790 // Mark it referenced in the new context regardless.
6791 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00006792 SemaRef.MarkMemberReferenced(E);
6793
John McCall3fa5cae2010-10-26 07:05:15 +00006794 return SemaRef.Owned(E);
Anders Carlsson1f240322009-12-22 05:24:09 +00006795 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00006796
John McCalld5532b62009-11-23 01:53:49 +00006797 TemplateArgumentListInfo TransArgs;
John McCall096832c2010-08-19 23:49:38 +00006798 if (E->hasExplicitTemplateArgs()) {
John McCalld5532b62009-11-23 01:53:49 +00006799 TransArgs.setLAngleLoc(E->getLAngleLoc());
6800 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006801 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6802 E->getNumTemplateArgs(),
6803 TransArgs))
6804 return ExprError();
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006805 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006806
Douglas Gregorb98b1992009-08-11 05:31:07 +00006807 // FIXME: Bogus source location for the operator
6808 SourceLocation FakeOperatorLoc
6809 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
6810
John McCallc2233c52010-01-15 08:34:02 +00006811 // FIXME: to do this check properly, we will need to preserve the
6812 // first-qualifier-in-scope here, just in case we had a dependent
6813 // base (and therefore couldn't do the check) and a
6814 // nested-name-qualifier (and therefore could do the lookup).
6815 NamedDecl *FirstQualifierInScope = 0;
6816
John McCall9ae2f072010-08-23 23:25:46 +00006817 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006818 E->isArrow(),
Douglas Gregor40d96a62011-02-28 21:54:11 +00006819 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006820 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00006821 E->getMemberNameInfo(),
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006822 Member,
John McCall6bb80172010-03-30 21:47:33 +00006823 FoundDecl,
John McCall096832c2010-08-19 23:49:38 +00006824 (E->hasExplicitTemplateArgs()
John McCalld5532b62009-11-23 01:53:49 +00006825 ? &TransArgs : 0),
John McCallc2233c52010-01-15 08:34:02 +00006826 FirstQualifierInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006827}
Mike Stump1eb44332009-09-09 15:08:12 +00006828
Douglas Gregorb98b1992009-08-11 05:31:07 +00006829template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006830ExprResult
John McCall454feb92009-12-08 09:21:05 +00006831TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006832 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006833 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006834 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006835
John McCall60d7b3a2010-08-24 06:29:42 +00006836 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006837 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006838 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006839
Douglas Gregorb98b1992009-08-11 05:31:07 +00006840 if (!getDerived().AlwaysRebuild() &&
6841 LHS.get() == E->getLHS() &&
6842 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006843 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006844
Lang Hamesbe9af122012-10-02 04:45:10 +00006845 Sema::FPContractStateRAII FPContractState(getSema());
6846 getSema().FPFeatures.fp_contract = E->isFPContractable();
6847
Douglas Gregorb98b1992009-08-11 05:31:07 +00006848 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006849 LHS.get(), RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006850}
6851
Mike Stump1eb44332009-09-09 15:08:12 +00006852template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006853ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006854TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall454feb92009-12-08 09:21:05 +00006855 CompoundAssignOperator *E) {
6856 return getDerived().TransformBinaryOperator(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006857}
Mike Stump1eb44332009-09-09 15:08:12 +00006858
Douglas Gregorb98b1992009-08-11 05:31:07 +00006859template<typename Derived>
John McCall56ca35d2011-02-17 10:25:35 +00006860ExprResult TreeTransform<Derived>::
6861TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
6862 // Just rebuild the common and RHS expressions and see whether we
6863 // get any changes.
6864
6865 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
6866 if (commonExpr.isInvalid())
6867 return ExprError();
6868
6869 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
6870 if (rhs.isInvalid())
6871 return ExprError();
6872
6873 if (!getDerived().AlwaysRebuild() &&
6874 commonExpr.get() == e->getCommon() &&
6875 rhs.get() == e->getFalseExpr())
6876 return SemaRef.Owned(e);
6877
6878 return getDerived().RebuildConditionalOperator(commonExpr.take(),
6879 e->getQuestionLoc(),
6880 0,
6881 e->getColonLoc(),
6882 rhs.get());
6883}
6884
6885template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006886ExprResult
John McCall454feb92009-12-08 09:21:05 +00006887TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006888 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006889 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006890 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006891
John McCall60d7b3a2010-08-24 06:29:42 +00006892 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006893 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006894 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006895
John McCall60d7b3a2010-08-24 06:29:42 +00006896 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006897 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006898 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006899
Douglas Gregorb98b1992009-08-11 05:31:07 +00006900 if (!getDerived().AlwaysRebuild() &&
6901 Cond.get() == E->getCond() &&
6902 LHS.get() == E->getLHS() &&
6903 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006904 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006905
John McCall9ae2f072010-08-23 23:25:46 +00006906 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006907 E->getQuestionLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006908 LHS.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006909 E->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006910 RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006911}
Mike Stump1eb44332009-09-09 15:08:12 +00006912
6913template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006914ExprResult
John McCall454feb92009-12-08 09:21:05 +00006915TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora88cfbf2009-12-12 18:16:41 +00006916 // Implicit casts are eliminated during transformation, since they
6917 // will be recomputed by semantic analysis after transformation.
Douglas Gregor6eef5192009-12-14 19:27:10 +00006918 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006919}
Mike Stump1eb44332009-09-09 15:08:12 +00006920
Douglas Gregorb98b1992009-08-11 05:31:07 +00006921template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006922ExprResult
John McCall454feb92009-12-08 09:21:05 +00006923TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006924 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6925 if (!Type)
6926 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006927
John McCall60d7b3a2010-08-24 06:29:42 +00006928 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006929 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006930 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006931 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006932
Douglas Gregorb98b1992009-08-11 05:31:07 +00006933 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006934 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006935 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006936 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006937
John McCall9d125032010-01-15 18:39:57 +00006938 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006939 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006940 E->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006941 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006942}
Mike Stump1eb44332009-09-09 15:08:12 +00006943
Douglas Gregorb98b1992009-08-11 05:31:07 +00006944template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006945ExprResult
John McCall454feb92009-12-08 09:21:05 +00006946TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCall42f56b52010-01-18 19:35:47 +00006947 TypeSourceInfo *OldT = E->getTypeSourceInfo();
6948 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
6949 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006950 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006951
John McCall60d7b3a2010-08-24 06:29:42 +00006952 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006953 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006954 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006955
Douglas Gregorb98b1992009-08-11 05:31:07 +00006956 if (!getDerived().AlwaysRebuild() &&
John McCall42f56b52010-01-18 19:35:47 +00006957 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006958 Init.get() == E->getInitializer())
Douglas Gregor92be2a52011-12-10 00:23:21 +00006959 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006960
John McCall1d7d8d62010-01-19 22:33:45 +00006961 // Note: the expression type doesn't necessarily match the
6962 // type-as-written, but that's okay, because it should always be
6963 // derivable from the initializer.
6964
John McCall42f56b52010-01-18 19:35:47 +00006965 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006966 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00006967 Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006968}
Mike Stump1eb44332009-09-09 15:08:12 +00006969
Douglas Gregorb98b1992009-08-11 05:31:07 +00006970template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006971ExprResult
John McCall454feb92009-12-08 09:21:05 +00006972TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006973 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006974 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006975 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006976
Douglas Gregorb98b1992009-08-11 05:31:07 +00006977 if (!getDerived().AlwaysRebuild() &&
6978 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00006979 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006980
Douglas Gregorb98b1992009-08-11 05:31:07 +00006981 // FIXME: Bad source location
Mike Stump1eb44332009-09-09 15:08:12 +00006982 SourceLocation FakeOperatorLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006983 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCall9ae2f072010-08-23 23:25:46 +00006984 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006985 E->getAccessorLoc(),
6986 E->getAccessor());
6987}
Mike Stump1eb44332009-09-09 15:08:12 +00006988
Douglas Gregorb98b1992009-08-11 05:31:07 +00006989template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006990ExprResult
John McCall454feb92009-12-08 09:21:05 +00006991TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006992 bool InitChanged = false;
Mike Stump1eb44332009-09-09 15:08:12 +00006993
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006994 SmallVector<Expr*, 4> Inits;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006995 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregoraa165f82011-01-03 19:04:46 +00006996 Inits, &InitChanged))
6997 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006998
Douglas Gregorb98b1992009-08-11 05:31:07 +00006999 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00007000 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007001
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007002 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Douglas Gregore48319a2009-11-09 17:16:50 +00007003 E->getRBraceLoc(), E->getType());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007004}
Mike Stump1eb44332009-09-09 15:08:12 +00007005
Douglas Gregorb98b1992009-08-11 05:31:07 +00007006template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007007ExprResult
John McCall454feb92009-12-08 09:21:05 +00007008TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007009 Designation Desig;
Mike Stump1eb44332009-09-09 15:08:12 +00007010
Douglas Gregor43959a92009-08-20 07:17:43 +00007011 // transform the initializer value
John McCall60d7b3a2010-08-24 06:29:42 +00007012 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007013 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007014 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007015
Douglas Gregor43959a92009-08-20 07:17:43 +00007016 // transform the designators.
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007017 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregorb98b1992009-08-11 05:31:07 +00007018 bool ExprChanged = false;
7019 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
7020 DEnd = E->designators_end();
7021 D != DEnd; ++D) {
7022 if (D->isFieldDesignator()) {
7023 Desig.AddDesignator(Designator::getField(D->getFieldName(),
7024 D->getDotLoc(),
7025 D->getFieldLoc()));
7026 continue;
7027 }
Mike Stump1eb44332009-09-09 15:08:12 +00007028
Douglas Gregorb98b1992009-08-11 05:31:07 +00007029 if (D->isArrayDesignator()) {
John McCall60d7b3a2010-08-24 06:29:42 +00007030 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007031 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007032 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007033
7034 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007035 D->getLBracketLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00007036
Douglas Gregorb98b1992009-08-11 05:31:07 +00007037 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
7038 ArrayExprs.push_back(Index.release());
7039 continue;
7040 }
Mike Stump1eb44332009-09-09 15:08:12 +00007041
Douglas Gregorb98b1992009-08-11 05:31:07 +00007042 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCall60d7b3a2010-08-24 06:29:42 +00007043 ExprResult Start
Douglas Gregorb98b1992009-08-11 05:31:07 +00007044 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
7045 if (Start.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007046 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007047
John McCall60d7b3a2010-08-24 06:29:42 +00007048 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007049 if (End.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007050 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007051
7052 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007053 End.get(),
7054 D->getLBracketLoc(),
7055 D->getEllipsisLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00007056
Douglas Gregorb98b1992009-08-11 05:31:07 +00007057 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
7058 End.get() != E->getArrayRangeEnd(*D);
Mike Stump1eb44332009-09-09 15:08:12 +00007059
Douglas Gregorb98b1992009-08-11 05:31:07 +00007060 ArrayExprs.push_back(Start.release());
7061 ArrayExprs.push_back(End.release());
7062 }
Mike Stump1eb44332009-09-09 15:08:12 +00007063
Douglas Gregorb98b1992009-08-11 05:31:07 +00007064 if (!getDerived().AlwaysRebuild() &&
7065 Init.get() == E->getInit() &&
7066 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00007067 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007068
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007069 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007070 E->getEqualOrColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00007071 E->usesGNUSyntax(), Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007072}
Mike Stump1eb44332009-09-09 15:08:12 +00007073
Douglas Gregorb98b1992009-08-11 05:31:07 +00007074template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007075ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007076TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall454feb92009-12-08 09:21:05 +00007077 ImplicitValueInitExpr *E) {
Douglas Gregor5557b252009-10-28 00:29:27 +00007078 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007079
Douglas Gregor5557b252009-10-28 00:29:27 +00007080 // FIXME: Will we ever have proper type location here? Will we actually
7081 // need to transform the type?
Douglas Gregorb98b1992009-08-11 05:31:07 +00007082 QualType T = getDerived().TransformType(E->getType());
7083 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00007084 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007085
Douglas Gregorb98b1992009-08-11 05:31:07 +00007086 if (!getDerived().AlwaysRebuild() &&
7087 T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00007088 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007089
Douglas Gregorb98b1992009-08-11 05:31:07 +00007090 return getDerived().RebuildImplicitValueInitExpr(T);
7091}
Mike Stump1eb44332009-09-09 15:08:12 +00007092
Douglas Gregorb98b1992009-08-11 05:31:07 +00007093template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007094ExprResult
John McCall454feb92009-12-08 09:21:05 +00007095TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00007096 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
7097 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007098 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007099
John McCall60d7b3a2010-08-24 06:29:42 +00007100 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007101 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007102 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007103
Douglas Gregorb98b1992009-08-11 05:31:07 +00007104 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara2cad9002010-08-10 10:06:15 +00007105 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007106 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007107 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007108
John McCall9ae2f072010-08-23 23:25:46 +00007109 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara2cad9002010-08-10 10:06:15 +00007110 TInfo, E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007111}
7112
7113template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007114ExprResult
John McCall454feb92009-12-08 09:21:05 +00007115TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007116 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007117 SmallVector<Expr*, 4> Inits;
Douglas Gregoraa165f82011-01-03 19:04:46 +00007118 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
7119 &ArgumentChanged))
7120 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007121
Douglas Gregorb98b1992009-08-11 05:31:07 +00007122 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007123 Inits,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007124 E->getRParenLoc());
7125}
Mike Stump1eb44332009-09-09 15:08:12 +00007126
Douglas Gregorb98b1992009-08-11 05:31:07 +00007127/// \brief Transform an address-of-label expression.
7128///
7129/// By default, the transformation of an address-of-label expression always
7130/// rebuilds the expression, so that the label identifier can be resolved to
7131/// the corresponding label statement by semantic analysis.
7132template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007133ExprResult
John McCall454feb92009-12-08 09:21:05 +00007134TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattner57ad3782011-02-17 20:34:02 +00007135 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
7136 E->getLabel());
7137 if (!LD)
7138 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007139
Douglas Gregorb98b1992009-08-11 05:31:07 +00007140 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00007141 cast<LabelDecl>(LD));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007142}
Mike Stump1eb44332009-09-09 15:08:12 +00007143
7144template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00007145ExprResult
John McCall454feb92009-12-08 09:21:05 +00007146TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCall7f39d512012-04-06 18:20:53 +00007147 SemaRef.ActOnStartStmtExpr();
John McCall60d7b3a2010-08-24 06:29:42 +00007148 StmtResult SubStmt
Douglas Gregorb98b1992009-08-11 05:31:07 +00007149 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCall7f39d512012-04-06 18:20:53 +00007150 if (SubStmt.isInvalid()) {
7151 SemaRef.ActOnStmtExprError();
John McCallf312b1e2010-08-26 23:41:50 +00007152 return ExprError();
John McCall7f39d512012-04-06 18:20:53 +00007153 }
Mike Stump1eb44332009-09-09 15:08:12 +00007154
Douglas Gregorb98b1992009-08-11 05:31:07 +00007155 if (!getDerived().AlwaysRebuild() &&
John McCall7f39d512012-04-06 18:20:53 +00007156 SubStmt.get() == E->getSubStmt()) {
7157 // Calling this an 'error' is unintuitive, but it does the right thing.
7158 SemaRef.ActOnStmtExprError();
Douglas Gregor92be2a52011-12-10 00:23:21 +00007159 return SemaRef.MaybeBindToTemporary(E);
John McCall7f39d512012-04-06 18:20:53 +00007160 }
Mike Stump1eb44332009-09-09 15:08:12 +00007161
7162 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00007163 SubStmt.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007164 E->getRParenLoc());
7165}
Mike Stump1eb44332009-09-09 15:08:12 +00007166
Douglas Gregorb98b1992009-08-11 05:31:07 +00007167template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007168ExprResult
John McCall454feb92009-12-08 09:21:05 +00007169TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007170 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007171 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007172 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007173
John McCall60d7b3a2010-08-24 06:29:42 +00007174 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007175 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007176 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007177
John McCall60d7b3a2010-08-24 06:29:42 +00007178 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007179 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007180 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007181
Douglas Gregorb98b1992009-08-11 05:31:07 +00007182 if (!getDerived().AlwaysRebuild() &&
7183 Cond.get() == E->getCond() &&
7184 LHS.get() == E->getLHS() &&
7185 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00007186 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007187
Douglas Gregorb98b1992009-08-11 05:31:07 +00007188 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00007189 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007190 E->getRParenLoc());
7191}
Mike Stump1eb44332009-09-09 15:08:12 +00007192
Douglas Gregorb98b1992009-08-11 05:31:07 +00007193template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007194ExprResult
John McCall454feb92009-12-08 09:21:05 +00007195TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007196 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007197}
7198
7199template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007200ExprResult
John McCall454feb92009-12-08 09:21:05 +00007201TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregor668d6d92009-12-13 20:44:55 +00007202 switch (E->getOperator()) {
7203 case OO_New:
7204 case OO_Delete:
7205 case OO_Array_New:
7206 case OO_Array_Delete:
7207 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier4a9d7952012-08-08 18:46:20 +00007208
Douglas Gregor668d6d92009-12-13 20:44:55 +00007209 case OO_Call: {
7210 // This is a call to an object's operator().
7211 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
7212
7213 // Transform the object itself.
John McCall60d7b3a2010-08-24 06:29:42 +00007214 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregor668d6d92009-12-13 20:44:55 +00007215 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007216 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00007217
7218 // FIXME: Poor location information
7219 SourceLocation FakeLParenLoc
7220 = SemaRef.PP.getLocForEndOfToken(
7221 static_cast<Expr *>(Object.get())->getLocEnd());
7222
7223 // Transform the call arguments.
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007224 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007225 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregoraa165f82011-01-03 19:04:46 +00007226 Args))
7227 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00007228
John McCall9ae2f072010-08-23 23:25:46 +00007229 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007230 Args,
Douglas Gregor668d6d92009-12-13 20:44:55 +00007231 E->getLocEnd());
7232 }
7233
7234#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
7235 case OO_##Name:
7236#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
7237#include "clang/Basic/OperatorKinds.def"
7238 case OO_Subscript:
7239 // Handled below.
7240 break;
7241
7242 case OO_Conditional:
7243 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregor668d6d92009-12-13 20:44:55 +00007244
7245 case OO_None:
7246 case NUM_OVERLOADED_OPERATORS:
7247 llvm_unreachable("not an overloaded operator?");
Douglas Gregor668d6d92009-12-13 20:44:55 +00007248 }
7249
John McCall60d7b3a2010-08-24 06:29:42 +00007250 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007251 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007252 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007253
Richard Smithefeeccf2012-10-21 03:28:35 +00007254 ExprResult First;
7255 if (E->getOperator() == OO_Amp)
7256 First = getDerived().TransformAddressOfOperand(E->getArg(0));
7257 else
7258 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007259 if (First.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007260 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007261
John McCall60d7b3a2010-08-24 06:29:42 +00007262 ExprResult Second;
Douglas Gregorb98b1992009-08-11 05:31:07 +00007263 if (E->getNumArgs() == 2) {
7264 Second = getDerived().TransformExpr(E->getArg(1));
7265 if (Second.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007266 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007267 }
Mike Stump1eb44332009-09-09 15:08:12 +00007268
Douglas Gregorb98b1992009-08-11 05:31:07 +00007269 if (!getDerived().AlwaysRebuild() &&
7270 Callee.get() == E->getCallee() &&
7271 First.get() == E->getArg(0) &&
Mike Stump1eb44332009-09-09 15:08:12 +00007272 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregor92be2a52011-12-10 00:23:21 +00007273 return SemaRef.MaybeBindToTemporary(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007274
Lang Hamesbe9af122012-10-02 04:45:10 +00007275 Sema::FPContractStateRAII FPContractState(getSema());
7276 getSema().FPFeatures.fp_contract = E->isFPContractable();
7277
Douglas Gregorb98b1992009-08-11 05:31:07 +00007278 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
7279 E->getOperatorLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00007280 Callee.get(),
7281 First.get(),
7282 Second.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007283}
Mike Stump1eb44332009-09-09 15:08:12 +00007284
Douglas Gregorb98b1992009-08-11 05:31:07 +00007285template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007286ExprResult
John McCall454feb92009-12-08 09:21:05 +00007287TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
7288 return getDerived().TransformCallExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007289}
Mike Stump1eb44332009-09-09 15:08:12 +00007290
Douglas Gregorb98b1992009-08-11 05:31:07 +00007291template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007292ExprResult
Peter Collingbournee08ce652011-02-09 21:07:24 +00007293TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
7294 // Transform the callee.
7295 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
7296 if (Callee.isInvalid())
7297 return ExprError();
7298
7299 // Transform exec config.
7300 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
7301 if (EC.isInvalid())
7302 return ExprError();
7303
7304 // Transform arguments.
7305 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007306 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007307 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00007308 &ArgChanged))
7309 return ExprError();
7310
7311 if (!getDerived().AlwaysRebuild() &&
7312 Callee.get() == E->getCallee() &&
7313 !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00007314 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbournee08ce652011-02-09 21:07:24 +00007315
7316 // FIXME: Wrong source location information for the '('.
7317 SourceLocation FakeLParenLoc
7318 = ((Expr *)Callee.get())->getSourceRange().getBegin();
7319 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007320 Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00007321 E->getRParenLoc(), EC.get());
7322}
7323
7324template<typename Derived>
7325ExprResult
John McCall454feb92009-12-08 09:21:05 +00007326TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007327 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7328 if (!Type)
7329 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007330
John McCall60d7b3a2010-08-24 06:29:42 +00007331 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00007332 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007333 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007334 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007335
Douglas Gregorb98b1992009-08-11 05:31:07 +00007336 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007337 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007338 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007339 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007340 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00007341 E->getStmtClass(),
Fariborz Jahanianf799ae12013-02-22 22:02:53 +00007342 E->getAngleBrackets().getBegin(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007343 Type,
Fariborz Jahanianf799ae12013-02-22 22:02:53 +00007344 E->getAngleBrackets().getEnd(),
7345 // FIXME. this should be '(' location
7346 E->getAngleBrackets().getEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00007347 SubExpr.get(),
Abramo Bagnara6cf7d7d2012-10-15 21:08:58 +00007348 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007349}
Mike Stump1eb44332009-09-09 15:08:12 +00007350
Douglas Gregorb98b1992009-08-11 05:31:07 +00007351template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007352ExprResult
John McCall454feb92009-12-08 09:21:05 +00007353TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
7354 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007355}
Mike Stump1eb44332009-09-09 15:08:12 +00007356
7357template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007358ExprResult
John McCall454feb92009-12-08 09:21:05 +00007359TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
7360 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007361}
7362
Douglas Gregorb98b1992009-08-11 05:31:07 +00007363template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007364ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007365TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall454feb92009-12-08 09:21:05 +00007366 CXXReinterpretCastExpr *E) {
7367 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007368}
Mike Stump1eb44332009-09-09 15:08:12 +00007369
Douglas Gregorb98b1992009-08-11 05:31:07 +00007370template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007371ExprResult
John McCall454feb92009-12-08 09:21:05 +00007372TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
7373 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007374}
Mike Stump1eb44332009-09-09 15:08:12 +00007375
Douglas Gregorb98b1992009-08-11 05:31:07 +00007376template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007377ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007378TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall454feb92009-12-08 09:21:05 +00007379 CXXFunctionalCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007380 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7381 if (!Type)
7382 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007383
John McCall60d7b3a2010-08-24 06:29:42 +00007384 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00007385 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007386 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007387 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007388
Douglas Gregorb98b1992009-08-11 05:31:07 +00007389 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007390 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007391 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007392 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007393
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007394 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Eli Friedmancdd4b782013-08-15 22:02:56 +00007395 E->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00007396 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007397 E->getRParenLoc());
7398}
Mike Stump1eb44332009-09-09 15:08:12 +00007399
Douglas Gregorb98b1992009-08-11 05:31:07 +00007400template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007401ExprResult
John McCall454feb92009-12-08 09:21:05 +00007402TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007403 if (E->isTypeOperand()) {
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007404 TypeSourceInfo *TInfo
7405 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7406 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007407 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007408
Douglas Gregorb98b1992009-08-11 05:31:07 +00007409 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007410 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007411 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007412
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007413 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7414 E->getLocStart(),
7415 TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007416 E->getLocEnd());
7417 }
Mike Stump1eb44332009-09-09 15:08:12 +00007418
Eli Friedmanef331b72012-01-20 01:26:23 +00007419 // We don't know whether the subexpression is potentially evaluated until
7420 // after we perform semantic analysis. We speculatively assume it is
7421 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregorb98b1992009-08-11 05:31:07 +00007422 // potentially evaluated.
Eli Friedman80bfa3d2012-09-26 04:34:21 +00007423 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
7424 Sema::ReuseLambdaContextDecl);
Mike Stump1eb44332009-09-09 15:08:12 +00007425
John McCall60d7b3a2010-08-24 06:29:42 +00007426 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007427 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007428 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007429
Douglas Gregorb98b1992009-08-11 05:31:07 +00007430 if (!getDerived().AlwaysRebuild() &&
7431 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007432 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007433
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007434 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7435 E->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00007436 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007437 E->getLocEnd());
7438}
7439
7440template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007441ExprResult
Francois Pichet01b7c302010-09-08 12:20:18 +00007442TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
7443 if (E->isTypeOperand()) {
7444 TypeSourceInfo *TInfo
7445 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7446 if (!TInfo)
7447 return ExprError();
7448
7449 if (!getDerived().AlwaysRebuild() &&
7450 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007451 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00007452
Douglas Gregor3c52a212011-03-06 17:40:41 +00007453 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet01b7c302010-09-08 12:20:18 +00007454 E->getLocStart(),
7455 TInfo,
7456 E->getLocEnd());
7457 }
7458
Francois Pichet01b7c302010-09-08 12:20:18 +00007459 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7460
7461 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
7462 if (SubExpr.isInvalid())
7463 return ExprError();
7464
7465 if (!getDerived().AlwaysRebuild() &&
7466 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007467 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00007468
7469 return getDerived().RebuildCXXUuidofExpr(E->getType(),
7470 E->getLocStart(),
7471 SubExpr.get(),
7472 E->getLocEnd());
7473}
7474
7475template<typename Derived>
7476ExprResult
John McCall454feb92009-12-08 09:21:05 +00007477TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007478 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007479}
Mike Stump1eb44332009-09-09 15:08:12 +00007480
Douglas Gregorb98b1992009-08-11 05:31:07 +00007481template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007482ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007483TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall454feb92009-12-08 09:21:05 +00007484 CXXNullPtrLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007485 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007486}
Mike Stump1eb44332009-09-09 15:08:12 +00007487
Douglas Gregorb98b1992009-08-11 05:31:07 +00007488template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007489ExprResult
John McCall454feb92009-12-08 09:21:05 +00007490TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Richard Smithcafeb942013-06-07 02:33:37 +00007491 QualType T = getSema().getCurrentThisType();
Mike Stump1eb44332009-09-09 15:08:12 +00007492
Douglas Gregorec79d872012-02-24 17:41:38 +00007493 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
7494 // Make sure that we capture 'this'.
7495 getSema().CheckCXXThisCapture(E->getLocStart());
John McCall3fa5cae2010-10-26 07:05:15 +00007496 return SemaRef.Owned(E);
Douglas Gregorec79d872012-02-24 17:41:38 +00007497 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007498
Douglas Gregor828a1972010-01-07 23:12:05 +00007499 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007500}
Mike Stump1eb44332009-09-09 15:08:12 +00007501
Douglas Gregorb98b1992009-08-11 05:31:07 +00007502template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007503ExprResult
John McCall454feb92009-12-08 09:21:05 +00007504TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007505 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007506 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007507 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007508
Douglas Gregorb98b1992009-08-11 05:31:07 +00007509 if (!getDerived().AlwaysRebuild() &&
7510 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007511 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007512
Douglas Gregorbca01b42011-07-06 22:04:06 +00007513 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
7514 E->isThrownVariableInScope());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007515}
Mike Stump1eb44332009-09-09 15:08:12 +00007516
Douglas Gregorb98b1992009-08-11 05:31:07 +00007517template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007518ExprResult
John McCall454feb92009-12-08 09:21:05 +00007519TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00007520 ParmVarDecl *Param
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007521 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
7522 E->getParam()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007523 if (!Param)
John McCallf312b1e2010-08-26 23:41:50 +00007524 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007525
Chandler Carruth53cb6f82010-02-08 06:42:49 +00007526 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007527 Param == E->getParam())
John McCall3fa5cae2010-10-26 07:05:15 +00007528 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007529
Douglas Gregor036aed12009-12-23 23:03:06 +00007530 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007531}
Mike Stump1eb44332009-09-09 15:08:12 +00007532
Douglas Gregorb98b1992009-08-11 05:31:07 +00007533template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007534ExprResult
Richard Smithc3bf52c2013-04-20 22:23:05 +00007535TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
7536 FieldDecl *Field
7537 = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(),
7538 E->getField()));
7539 if (!Field)
7540 return ExprError();
7541
7542 if (!getDerived().AlwaysRebuild() && Field == E->getField())
7543 return SemaRef.Owned(E);
7544
7545 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
7546}
7547
7548template<typename Derived>
7549ExprResult
Douglas Gregorab6677e2010-09-08 00:15:04 +00007550TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
7551 CXXScalarValueInitExpr *E) {
7552 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7553 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007554 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007555
Douglas Gregorb98b1992009-08-11 05:31:07 +00007556 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007557 T == E->getTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007558 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007559
Chad Rosier4a9d7952012-08-08 18:46:20 +00007560 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregorab6677e2010-09-08 00:15:04 +00007561 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregored8abf12010-07-08 06:14:04 +00007562 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007563}
Mike Stump1eb44332009-09-09 15:08:12 +00007564
Douglas Gregorb98b1992009-08-11 05:31:07 +00007565template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007566ExprResult
John McCall454feb92009-12-08 09:21:05 +00007567TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007568 // Transform the type that we're allocating
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007569 TypeSourceInfo *AllocTypeInfo
7570 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
7571 if (!AllocTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007572 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007573
Douglas Gregorb98b1992009-08-11 05:31:07 +00007574 // Transform the size of the array we're allocating (if any).
John McCall60d7b3a2010-08-24 06:29:42 +00007575 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007576 if (ArraySize.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007577 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007578
Douglas Gregorb98b1992009-08-11 05:31:07 +00007579 // Transform the placement arguments (if any).
7580 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007581 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007582 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregoraa165f82011-01-03 19:04:46 +00007583 E->getNumPlacementArgs(), true,
7584 PlacementArgs, &ArgumentChanged))
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007585 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007586
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007587 // Transform the initializer (if any).
7588 Expr *OldInit = E->getInitializer();
7589 ExprResult NewInit;
7590 if (OldInit)
7591 NewInit = getDerived().TransformExpr(OldInit);
7592 if (NewInit.isInvalid())
7593 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007594
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007595 // Transform new operator and delete operator.
Douglas Gregor1af74512010-02-26 00:38:10 +00007596 FunctionDecl *OperatorNew = 0;
7597 if (E->getOperatorNew()) {
7598 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007599 getDerived().TransformDecl(E->getLocStart(),
7600 E->getOperatorNew()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007601 if (!OperatorNew)
John McCallf312b1e2010-08-26 23:41:50 +00007602 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007603 }
7604
7605 FunctionDecl *OperatorDelete = 0;
7606 if (E->getOperatorDelete()) {
7607 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007608 getDerived().TransformDecl(E->getLocStart(),
7609 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007610 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007611 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007612 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007613
Douglas Gregorb98b1992009-08-11 05:31:07 +00007614 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007615 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007616 ArraySize.get() == E->getArraySize() &&
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007617 NewInit.get() == OldInit &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007618 OperatorNew == E->getOperatorNew() &&
7619 OperatorDelete == E->getOperatorDelete() &&
7620 !ArgumentChanged) {
7621 // Mark any declarations we need as referenced.
7622 // FIXME: instantiation-specific.
Douglas Gregor1af74512010-02-26 00:38:10 +00007623 if (OperatorNew)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007624 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregor1af74512010-02-26 00:38:10 +00007625 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007626 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007627
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007628 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007629 QualType ElementType
7630 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
7631 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
7632 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
7633 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedman5f2987c2012-02-02 03:46:19 +00007634 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007635 }
7636 }
7637 }
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007638
John McCall3fa5cae2010-10-26 07:05:15 +00007639 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007640 }
Mike Stump1eb44332009-09-09 15:08:12 +00007641
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007642 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007643 if (!ArraySize.get()) {
7644 // If no array size was specified, but the new expression was
7645 // instantiated with an array type (e.g., "new T" where T is
7646 // instantiated with "int[4]"), extract the outer bound from the
7647 // array type as our array size. We do this with constant and
7648 // dependently-sized array types.
7649 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
7650 if (!ArrayT) {
7651 // Do nothing
7652 } else if (const ConstantArrayType *ConsArrayT
7653 = dyn_cast<ConstantArrayType>(ArrayT)) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00007654 ArraySize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007655 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
Chad Rosier4a9d7952012-08-08 18:46:20 +00007656 ConsArrayT->getSize(),
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007657 SemaRef.Context.getSizeType(),
7658 /*FIXME:*/E->getLocStart()));
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007659 AllocType = ConsArrayT->getElementType();
7660 } else if (const DependentSizedArrayType *DepArrayT
7661 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
7662 if (DepArrayT->getSizeExpr()) {
John McCall3fa5cae2010-10-26 07:05:15 +00007663 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007664 AllocType = DepArrayT->getElementType();
7665 }
7666 }
7667 }
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007668
Douglas Gregorb98b1992009-08-11 05:31:07 +00007669 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
7670 E->isGlobalNew(),
7671 /*FIXME:*/E->getLocStart(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007672 PlacementArgs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007673 /*FIXME:*/E->getLocStart(),
Douglas Gregor4bd40312010-07-13 15:54:32 +00007674 E->getTypeIdParens(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007675 AllocType,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007676 AllocTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00007677 ArraySize.get(),
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007678 E->getDirectInitRange(),
7679 NewInit.take());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007680}
Mike Stump1eb44332009-09-09 15:08:12 +00007681
Douglas Gregorb98b1992009-08-11 05:31:07 +00007682template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007683ExprResult
John McCall454feb92009-12-08 09:21:05 +00007684TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007685 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007686 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007687 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007688
Douglas Gregor1af74512010-02-26 00:38:10 +00007689 // Transform the delete operator, if known.
7690 FunctionDecl *OperatorDelete = 0;
7691 if (E->getOperatorDelete()) {
7692 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007693 getDerived().TransformDecl(E->getLocStart(),
7694 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007695 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007696 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007697 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007698
Douglas Gregorb98b1992009-08-11 05:31:07 +00007699 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007700 Operand.get() == E->getArgument() &&
7701 OperatorDelete == E->getOperatorDelete()) {
7702 // Mark any declarations we need as referenced.
7703 // FIXME: instantiation-specific.
7704 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007705 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007706
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007707 if (!E->getArgument()->isTypeDependent()) {
7708 QualType Destroyed = SemaRef.Context.getBaseElementType(
7709 E->getDestroyedType());
7710 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
7711 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007712 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedman5f2987c2012-02-02 03:46:19 +00007713 SemaRef.LookupDestructor(Record));
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007714 }
7715 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007716
John McCall3fa5cae2010-10-26 07:05:15 +00007717 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007718 }
Mike Stump1eb44332009-09-09 15:08:12 +00007719
Douglas Gregorb98b1992009-08-11 05:31:07 +00007720 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
7721 E->isGlobalDelete(),
7722 E->isArrayForm(),
John McCall9ae2f072010-08-23 23:25:46 +00007723 Operand.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007724}
Mike Stump1eb44332009-09-09 15:08:12 +00007725
Douglas Gregorb98b1992009-08-11 05:31:07 +00007726template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007727ExprResult
Douglas Gregora71d8192009-09-04 17:36:40 +00007728TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall454feb92009-12-08 09:21:05 +00007729 CXXPseudoDestructorExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007730 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora71d8192009-09-04 17:36:40 +00007731 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007732 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007733
John McCallb3d87482010-08-24 05:47:05 +00007734 ParsedType ObjectTypePtr;
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007735 bool MayBePseudoDestructor = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007736 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007737 E->getOperatorLoc(),
7738 E->isArrow()? tok::arrow : tok::period,
7739 ObjectTypePtr,
7740 MayBePseudoDestructor);
7741 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007742 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007743
John McCallb3d87482010-08-24 05:47:05 +00007744 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007745 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
7746 if (QualifierLoc) {
7747 QualifierLoc
7748 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
7749 if (!QualifierLoc)
John McCall43fed0d2010-11-12 08:19:04 +00007750 return ExprError();
7751 }
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007752 CXXScopeSpec SS;
7753 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00007754
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007755 PseudoDestructorTypeStorage Destroyed;
7756 if (E->getDestroyedTypeInfo()) {
7757 TypeSourceInfo *DestroyedTypeInfo
John McCall43fed0d2010-11-12 08:19:04 +00007758 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00007759 ObjectType, 0, SS);
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007760 if (!DestroyedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007761 return ExprError();
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007762 Destroyed = DestroyedTypeInfo;
Douglas Gregor6b18e742011-11-09 02:19:47 +00007763 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007764 // We aren't likely to be able to resolve the identifier down to a type
7765 // now anyway, so just retain the identifier.
7766 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
7767 E->getDestroyedTypeLoc());
7768 } else {
7769 // Look for a destructor known with the given name.
John McCallb3d87482010-08-24 05:47:05 +00007770 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007771 *E->getDestroyedTypeIdentifier(),
7772 E->getDestroyedTypeLoc(),
7773 /*Scope=*/0,
7774 SS, ObjectTypePtr,
7775 false);
7776 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007777 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007778
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007779 Destroyed
7780 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
7781 E->getDestroyedTypeLoc());
7782 }
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007783
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007784 TypeSourceInfo *ScopeTypeInfo = 0;
7785 if (E->getScopeTypeInfo()) {
Douglas Gregor303b96f2013-03-08 21:25:01 +00007786 CXXScopeSpec EmptySS;
7787 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
7788 E->getScopeTypeInfo(), ObjectType, 0, EmptySS);
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007789 if (!ScopeTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007790 return ExprError();
Douglas Gregora71d8192009-09-04 17:36:40 +00007791 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007792
John McCall9ae2f072010-08-23 23:25:46 +00007793 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregora71d8192009-09-04 17:36:40 +00007794 E->getOperatorLoc(),
7795 E->isArrow(),
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007796 SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007797 ScopeTypeInfo,
7798 E->getColonColonLoc(),
Douglas Gregorfce46ee2010-02-24 23:50:37 +00007799 E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007800 Destroyed);
Douglas Gregora71d8192009-09-04 17:36:40 +00007801}
Mike Stump1eb44332009-09-09 15:08:12 +00007802
Douglas Gregora71d8192009-09-04 17:36:40 +00007803template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007804ExprResult
John McCallba135432009-11-21 08:51:07 +00007805TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall454feb92009-12-08 09:21:05 +00007806 UnresolvedLookupExpr *Old) {
John McCallf7a1a742009-11-24 19:00:30 +00007807 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
7808 Sema::LookupOrdinaryName);
7809
7810 // Transform all the decls.
7811 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
7812 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007813 NamedDecl *InstD = static_cast<NamedDecl*>(
7814 getDerived().TransformDecl(Old->getNameLoc(),
7815 *I));
John McCall9f54ad42009-12-10 09:41:52 +00007816 if (!InstD) {
7817 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7818 // This can happen because of dependent hiding.
7819 if (isa<UsingShadowDecl>(*I))
7820 continue;
Serge Pavlov1e75a1a2013-09-04 04:50:29 +00007821 else {
7822 R.clear();
John McCallf312b1e2010-08-26 23:41:50 +00007823 return ExprError();
Serge Pavlov1e75a1a2013-09-04 04:50:29 +00007824 }
John McCall9f54ad42009-12-10 09:41:52 +00007825 }
John McCallf7a1a742009-11-24 19:00:30 +00007826
7827 // Expand using declarations.
7828 if (isa<UsingDecl>(InstD)) {
7829 UsingDecl *UD = cast<UsingDecl>(InstD);
7830 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7831 E = UD->shadow_end(); I != E; ++I)
7832 R.addDecl(*I);
7833 continue;
7834 }
7835
7836 R.addDecl(InstD);
7837 }
7838
7839 // Resolve a kind, but don't do any further analysis. If it's
7840 // ambiguous, the callee needs to deal with it.
7841 R.resolveKind();
7842
7843 // Rebuild the nested-name qualifier, if present.
7844 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00007845 if (Old->getQualifierLoc()) {
7846 NestedNameSpecifierLoc QualifierLoc
7847 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7848 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007849 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007850
Douglas Gregor4c9be892011-02-28 20:01:57 +00007851 SS.Adopt(QualifierLoc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007852 }
7853
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007854 if (Old->getNamingClass()) {
Douglas Gregor66c45152010-04-27 16:10:10 +00007855 CXXRecordDecl *NamingClass
7856 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
7857 Old->getNameLoc(),
7858 Old->getNamingClass()));
Serge Pavlov1e75a1a2013-09-04 04:50:29 +00007859 if (!NamingClass) {
7860 R.clear();
John McCallf312b1e2010-08-26 23:41:50 +00007861 return ExprError();
Serge Pavlov1e75a1a2013-09-04 04:50:29 +00007862 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007863
Douglas Gregor66c45152010-04-27 16:10:10 +00007864 R.setNamingClass(NamingClass);
John McCallf7a1a742009-11-24 19:00:30 +00007865 }
7866
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007867 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
7868
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007869 // If we have neither explicit template arguments, nor the template keyword,
7870 // it's a normal declaration name.
7871 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
John McCallf7a1a742009-11-24 19:00:30 +00007872 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
7873
7874 // If we have template arguments, rebuild them, then rebuild the
7875 // templateid expression.
7876 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola02e221b2012-08-28 04:13:54 +00007877 if (Old->hasExplicitTemplateArgs() &&
7878 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregorfcc12532010-12-20 17:31:10 +00007879 Old->getNumTemplateArgs(),
Serge Pavlov1e75a1a2013-09-04 04:50:29 +00007880 TransArgs)) {
7881 R.clear();
Douglas Gregorfcc12532010-12-20 17:31:10 +00007882 return ExprError();
Serge Pavlov1e75a1a2013-09-04 04:50:29 +00007883 }
John McCallf7a1a742009-11-24 19:00:30 +00007884
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007885 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007886 Old->requiresADL(), &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007887}
Mike Stump1eb44332009-09-09 15:08:12 +00007888
Douglas Gregorb98b1992009-08-11 05:31:07 +00007889template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007890ExprResult
John McCall454feb92009-12-08 09:21:05 +00007891TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007892 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7893 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007894 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007895
Douglas Gregorb98b1992009-08-11 05:31:07 +00007896 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007897 T == E->getQueriedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007898 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007899
Mike Stump1eb44332009-09-09 15:08:12 +00007900 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007901 E->getLocStart(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007902 T,
7903 E->getLocEnd());
7904}
Mike Stump1eb44332009-09-09 15:08:12 +00007905
Douglas Gregorb98b1992009-08-11 05:31:07 +00007906template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007907ExprResult
Francois Pichet6ad6f282010-12-07 00:08:36 +00007908TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
7909 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
7910 if (!LhsT)
7911 return ExprError();
7912
7913 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
7914 if (!RhsT)
7915 return ExprError();
7916
7917 if (!getDerived().AlwaysRebuild() &&
7918 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
7919 return SemaRef.Owned(E);
7920
7921 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
7922 E->getLocStart(),
7923 LhsT, RhsT,
7924 E->getLocEnd());
7925}
7926
7927template<typename Derived>
7928ExprResult
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007929TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
7930 bool ArgChanged = false;
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00007931 SmallVector<TypeSourceInfo *, 4> Args;
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007932 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
7933 TypeSourceInfo *From = E->getArg(I);
7934 TypeLoc FromTL = From->getTypeLoc();
David Blaikie39e6ab42013-02-18 22:06:02 +00007935 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007936 TypeLocBuilder TLB;
7937 TLB.reserve(FromTL.getFullDataSize());
7938 QualType To = getDerived().TransformType(TLB, FromTL);
7939 if (To.isNull())
7940 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007941
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007942 if (To == From->getType())
7943 Args.push_back(From);
7944 else {
7945 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7946 ArgChanged = true;
7947 }
7948 continue;
7949 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007950
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007951 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007952
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007953 // We have a pack expansion. Instantiate it.
David Blaikie39e6ab42013-02-18 22:06:02 +00007954 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007955 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
7956 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
7957 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007958
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007959 // Determine whether the set of unexpanded parameter packs can and should
7960 // be expanded.
7961 bool Expand = true;
7962 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00007963 Optional<unsigned> OrigNumExpansions =
7964 ExpansionTL.getTypePtr()->getNumExpansions();
7965 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007966 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
7967 PatternTL.getSourceRange(),
7968 Unexpanded,
7969 Expand, RetainExpansion,
7970 NumExpansions))
7971 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007972
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007973 if (!Expand) {
7974 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00007975 // transformation on the pack expansion, producing another pack
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007976 // expansion.
7977 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007978
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007979 TypeLocBuilder TLB;
7980 TLB.reserve(From->getTypeLoc().getFullDataSize());
7981
7982 QualType To = getDerived().TransformType(TLB, PatternTL);
7983 if (To.isNull())
7984 return ExprError();
7985
Chad Rosier4a9d7952012-08-08 18:46:20 +00007986 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007987 PatternTL.getSourceRange(),
7988 ExpansionTL.getEllipsisLoc(),
7989 NumExpansions);
7990 if (To.isNull())
7991 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007992
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007993 PackExpansionTypeLoc ToExpansionTL
7994 = TLB.push<PackExpansionTypeLoc>(To);
7995 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7996 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7997 continue;
7998 }
7999
8000 // Expand the pack expansion by substituting for each argument in the
8001 // pack(s).
8002 for (unsigned I = 0; I != *NumExpansions; ++I) {
8003 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
8004 TypeLocBuilder TLB;
8005 TLB.reserve(PatternTL.getFullDataSize());
8006 QualType To = getDerived().TransformType(TLB, PatternTL);
8007 if (To.isNull())
8008 return ExprError();
8009
Eli Friedman20cfeca2013-07-19 21:49:32 +00008010 if (To->containsUnexpandedParameterPack()) {
8011 To = getDerived().RebuildPackExpansionType(To,
8012 PatternTL.getSourceRange(),
8013 ExpansionTL.getEllipsisLoc(),
8014 NumExpansions);
8015 if (To.isNull())
8016 return ExprError();
8017
8018 PackExpansionTypeLoc ToExpansionTL
8019 = TLB.push<PackExpansionTypeLoc>(To);
8020 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8021 }
8022
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00008023 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8024 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008025
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00008026 if (!RetainExpansion)
8027 continue;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008028
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00008029 // If we're supposed to retain a pack expansion, do so by temporarily
8030 // forgetting the partially-substituted parameter pack.
8031 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
8032
8033 TypeLocBuilder TLB;
8034 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008035
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00008036 QualType To = getDerived().TransformType(TLB, PatternTL);
8037 if (To.isNull())
8038 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008039
8040 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00008041 PatternTL.getSourceRange(),
8042 ExpansionTL.getEllipsisLoc(),
8043 NumExpansions);
8044 if (To.isNull())
8045 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008046
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00008047 PackExpansionTypeLoc ToExpansionTL
8048 = TLB.push<PackExpansionTypeLoc>(To);
8049 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8050 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8051 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008052
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00008053 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8054 return SemaRef.Owned(E);
8055
8056 return getDerived().RebuildTypeTrait(E->getTrait(),
8057 E->getLocStart(),
8058 Args,
8059 E->getLocEnd());
8060}
8061
8062template<typename Derived>
8063ExprResult
John Wiegley21ff2e52011-04-28 00:16:57 +00008064TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
8065 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
8066 if (!T)
8067 return ExprError();
8068
8069 if (!getDerived().AlwaysRebuild() &&
8070 T == E->getQueriedTypeSourceInfo())
8071 return SemaRef.Owned(E);
8072
8073 ExprResult SubExpr;
8074 {
8075 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8076 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
8077 if (SubExpr.isInvalid())
8078 return ExprError();
8079
8080 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
8081 return SemaRef.Owned(E);
8082 }
8083
8084 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
8085 E->getLocStart(),
8086 T,
8087 SubExpr.get(),
8088 E->getLocEnd());
8089}
8090
8091template<typename Derived>
8092ExprResult
John Wiegley55262202011-04-25 06:54:41 +00008093TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
8094 ExprResult SubExpr;
8095 {
8096 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8097 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
8098 if (SubExpr.isInvalid())
8099 return ExprError();
8100
8101 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
8102 return SemaRef.Owned(E);
8103 }
8104
8105 return getDerived().RebuildExpressionTrait(
8106 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
8107}
8108
8109template<typename Derived>
8110ExprResult
John McCall865d4472009-11-19 22:55:06 +00008111TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00008112 DependentScopeDeclRefExpr *E) {
Richard Smithefeeccf2012-10-21 03:28:35 +00008113 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand*/false);
8114}
8115
8116template<typename Derived>
8117ExprResult
8118TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
8119 DependentScopeDeclRefExpr *E,
8120 bool IsAddressOfOperand) {
Reid Kleckner8690cee2013-10-15 18:38:02 +00008121 assert(E->getQualifierLoc());
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00008122 NestedNameSpecifierLoc QualifierLoc
8123 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
8124 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008125 return ExprError();
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008126 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00008127
John McCall43fed0d2010-11-12 08:19:04 +00008128 // TODO: If this is a conversion-function-id, verify that the
8129 // destination type name (if present) resolves the same way after
8130 // instantiation as it did in the local scope.
8131
Abramo Bagnara25777432010-08-11 22:01:17 +00008132 DeclarationNameInfo NameInfo
8133 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
8134 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00008135 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008136
John McCallf7a1a742009-11-24 19:00:30 +00008137 if (!E->hasExplicitTemplateArgs()) {
8138 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00008139 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00008140 // Note: it is sufficient to compare the Name component of NameInfo:
8141 // if name has not changed, DNLoc has not changed either.
8142 NameInfo.getName() == E->getDeclName())
John McCall3fa5cae2010-10-26 07:05:15 +00008143 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008144
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00008145 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008146 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00008147 NameInfo,
Richard Smithefeeccf2012-10-21 03:28:35 +00008148 /*TemplateArgs*/ 0,
8149 IsAddressOfOperand);
Douglas Gregorf17bb742009-10-22 17:20:55 +00008150 }
John McCalld5532b62009-11-23 01:53:49 +00008151
8152 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008153 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8154 E->getNumTemplateArgs(),
8155 TransArgs))
8156 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00008157
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00008158 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008159 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00008160 NameInfo,
Richard Smithefeeccf2012-10-21 03:28:35 +00008161 &TransArgs,
8162 IsAddressOfOperand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008163}
8164
8165template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008166ExprResult
John McCall454feb92009-12-08 09:21:05 +00008167TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithc83c2302012-12-19 01:39:02 +00008168 // CXXConstructExprs other than for list-initialization and
8169 // CXXTemporaryObjectExpr are always implicit, so when we have
8170 // a 1-argument construction we just transform that argument.
Richard Smith73ed67c2012-11-26 08:32:48 +00008171 if ((E->getNumArgs() == 1 ||
8172 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithc83c2302012-12-19 01:39:02 +00008173 (!getDerived().DropCallArgument(E->getArg(0))) &&
8174 !E->isListInitialization())
Douglas Gregor321725d2010-02-03 03:01:57 +00008175 return getDerived().TransformExpr(E->getArg(0));
8176
Douglas Gregorb98b1992009-08-11 05:31:07 +00008177 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
8178
8179 QualType T = getDerived().TransformType(E->getType());
8180 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00008181 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00008182
8183 CXXConstructorDecl *Constructor
8184 = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00008185 getDerived().TransformDecl(E->getLocStart(),
8186 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00008187 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00008188 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008189
Douglas Gregorb98b1992009-08-11 05:31:07 +00008190 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008191 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008192 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008193 &ArgumentChanged))
8194 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008195
Douglas Gregorb98b1992009-08-11 05:31:07 +00008196 if (!getDerived().AlwaysRebuild() &&
8197 T == E->getType() &&
8198 Constructor == E->getConstructor() &&
Douglas Gregorc845aad2010-02-26 00:01:57 +00008199 !ArgumentChanged) {
Douglas Gregor1af74512010-02-26 00:38:10 +00008200 // Mark the constructor as referenced.
8201 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00008202 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00008203 return SemaRef.Owned(E);
Douglas Gregorc845aad2010-02-26 00:01:57 +00008204 }
Mike Stump1eb44332009-09-09 15:08:12 +00008205
Douglas Gregor4411d2e2009-12-14 16:27:04 +00008206 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
8207 Constructor, E->isElidable(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008208 Args,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00008209 E->hadMultipleCandidates(),
Richard Smithc83c2302012-12-19 01:39:02 +00008210 E->isListInitialization(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00008211 E->requiresZeroInitialization(),
Chandler Carruth428edaf2010-10-25 08:47:36 +00008212 E->getConstructionKind(),
Enea Zaffanella1245a542013-09-07 05:49:53 +00008213 E->getParenOrBraceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008214}
Mike Stump1eb44332009-09-09 15:08:12 +00008215
Douglas Gregorb98b1992009-08-11 05:31:07 +00008216/// \brief Transform a C++ temporary-binding expression.
8217///
Douglas Gregor51326552009-12-24 18:51:59 +00008218/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
8219/// transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00008220template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008221ExprResult
John McCall454feb92009-12-08 09:21:05 +00008222TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00008223 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008224}
Mike Stump1eb44332009-09-09 15:08:12 +00008225
John McCall4765fa02010-12-06 08:20:24 +00008226/// \brief Transform a C++ expression that contains cleanups that should
8227/// be run after the expression is evaluated.
Douglas Gregorb98b1992009-08-11 05:31:07 +00008228///
John McCall4765fa02010-12-06 08:20:24 +00008229/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor51326552009-12-24 18:51:59 +00008230/// just transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00008231template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008232ExprResult
John McCall4765fa02010-12-06 08:20:24 +00008233TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00008234 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008235}
Mike Stump1eb44332009-09-09 15:08:12 +00008236
Douglas Gregorb98b1992009-08-11 05:31:07 +00008237template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008238ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00008239TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregorab6677e2010-09-08 00:15:04 +00008240 CXXTemporaryObjectExpr *E) {
8241 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8242 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00008243 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008244
Douglas Gregorb98b1992009-08-11 05:31:07 +00008245 CXXConstructorDecl *Constructor
8246 = cast_or_null<CXXConstructorDecl>(
Chad Rosier4a9d7952012-08-08 18:46:20 +00008247 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00008248 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00008249 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00008250 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008251
Douglas Gregorb98b1992009-08-11 05:31:07 +00008252 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008253 SmallVector<Expr*, 8> Args;
Douglas Gregorb98b1992009-08-11 05:31:07 +00008254 Args.reserve(E->getNumArgs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008255 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008256 &ArgumentChanged))
8257 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008258
Douglas Gregorb98b1992009-08-11 05:31:07 +00008259 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00008260 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00008261 Constructor == E->getConstructor() &&
Douglas Gregor91be6f52010-03-02 17:18:33 +00008262 !ArgumentChanged) {
8263 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00008264 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00008265 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor91be6f52010-03-02 17:18:33 +00008266 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008267
Richard Smithc83c2302012-12-19 01:39:02 +00008268 // FIXME: Pass in E->isListInitialization().
Douglas Gregorab6677e2010-09-08 00:15:04 +00008269 return getDerived().RebuildCXXTemporaryObjectExpr(T,
8270 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008271 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008272 E->getLocEnd());
8273}
Mike Stump1eb44332009-09-09 15:08:12 +00008274
Douglas Gregorb98b1992009-08-11 05:31:07 +00008275template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008276ExprResult
Douglas Gregor01d08012012-02-07 10:09:13 +00008277TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Faisal Valifad9e132013-09-26 19:54:12 +00008278
Faisal Valid78d6592013-11-12 01:40:44 +00008279 LambdaScopeInfo *LSI = getSema().PushLambdaScope();
Faisal Valia3d311e2013-10-23 06:44:28 +00008280 // Transform the template parameters, and add them to the current
8281 // instantiation scope. The null case is handled correctly.
8282 LSI->GLTemplateParameterList = getDerived().TransformTemplateParameterList(
8283 E->getTemplateParameterList());
8284
8285 // Check to see if the TypeSourceInfo of the call operator needs to
8286 // be transformed, and if so do the transformation in the
8287 // CurrentInstantiationScope.
8288
8289 TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo();
8290 FunctionProtoTypeLoc OldCallOpFPTL =
8291 OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>();
8292 TypeSourceInfo *NewCallOpTSI = 0;
8293
8294 const bool CallOpWasAlreadyTransformed =
8295 getDerived().AlreadyTransformed(OldCallOpTSI->getType());
8296
8297 // Use the Old Call Operator's TypeSourceInfo if it is already transformed.
8298 if (CallOpWasAlreadyTransformed)
8299 NewCallOpTSI = OldCallOpTSI;
8300 else {
8301 // Transform the TypeSourceInfo of the Original Lambda's Call Operator.
8302 // The transformation MUST be done in the CurrentInstantiationScope since
8303 // it introduces a mapping of the original to the newly created
8304 // transformed parameters.
8305
8306 TypeLocBuilder NewCallOpTLBuilder;
8307 QualType NewCallOpType = TransformFunctionProtoType(NewCallOpTLBuilder,
8308 OldCallOpFPTL,
8309 0, 0);
8310 NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context,
8311 NewCallOpType);
Faisal Valifad9e132013-09-26 19:54:12 +00008312 }
Faisal Valia3d311e2013-10-23 06:44:28 +00008313 // Extract the ParmVarDecls from the NewCallOpTSI and add them to
8314 // the vector below - this will be used to synthesize the
8315 // NewCallOperator. Additionally, add the parameters of the untransformed
8316 // lambda call operator to the CurrentInstantiationScope.
8317 SmallVector<ParmVarDecl *, 4> Params;
8318 {
8319 FunctionProtoTypeLoc NewCallOpFPTL =
8320 NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>();
8321 ParmVarDecl **NewParamDeclArray = NewCallOpFPTL.getParmArray();
8322 const unsigned NewNumArgs = NewCallOpFPTL.getNumArgs();
8323
8324 for (unsigned I = 0; I < NewNumArgs; ++I) {
8325 // If this call operator's type does not require transformation,
8326 // the parameters do not get added to the current instantiation scope,
8327 // - so ADD them! This allows the following to compile when the enclosing
8328 // template is specialized and the entire lambda expression has to be
8329 // transformed.
8330 // template<class T> void foo(T t) {
8331 // auto L = [](auto a) {
8332 // auto M = [](char b) { <-- note: non-generic lambda
8333 // auto N = [](auto c) {
8334 // int x = sizeof(a);
8335 // x = sizeof(b); <-- specifically this line
8336 // x = sizeof(c);
8337 // };
8338 // };
8339 // };
8340 // }
8341 // foo('a')
8342 if (CallOpWasAlreadyTransformed)
8343 getDerived().transformedLocalDecl(NewParamDeclArray[I],
8344 NewParamDeclArray[I]);
8345 // Add to Params array, so these parameters can be used to create
8346 // the newly transformed call operator.
8347 Params.push_back(NewParamDeclArray[I]);
8348 }
8349 }
8350
8351 if (!NewCallOpTSI)
Douglas Gregordfca6f52012-02-13 22:00:16 +00008352 return ExprError();
8353
Eli Friedman8da8a662012-09-19 01:18:11 +00008354 // Create the local class that will describe the lambda.
8355 CXXRecordDecl *Class
8356 = getSema().createLambdaClosureType(E->getIntroducerRange(),
Faisal Valia3d311e2013-10-23 06:44:28 +00008357 NewCallOpTSI,
Faisal Valibef582b2013-10-23 16:10:50 +00008358 /*KnownDependent=*/false,
8359 E->getCaptureDefault());
8360
Eli Friedman8da8a662012-09-19 01:18:11 +00008361 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
8362
Douglas Gregordfca6f52012-02-13 22:00:16 +00008363 // Build the call operator.
Faisal Valia3d311e2013-10-23 06:44:28 +00008364 CXXMethodDecl *NewCallOperator
Douglas Gregordfca6f52012-02-13 22:00:16 +00008365 = getSema().startLambdaDefinition(Class, E->getIntroducerRange(),
Faisal Valia3d311e2013-10-23 06:44:28 +00008366 NewCallOpTSI,
Douglas Gregorc6889e72012-02-14 22:28:59 +00008367 E->getCallOperator()->getLocEnd(),
Richard Smithadb1d4c2012-07-22 23:45:10 +00008368 Params);
Faisal Valia3d311e2013-10-23 06:44:28 +00008369 LSI->CallOperator = NewCallOperator;
Rafael Espindolaf003acd2013-10-04 14:28:51 +00008370
Faisal Valia3d311e2013-10-23 06:44:28 +00008371 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
8372
8373 return getDerived().TransformLambdaScope(E, NewCallOperator);
Richard Smith612409e2012-07-25 03:56:55 +00008374}
8375
8376template<typename Derived>
8377ExprResult
8378TreeTransform<Derived>::TransformLambdaScope(LambdaExpr *E,
8379 CXXMethodDecl *CallOperator) {
Richard Smith0d8e9642013-05-16 06:20:58 +00008380 bool Invalid = false;
8381
8382 // Transform any init-capture expressions before entering the scope of the
8383 // lambda.
Robert Wilhelme7205c02013-08-10 12:33:24 +00008384 SmallVector<ExprResult, 8> InitCaptureExprs;
Richard Smith0d8e9642013-05-16 06:20:58 +00008385 InitCaptureExprs.resize(E->explicit_capture_end() -
8386 E->explicit_capture_begin());
8387 for (LambdaExpr::capture_iterator C = E->capture_begin(),
8388 CEnd = E->capture_end();
8389 C != CEnd; ++C) {
8390 if (!C->isInitCapture())
8391 continue;
8392 InitCaptureExprs[C - E->capture_begin()] =
Richard Smith04fa7a32013-09-28 04:02:39 +00008393 getDerived().TransformInitializer(
8394 C->getCapturedVar()->getInit(),
8395 C->getCapturedVar()->getInitStyle() == VarDecl::CallInit);
Richard Smith0d8e9642013-05-16 06:20:58 +00008396 }
8397
Douglas Gregord5387e82012-02-14 00:00:48 +00008398 // Introduce the context of the call operator.
8399 Sema::ContextRAII SavedContext(getSema(), CallOperator);
8400
Faisal Valifad9e132013-09-26 19:54:12 +00008401 LambdaScopeInfo *const LSI = getSema().getCurLambda();
Douglas Gregordfca6f52012-02-13 22:00:16 +00008402 // Enter the scope of the lambda.
Faisal Valifad9e132013-09-26 19:54:12 +00008403 getSema().buildLambdaScope(LSI, CallOperator, E->getIntroducerRange(),
Douglas Gregordfca6f52012-02-13 22:00:16 +00008404 E->getCaptureDefault(),
James Dennettf68af642013-08-09 23:08:25 +00008405 E->getCaptureDefaultLoc(),
Douglas Gregordfca6f52012-02-13 22:00:16 +00008406 E->hasExplicitParameters(),
8407 E->hasExplicitResultType(),
8408 E->isMutable());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008409
Douglas Gregordfca6f52012-02-13 22:00:16 +00008410 // Transform captures.
Douglas Gregordfca6f52012-02-13 22:00:16 +00008411 bool FinishedExplicitCaptures = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008412 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregordfca6f52012-02-13 22:00:16 +00008413 CEnd = E->capture_end();
8414 C != CEnd; ++C) {
8415 // When we hit the first implicit capture, tell Sema that we've finished
8416 // the list of explicit captures.
8417 if (!FinishedExplicitCaptures && C->isImplicit()) {
8418 getSema().finishLambdaExplicitCaptures(LSI);
8419 FinishedExplicitCaptures = true;
8420 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008421
Douglas Gregordfca6f52012-02-13 22:00:16 +00008422 // Capturing 'this' is trivial.
8423 if (C->capturesThis()) {
8424 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
8425 continue;
8426 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008427
Richard Smith0d8e9642013-05-16 06:20:58 +00008428 // Rebuild init-captures, including the implied field declaration.
8429 if (C->isInitCapture()) {
8430 ExprResult Init = InitCaptureExprs[C - E->capture_begin()];
8431 if (Init.isInvalid()) {
8432 Invalid = true;
8433 continue;
8434 }
Richard Smith04fa7a32013-09-28 04:02:39 +00008435 VarDecl *OldVD = C->getCapturedVar();
8436 VarDecl *NewVD = getSema().checkInitCapture(
8437 C->getLocation(), OldVD->getType()->isReferenceType(),
8438 OldVD->getIdentifier(), Init.take());
8439 if (!NewVD)
Richard Smith0d8e9642013-05-16 06:20:58 +00008440 Invalid = true;
8441 else
Richard Smith04fa7a32013-09-28 04:02:39 +00008442 getDerived().transformedLocalDecl(OldVD, NewVD);
8443 getSema().buildInitCaptureField(LSI, NewVD);
Richard Smith0d8e9642013-05-16 06:20:58 +00008444 continue;
8445 }
8446
8447 assert(C->capturesVariable() && "unexpected kind of lambda capture");
8448
Douglas Gregora7365242012-02-14 19:27:52 +00008449 // Determine the capture kind for Sema.
8450 Sema::TryCaptureKind Kind
8451 = C->isImplicit()? Sema::TryCapture_Implicit
8452 : C->getCaptureKind() == LCK_ByCopy
8453 ? Sema::TryCapture_ExplicitByVal
8454 : Sema::TryCapture_ExplicitByRef;
8455 SourceLocation EllipsisLoc;
8456 if (C->isPackExpansion()) {
8457 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
8458 bool ShouldExpand = false;
8459 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00008460 Optional<unsigned> NumExpansions;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008461 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
8462 C->getLocation(),
Douglas Gregora7365242012-02-14 19:27:52 +00008463 Unexpanded,
8464 ShouldExpand, RetainExpansion,
Richard Smith0d8e9642013-05-16 06:20:58 +00008465 NumExpansions)) {
8466 Invalid = true;
8467 continue;
8468 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008469
Douglas Gregora7365242012-02-14 19:27:52 +00008470 if (ShouldExpand) {
8471 // The transform has determined that we should perform an expansion;
8472 // transform and capture each of the arguments.
8473 // expansion of the pattern. Do so.
8474 VarDecl *Pack = C->getCapturedVar();
8475 for (unsigned I = 0; I != *NumExpansions; ++I) {
8476 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8477 VarDecl *CapturedVar
Chad Rosier4a9d7952012-08-08 18:46:20 +00008478 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregora7365242012-02-14 19:27:52 +00008479 Pack));
8480 if (!CapturedVar) {
8481 Invalid = true;
8482 continue;
8483 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008484
Douglas Gregora7365242012-02-14 19:27:52 +00008485 // Capture the transformed variable.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008486 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
8487 }
Douglas Gregora7365242012-02-14 19:27:52 +00008488 continue;
8489 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008490
Douglas Gregora7365242012-02-14 19:27:52 +00008491 EllipsisLoc = C->getEllipsisLoc();
8492 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008493
Douglas Gregordfca6f52012-02-13 22:00:16 +00008494 // Transform the captured variable.
8495 VarDecl *CapturedVar
Chad Rosier4a9d7952012-08-08 18:46:20 +00008496 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregordfca6f52012-02-13 22:00:16 +00008497 C->getCapturedVar()));
8498 if (!CapturedVar) {
8499 Invalid = true;
8500 continue;
8501 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008502
Douglas Gregordfca6f52012-02-13 22:00:16 +00008503 // Capture the transformed variable.
Douglas Gregor999713e2012-02-18 09:37:24 +00008504 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
Douglas Gregordfca6f52012-02-13 22:00:16 +00008505 }
8506 if (!FinishedExplicitCaptures)
8507 getSema().finishLambdaExplicitCaptures(LSI);
8508
Douglas Gregordfca6f52012-02-13 22:00:16 +00008509
8510 // Enter a new evaluation context to insulate the lambda from any
8511 // cleanups from the enclosing full-expression.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008512 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
Douglas Gregordfca6f52012-02-13 22:00:16 +00008513
8514 if (Invalid) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008515 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
Douglas Gregordfca6f52012-02-13 22:00:16 +00008516 /*IsInstantiation=*/true);
8517 return ExprError();
8518 }
8519
8520 // Instantiate the body of the lambda expression.
Douglas Gregord5387e82012-02-14 00:00:48 +00008521 StmtResult Body = getDerived().TransformStmt(E->getBody());
8522 if (Body.isInvalid()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008523 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
Douglas Gregord5387e82012-02-14 00:00:48 +00008524 /*IsInstantiation=*/true);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008525 return ExprError();
Douglas Gregord5387e82012-02-14 00:00:48 +00008526 }
Douglas Gregorccc1b5e2012-02-21 00:37:24 +00008527
Chad Rosier4a9d7952012-08-08 18:46:20 +00008528 return getSema().ActOnLambdaExpr(E->getLocStart(), Body.take(),
Douglas Gregorf54486a2012-04-04 17:40:10 +00008529 /*CurScope=*/0, /*IsInstantiation=*/true);
Douglas Gregor01d08012012-02-07 10:09:13 +00008530}
8531
8532template<typename Derived>
8533ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00008534TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall454feb92009-12-08 09:21:05 +00008535 CXXUnresolvedConstructExpr *E) {
Douglas Gregorab6677e2010-09-08 00:15:04 +00008536 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8537 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00008538 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008539
Douglas Gregorb98b1992009-08-11 05:31:07 +00008540 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008541 SmallVector<Expr*, 8> Args;
Douglas Gregoraa165f82011-01-03 19:04:46 +00008542 Args.reserve(E->arg_size());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008543 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008544 &ArgumentChanged))
8545 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008546
Douglas Gregorb98b1992009-08-11 05:31:07 +00008547 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00008548 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00008549 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00008550 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008551
Douglas Gregorb98b1992009-08-11 05:31:07 +00008552 // FIXME: we're faking the locations of the commas
Douglas Gregorab6677e2010-09-08 00:15:04 +00008553 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008554 E->getLParenLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008555 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008556 E->getRParenLoc());
8557}
Mike Stump1eb44332009-09-09 15:08:12 +00008558
Douglas Gregorb98b1992009-08-11 05:31:07 +00008559template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008560ExprResult
John McCall865d4472009-11-19 22:55:06 +00008561TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00008562 CXXDependentScopeMemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008563 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008564 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00008565 Expr *OldBase;
8566 QualType BaseType;
8567 QualType ObjectType;
8568 if (!E->isImplicitAccess()) {
8569 OldBase = E->getBase();
8570 Base = getDerived().TransformExpr(OldBase);
8571 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008572 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008573
John McCallaa81e162009-12-01 22:10:20 +00008574 // Start the member reference and compute the object's type.
John McCallb3d87482010-08-24 05:47:05 +00008575 ParsedType ObjectTy;
Douglas Gregord4dca082010-02-24 18:44:31 +00008576 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00008577 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008578 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00008579 E->isArrow()? tok::arrow : tok::period,
Douglas Gregord4dca082010-02-24 18:44:31 +00008580 ObjectTy,
8581 MayBePseudoDestructor);
John McCallaa81e162009-12-01 22:10:20 +00008582 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008583 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00008584
John McCallb3d87482010-08-24 05:47:05 +00008585 ObjectType = ObjectTy.get();
John McCallaa81e162009-12-01 22:10:20 +00008586 BaseType = ((Expr*) Base.get())->getType();
8587 } else {
8588 OldBase = 0;
8589 BaseType = getDerived().TransformType(E->getBaseType());
8590 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
8591 }
Mike Stump1eb44332009-09-09 15:08:12 +00008592
Douglas Gregor6cd21982009-10-20 05:58:46 +00008593 // Transform the first part of the nested-name-specifier that qualifies
8594 // the member name.
Douglas Gregorc68afe22009-09-03 21:38:09 +00008595 NamedDecl *FirstQualifierInScope
Douglas Gregor6cd21982009-10-20 05:58:46 +00008596 = getDerived().TransformFirstQualifierInScope(
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008597 E->getFirstQualifierFoundInScope(),
8598 E->getQualifierLoc().getBeginLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00008599
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008600 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregora38c6872009-09-03 16:14:30 +00008601 if (E->getQualifier()) {
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008602 QualifierLoc
8603 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
8604 ObjectType,
8605 FirstQualifierInScope);
8606 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008607 return ExprError();
Douglas Gregora38c6872009-09-03 16:14:30 +00008608 }
Mike Stump1eb44332009-09-09 15:08:12 +00008609
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008610 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
8611
John McCall43fed0d2010-11-12 08:19:04 +00008612 // TODO: If this is a conversion-function-id, verify that the
8613 // destination type name (if present) resolves the same way after
8614 // instantiation as it did in the local scope.
8615
Abramo Bagnara25777432010-08-11 22:01:17 +00008616 DeclarationNameInfo NameInfo
John McCall43fed0d2010-11-12 08:19:04 +00008617 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnara25777432010-08-11 22:01:17 +00008618 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00008619 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008620
John McCallaa81e162009-12-01 22:10:20 +00008621 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008622 // This is a reference to a member without an explicitly-specified
8623 // template argument list. Optimize for this common case.
8624 if (!getDerived().AlwaysRebuild() &&
John McCallaa81e162009-12-01 22:10:20 +00008625 Base.get() == OldBase &&
8626 BaseType == E->getBaseType() &&
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008627 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00008628 NameInfo.getName() == E->getMember() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008629 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCall3fa5cae2010-10-26 07:05:15 +00008630 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008631
John McCall9ae2f072010-08-23 23:25:46 +00008632 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008633 BaseType,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008634 E->isArrow(),
8635 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008636 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008637 TemplateKWLoc,
John McCall129e2df2009-11-30 22:42:35 +00008638 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00008639 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00008640 /*TemplateArgs*/ 0);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008641 }
8642
John McCalld5532b62009-11-23 01:53:49 +00008643 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008644 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8645 E->getNumTemplateArgs(),
8646 TransArgs))
8647 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008648
John McCall9ae2f072010-08-23 23:25:46 +00008649 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008650 BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008651 E->isArrow(),
8652 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008653 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008654 TemplateKWLoc,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008655 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00008656 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00008657 &TransArgs);
8658}
8659
8660template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008661ExprResult
John McCall454feb92009-12-08 09:21:05 +00008662TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall129e2df2009-11-30 22:42:35 +00008663 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008664 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00008665 QualType BaseType;
8666 if (!Old->isImplicitAccess()) {
8667 Base = getDerived().TransformExpr(Old->getBase());
8668 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008669 return ExprError();
Richard Smith9138b4e2011-10-26 19:06:56 +00008670 Base = getSema().PerformMemberExprBaseConversion(Base.take(),
8671 Old->isArrow());
8672 if (Base.isInvalid())
8673 return ExprError();
8674 BaseType = Base.get()->getType();
John McCallaa81e162009-12-01 22:10:20 +00008675 } else {
8676 BaseType = getDerived().TransformType(Old->getBaseType());
8677 }
John McCall129e2df2009-11-30 22:42:35 +00008678
Douglas Gregor4c9be892011-02-28 20:01:57 +00008679 NestedNameSpecifierLoc QualifierLoc;
8680 if (Old->getQualifierLoc()) {
8681 QualifierLoc
8682 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
8683 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008684 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00008685 }
8686
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008687 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
8688
Abramo Bagnara25777432010-08-11 22:01:17 +00008689 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall129e2df2009-11-30 22:42:35 +00008690 Sema::LookupOrdinaryName);
8691
8692 // Transform all the decls.
8693 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
8694 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00008695 NamedDecl *InstD = static_cast<NamedDecl*>(
8696 getDerived().TransformDecl(Old->getMemberLoc(),
8697 *I));
John McCall9f54ad42009-12-10 09:41:52 +00008698 if (!InstD) {
8699 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
8700 // This can happen because of dependent hiding.
8701 if (isa<UsingShadowDecl>(*I))
8702 continue;
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00008703 else {
8704 R.clear();
John McCallf312b1e2010-08-26 23:41:50 +00008705 return ExprError();
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00008706 }
John McCall9f54ad42009-12-10 09:41:52 +00008707 }
John McCall129e2df2009-11-30 22:42:35 +00008708
8709 // Expand using declarations.
8710 if (isa<UsingDecl>(InstD)) {
8711 UsingDecl *UD = cast<UsingDecl>(InstD);
8712 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
8713 E = UD->shadow_end(); I != E; ++I)
8714 R.addDecl(*I);
8715 continue;
8716 }
8717
8718 R.addDecl(InstD);
8719 }
8720
8721 R.resolveKind();
8722
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008723 // Determine the naming class.
Chandler Carruth042d6f92010-05-19 01:37:01 +00008724 if (Old->getNamingClass()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008725 CXXRecordDecl *NamingClass
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008726 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregor66c45152010-04-27 16:10:10 +00008727 Old->getMemberLoc(),
8728 Old->getNamingClass()));
8729 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00008730 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008731
Douglas Gregor66c45152010-04-27 16:10:10 +00008732 R.setNamingClass(NamingClass);
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008733 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008734
John McCall129e2df2009-11-30 22:42:35 +00008735 TemplateArgumentListInfo TransArgs;
8736 if (Old->hasExplicitTemplateArgs()) {
8737 TransArgs.setLAngleLoc(Old->getLAngleLoc());
8738 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008739 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
8740 Old->getNumTemplateArgs(),
8741 TransArgs))
8742 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00008743 }
John McCallc2233c52010-01-15 08:34:02 +00008744
8745 // FIXME: to do this check properly, we will need to preserve the
8746 // first-qualifier-in-scope here, just in case we had a dependent
8747 // base (and therefore couldn't do the check) and a
8748 // nested-name-qualifier (and therefore could do the lookup).
8749 NamedDecl *FirstQualifierInScope = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008750
John McCall9ae2f072010-08-23 23:25:46 +00008751 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008752 BaseType,
John McCall129e2df2009-11-30 22:42:35 +00008753 Old->getOperatorLoc(),
8754 Old->isArrow(),
Douglas Gregor4c9be892011-02-28 20:01:57 +00008755 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008756 TemplateKWLoc,
John McCallc2233c52010-01-15 08:34:02 +00008757 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00008758 R,
8759 (Old->hasExplicitTemplateArgs()
8760 ? &TransArgs : 0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00008761}
8762
8763template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008764ExprResult
Sebastian Redl2e156222010-09-10 20:55:43 +00008765TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Sean Hunteea06c62011-05-31 19:54:49 +00008766 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl2e156222010-09-10 20:55:43 +00008767 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
8768 if (SubExpr.isInvalid())
8769 return ExprError();
8770
8771 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00008772 return SemaRef.Owned(E);
Sebastian Redl2e156222010-09-10 20:55:43 +00008773
8774 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
8775}
8776
8777template<typename Derived>
8778ExprResult
Douglas Gregorbe230c32011-01-03 17:17:50 +00008779TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor4f1d2822011-01-13 00:19:55 +00008780 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
8781 if (Pattern.isInvalid())
8782 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008783
Douglas Gregor4f1d2822011-01-13 00:19:55 +00008784 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
8785 return SemaRef.Owned(E);
8786
Douglas Gregor67fd1252011-01-14 21:20:45 +00008787 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
8788 E->getNumExpansions());
Douglas Gregorbe230c32011-01-03 17:17:50 +00008789}
Douglas Gregoree8aff02011-01-04 17:33:58 +00008790
8791template<typename Derived>
8792ExprResult
8793TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
8794 // If E is not value-dependent, then nothing will change when we transform it.
8795 // Note: This is an instantiation-centric view.
8796 if (!E->isValueDependent())
8797 return SemaRef.Owned(E);
8798
8799 // Note: None of the implementations of TryExpandParameterPacks can ever
8800 // produce a diagnostic when given only a single unexpanded parameter pack,
Chad Rosier4a9d7952012-08-08 18:46:20 +00008801 // so
Douglas Gregoree8aff02011-01-04 17:33:58 +00008802 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
8803 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00008804 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00008805 Optional<unsigned> NumExpansions;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008806 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikiea71f9d02011-09-22 02:34:54 +00008807 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00008808 ShouldExpand, RetainExpansion,
8809 NumExpansions))
Douglas Gregoree8aff02011-01-04 17:33:58 +00008810 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008811
Douglas Gregor089e8932011-10-10 18:59:29 +00008812 if (RetainExpansion)
Douglas Gregoree8aff02011-01-04 17:33:58 +00008813 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008814
Douglas Gregor089e8932011-10-10 18:59:29 +00008815 NamedDecl *Pack = E->getPack();
8816 if (!ShouldExpand) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008817 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
Douglas Gregor089e8932011-10-10 18:59:29 +00008818 Pack));
8819 if (!Pack)
8820 return ExprError();
8821 }
8822
Chad Rosier4a9d7952012-08-08 18:46:20 +00008823
Douglas Gregoree8aff02011-01-04 17:33:58 +00008824 // We now know the length of the parameter pack, so build a new expression
8825 // that stores that length.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008826 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
8827 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregor089e8932011-10-10 18:59:29 +00008828 NumExpansions);
Douglas Gregoree8aff02011-01-04 17:33:58 +00008829}
8830
Douglas Gregorbe230c32011-01-03 17:17:50 +00008831template<typename Derived>
8832ExprResult
Douglas Gregorc7793c72011-01-15 01:15:58 +00008833TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
8834 SubstNonTypeTemplateParmPackExpr *E) {
8835 // Default behavior is to do nothing with this transformation.
8836 return SemaRef.Owned(E);
8837}
8838
8839template<typename Derived>
8840ExprResult
John McCall91a57552011-07-15 05:09:51 +00008841TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
8842 SubstNonTypeTemplateParmExpr *E) {
8843 // Default behavior is to do nothing with this transformation.
8844 return SemaRef.Owned(E);
8845}
8846
8847template<typename Derived>
8848ExprResult
Richard Smith9a4db032012-09-12 00:56:43 +00008849TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
8850 // Default behavior is to do nothing with this transformation.
8851 return SemaRef.Owned(E);
8852}
8853
8854template<typename Derived>
8855ExprResult
Douglas Gregor03e80032011-06-21 17:03:29 +00008856TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
8857 MaterializeTemporaryExpr *E) {
8858 return getDerived().TransformExpr(E->GetTemporaryExpr());
8859}
Chad Rosier4a9d7952012-08-08 18:46:20 +00008860
Douglas Gregor03e80032011-06-21 17:03:29 +00008861template<typename Derived>
8862ExprResult
Richard Smith7c3e6152013-06-12 22:31:48 +00008863TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
8864 CXXStdInitializerListExpr *E) {
8865 return getDerived().TransformExpr(E->getSubExpr());
8866}
8867
8868template<typename Derived>
8869ExprResult
John McCall454feb92009-12-08 09:21:05 +00008870TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008871 return SemaRef.MaybeBindToTemporary(E);
8872}
8873
8874template<typename Derived>
8875ExprResult
8876TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Jordy Rosed8b5ca12012-03-12 17:53:02 +00008877 return SemaRef.Owned(E);
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008878}
8879
8880template<typename Derived>
8881ExprResult
Patrick Beardeb382ec2012-04-19 00:25:12 +00008882TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
8883 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
8884 if (SubExpr.isInvalid())
8885 return ExprError();
8886
8887 if (!getDerived().AlwaysRebuild() &&
8888 SubExpr.get() == E->getSubExpr())
8889 return SemaRef.Owned(E);
8890
8891 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008892}
8893
8894template<typename Derived>
8895ExprResult
8896TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
8897 // Transform each of the elements.
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00008898 SmallVector<Expr *, 8> Elements;
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008899 bool ArgChanged = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008900 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008901 /*IsCall=*/false, Elements, &ArgChanged))
8902 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008903
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008904 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8905 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008906
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008907 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
8908 Elements.data(),
8909 Elements.size());
8910}
8911
8912template<typename Derived>
8913ExprResult
8914TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier4a9d7952012-08-08 18:46:20 +00008915 ObjCDictionaryLiteral *E) {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008916 // Transform each of the elements.
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00008917 SmallVector<ObjCDictionaryElement, 8> Elements;
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008918 bool ArgChanged = false;
8919 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
8920 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008921
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008922 if (OrigElement.isPackExpansion()) {
8923 // This key/value element is a pack expansion.
8924 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
8925 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
8926 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
8927 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
8928
8929 // Determine whether the set of unexpanded parameter packs can
8930 // and should be expanded.
8931 bool Expand = true;
8932 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00008933 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
8934 Optional<unsigned> NumExpansions = OrigNumExpansions;
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008935 SourceRange PatternRange(OrigElement.Key->getLocStart(),
8936 OrigElement.Value->getLocEnd());
8937 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
8938 PatternRange,
8939 Unexpanded,
8940 Expand, RetainExpansion,
8941 NumExpansions))
8942 return ExprError();
8943
8944 if (!Expand) {
8945 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00008946 // transformation on the pack expansion, producing another pack
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008947 // expansion.
8948 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
8949 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8950 if (Key.isInvalid())
8951 return ExprError();
8952
8953 if (Key.get() != OrigElement.Key)
8954 ArgChanged = true;
8955
8956 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8957 if (Value.isInvalid())
8958 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008959
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008960 if (Value.get() != OrigElement.Value)
8961 ArgChanged = true;
8962
Chad Rosier4a9d7952012-08-08 18:46:20 +00008963 ObjCDictionaryElement Expansion = {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008964 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
8965 };
8966 Elements.push_back(Expansion);
8967 continue;
8968 }
8969
8970 // Record right away that the argument was changed. This needs
8971 // to happen even if the array expands to nothing.
8972 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008973
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008974 // The transform has determined that we should perform an elementwise
8975 // expansion of the pattern. Do so.
8976 for (unsigned I = 0; I != *NumExpansions; ++I) {
8977 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8978 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8979 if (Key.isInvalid())
8980 return ExprError();
8981
8982 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8983 if (Value.isInvalid())
8984 return ExprError();
8985
Chad Rosier4a9d7952012-08-08 18:46:20 +00008986 ObjCDictionaryElement Element = {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008987 Key.get(), Value.get(), SourceLocation(), NumExpansions
8988 };
8989
8990 // If any unexpanded parameter packs remain, we still have a
8991 // pack expansion.
8992 if (Key.get()->containsUnexpandedParameterPack() ||
8993 Value.get()->containsUnexpandedParameterPack())
8994 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008995
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008996 Elements.push_back(Element);
8997 }
8998
8999 // We've finished with this pack expansion.
9000 continue;
9001 }
9002
9003 // Transform and check key.
9004 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
9005 if (Key.isInvalid())
9006 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00009007
Ted Kremenekebcb57a2012-03-06 20:05:56 +00009008 if (Key.get() != OrigElement.Key)
9009 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00009010
Ted Kremenekebcb57a2012-03-06 20:05:56 +00009011 // Transform and check value.
9012 ExprResult Value
9013 = getDerived().TransformExpr(OrigElement.Value);
9014 if (Value.isInvalid())
9015 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00009016
Ted Kremenekebcb57a2012-03-06 20:05:56 +00009017 if (Value.get() != OrigElement.Value)
9018 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00009019
9020 ObjCDictionaryElement Element = {
David Blaikie66874fb2013-02-21 01:47:18 +00009021 Key.get(), Value.get(), SourceLocation(), None
Ted Kremenekebcb57a2012-03-06 20:05:56 +00009022 };
9023 Elements.push_back(Element);
9024 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00009025
Ted Kremenekebcb57a2012-03-06 20:05:56 +00009026 if (!getDerived().AlwaysRebuild() && !ArgChanged)
9027 return SemaRef.MaybeBindToTemporary(E);
9028
9029 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
9030 Elements.data(),
9031 Elements.size());
Douglas Gregorb98b1992009-08-11 05:31:07 +00009032}
9033
Mike Stump1eb44332009-09-09 15:08:12 +00009034template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009035ExprResult
John McCall454feb92009-12-08 09:21:05 +00009036TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregor81d34662010-04-20 15:39:42 +00009037 TypeSourceInfo *EncodedTypeInfo
9038 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
9039 if (!EncodedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00009040 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009041
Douglas Gregorb98b1992009-08-11 05:31:07 +00009042 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor81d34662010-04-20 15:39:42 +00009043 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00009044 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009045
9046 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregor81d34662010-04-20 15:39:42 +00009047 EncodedTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00009048 E->getRParenLoc());
9049}
Mike Stump1eb44332009-09-09 15:08:12 +00009050
Douglas Gregorb98b1992009-08-11 05:31:07 +00009051template<typename Derived>
John McCallf85e1932011-06-15 23:02:42 +00009052ExprResult TreeTransform<Derived>::
9053TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
John McCall93b64572013-04-11 02:14:26 +00009054 // This is a kind of implicit conversion, and it needs to get dropped
9055 // and recomputed for the same general reasons that ImplicitCastExprs
9056 // do, as well a more specific one: this expression is only valid when
9057 // it appears *immediately* as an argument expression.
9058 return getDerived().TransformExpr(E->getSubExpr());
John McCallf85e1932011-06-15 23:02:42 +00009059}
9060
9061template<typename Derived>
9062ExprResult TreeTransform<Derived>::
9063TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00009064 TypeSourceInfo *TSInfo
John McCallf85e1932011-06-15 23:02:42 +00009065 = getDerived().TransformType(E->getTypeInfoAsWritten());
9066 if (!TSInfo)
9067 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00009068
John McCallf85e1932011-06-15 23:02:42 +00009069 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier4a9d7952012-08-08 18:46:20 +00009070 if (Result.isInvalid())
John McCallf85e1932011-06-15 23:02:42 +00009071 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00009072
John McCallf85e1932011-06-15 23:02:42 +00009073 if (!getDerived().AlwaysRebuild() &&
9074 TSInfo == E->getTypeInfoAsWritten() &&
9075 Result.get() == E->getSubExpr())
9076 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00009077
John McCallf85e1932011-06-15 23:02:42 +00009078 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00009079 E->getBridgeKeywordLoc(), TSInfo,
John McCallf85e1932011-06-15 23:02:42 +00009080 Result.get());
9081}
9082
9083template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009084ExprResult
John McCall454feb92009-12-08 09:21:05 +00009085TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00009086 // Transform arguments.
9087 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00009088 SmallVector<Expr*, 8> Args;
Douglas Gregoraa165f82011-01-03 19:04:46 +00009089 Args.reserve(E->getNumArgs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00009090 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00009091 &ArgChanged))
9092 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00009093
Douglas Gregor92e986e2010-04-22 16:44:27 +00009094 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
9095 // Class message: transform the receiver type.
9096 TypeSourceInfo *ReceiverTypeInfo
9097 = getDerived().TransformType(E->getClassReceiverTypeInfo());
9098 if (!ReceiverTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00009099 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00009100
Douglas Gregor92e986e2010-04-22 16:44:27 +00009101 // If nothing changed, just retain the existing message send.
9102 if (!getDerived().AlwaysRebuild() &&
9103 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00009104 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor92e986e2010-04-22 16:44:27 +00009105
9106 // Build a new class message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00009107 SmallVector<SourceLocation, 16> SelLocs;
9108 E->getSelectorLocs(SelLocs);
Douglas Gregor92e986e2010-04-22 16:44:27 +00009109 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
9110 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00009111 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00009112 E->getMethodDecl(),
9113 E->getLeftLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009114 Args,
Douglas Gregor92e986e2010-04-22 16:44:27 +00009115 E->getRightLoc());
9116 }
9117
9118 // Instance message: transform the receiver
9119 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
9120 "Only class and instance messages may be instantiated");
John McCall60d7b3a2010-08-24 06:29:42 +00009121 ExprResult Receiver
Douglas Gregor92e986e2010-04-22 16:44:27 +00009122 = getDerived().TransformExpr(E->getInstanceReceiver());
9123 if (Receiver.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009124 return ExprError();
Douglas Gregor92e986e2010-04-22 16:44:27 +00009125
9126 // If nothing changed, just retain the existing message send.
9127 if (!getDerived().AlwaysRebuild() &&
9128 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00009129 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00009130
Douglas Gregor92e986e2010-04-22 16:44:27 +00009131 // Build a new instance message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00009132 SmallVector<SourceLocation, 16> SelLocs;
9133 E->getSelectorLocs(SelLocs);
John McCall9ae2f072010-08-23 23:25:46 +00009134 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00009135 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00009136 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00009137 E->getMethodDecl(),
9138 E->getLeftLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009139 Args,
Douglas Gregor92e986e2010-04-22 16:44:27 +00009140 E->getRightLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00009141}
9142
Mike Stump1eb44332009-09-09 15:08:12 +00009143template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009144ExprResult
John McCall454feb92009-12-08 09:21:05 +00009145TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00009146 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009147}
9148
Mike Stump1eb44332009-09-09 15:08:12 +00009149template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009150ExprResult
John McCall454feb92009-12-08 09:21:05 +00009151TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00009152 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009153}
9154
Mike Stump1eb44332009-09-09 15:08:12 +00009155template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009156ExprResult
John McCall454feb92009-12-08 09:21:05 +00009157TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009158 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00009159 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009160 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009161 return ExprError();
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009162
9163 // We don't need to transform the ivar; it will never change.
Chad Rosier4a9d7952012-08-08 18:46:20 +00009164
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009165 // If nothing changed, just retain the existing expression.
9166 if (!getDerived().AlwaysRebuild() &&
9167 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00009168 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00009169
John McCall9ae2f072010-08-23 23:25:46 +00009170 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009171 E->getLocation(),
9172 E->isArrow(), E->isFreeIvar());
Douglas Gregorb98b1992009-08-11 05:31:07 +00009173}
9174
Mike Stump1eb44332009-09-09 15:08:12 +00009175template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009176ExprResult
John McCall454feb92009-12-08 09:21:05 +00009177TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCall12f78a62010-12-02 01:19:52 +00009178 // 'super' and types never change. Property never changes. Just
9179 // retain the existing expression.
9180 if (!E->isObjectReceiver())
John McCall3fa5cae2010-10-26 07:05:15 +00009181 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00009182
Douglas Gregore3303542010-04-26 20:47:02 +00009183 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00009184 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregore3303542010-04-26 20:47:02 +00009185 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009186 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00009187
Douglas Gregore3303542010-04-26 20:47:02 +00009188 // We don't need to transform the property; it will never change.
Chad Rosier4a9d7952012-08-08 18:46:20 +00009189
Douglas Gregore3303542010-04-26 20:47:02 +00009190 // If nothing changed, just retain the existing expression.
9191 if (!getDerived().AlwaysRebuild() &&
9192 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00009193 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009194
John McCall12f78a62010-12-02 01:19:52 +00009195 if (E->isExplicitProperty())
9196 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
9197 E->getExplicitProperty(),
9198 E->getLocation());
9199
9200 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall3c3b7f92011-10-25 17:37:35 +00009201 SemaRef.Context.PseudoObjectTy,
John McCall12f78a62010-12-02 01:19:52 +00009202 E->getImplicitPropertyGetter(),
9203 E->getImplicitPropertySetter(),
9204 E->getLocation());
Douglas Gregorb98b1992009-08-11 05:31:07 +00009205}
9206
Mike Stump1eb44332009-09-09 15:08:12 +00009207template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009208ExprResult
Ted Kremenekebcb57a2012-03-06 20:05:56 +00009209TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
9210 // Transform the base expression.
9211 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
9212 if (Base.isInvalid())
9213 return ExprError();
9214
9215 // Transform the key expression.
9216 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
9217 if (Key.isInvalid())
9218 return ExprError();
9219
9220 // If nothing changed, just retain the existing expression.
9221 if (!getDerived().AlwaysRebuild() &&
9222 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
9223 return SemaRef.Owned(E);
9224
Chad Rosier4a9d7952012-08-08 18:46:20 +00009225 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremenekebcb57a2012-03-06 20:05:56 +00009226 Base.get(), Key.get(),
9227 E->getAtIndexMethodDecl(),
9228 E->setAtIndexMethodDecl());
9229}
9230
9231template<typename Derived>
9232ExprResult
John McCall454feb92009-12-08 09:21:05 +00009233TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009234 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00009235 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009236 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009237 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00009238
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009239 // If nothing changed, just retain the existing expression.
9240 if (!getDerived().AlwaysRebuild() &&
9241 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00009242 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00009243
John McCall9ae2f072010-08-23 23:25:46 +00009244 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Fariborz Jahanianec8deba2013-03-28 19:50:55 +00009245 E->getOpLoc(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009246 E->isArrow());
Douglas Gregorb98b1992009-08-11 05:31:07 +00009247}
9248
Mike Stump1eb44332009-09-09 15:08:12 +00009249template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009250ExprResult
John McCall454feb92009-12-08 09:21:05 +00009251TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009252 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00009253 SmallVector<Expr*, 8> SubExprs;
Douglas Gregoraa165f82011-01-03 19:04:46 +00009254 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00009255 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregoraa165f82011-01-03 19:04:46 +00009256 SubExprs, &ArgumentChanged))
9257 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009258
Douglas Gregorb98b1992009-08-11 05:31:07 +00009259 if (!getDerived().AlwaysRebuild() &&
9260 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00009261 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00009262
Douglas Gregorb98b1992009-08-11 05:31:07 +00009263 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009264 SubExprs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00009265 E->getRParenLoc());
9266}
9267
Mike Stump1eb44332009-09-09 15:08:12 +00009268template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009269ExprResult
Hal Finkel414a1bd2013-09-18 03:29:45 +00009270TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) {
9271 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
9272 if (SrcExpr.isInvalid())
9273 return ExprError();
9274
9275 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
9276 if (!Type)
9277 return ExprError();
9278
9279 if (!getDerived().AlwaysRebuild() &&
9280 Type == E->getTypeSourceInfo() &&
9281 SrcExpr.get() == E->getSrcExpr())
9282 return SemaRef.Owned(E);
9283
9284 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
9285 SrcExpr.get(), Type,
9286 E->getRParenLoc());
9287}
9288
9289template<typename Derived>
9290ExprResult
John McCall454feb92009-12-08 09:21:05 +00009291TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCallc6ac9c32011-02-04 18:33:18 +00009292 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier4a9d7952012-08-08 18:46:20 +00009293
John McCallc6ac9c32011-02-04 18:33:18 +00009294 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
9295 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
9296
9297 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahanian05865202011-12-03 17:47:53 +00009298 blockScope->TheDecl->setBlockMissingReturnType(
9299 oldBlock->blockMissingReturnType());
Chad Rosier4a9d7952012-08-08 18:46:20 +00009300
Chris Lattner686775d2011-07-20 06:58:45 +00009301 SmallVector<ParmVarDecl*, 4> params;
9302 SmallVector<QualType, 4> paramTypes;
Chad Rosier4a9d7952012-08-08 18:46:20 +00009303
Fariborz Jahaniana729da22010-07-09 18:44:02 +00009304 // Parameter substitution.
John McCallc6ac9c32011-02-04 18:33:18 +00009305 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
9306 oldBlock->param_begin(),
9307 oldBlock->param_size(),
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00009308 0, paramTypes, &params)) {
9309 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregor92be2a52011-12-10 00:23:21 +00009310 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00009311 }
John McCallc6ac9c32011-02-04 18:33:18 +00009312
Jordan Rose09189892013-03-08 22:25:36 +00009313 const FunctionProtoType *exprFunctionType = E->getFunctionType();
Eli Friedman84b007f2012-01-26 03:00:14 +00009314 QualType exprResultType =
9315 getDerived().TransformType(exprFunctionType->getResultType());
Douglas Gregora779d9c2011-01-19 21:32:01 +00009316
Jordan Rosebea522f2013-03-08 21:51:21 +00009317 QualType functionType =
9318 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes,
Jordan Rose09189892013-03-08 22:25:36 +00009319 exprFunctionType->getExtProtoInfo());
John McCallc6ac9c32011-02-04 18:33:18 +00009320 blockScope->FunctionType = functionType;
John McCall711c52b2011-01-05 12:14:39 +00009321
9322 // Set the parameters on the block decl.
John McCallc6ac9c32011-02-04 18:33:18 +00009323 if (!params.empty())
David Blaikie4278c652011-09-21 18:16:56 +00009324 blockScope->TheDecl->setParams(params);
Eli Friedman84b007f2012-01-26 03:00:14 +00009325
9326 if (!oldBlock->blockMissingReturnType()) {
9327 blockScope->HasImplicitReturnType = false;
9328 blockScope->ReturnType = exprResultType;
9329 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00009330
John McCall711c52b2011-01-05 12:14:39 +00009331 // Transform the body
John McCallc6ac9c32011-02-04 18:33:18 +00009332 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00009333 if (body.isInvalid()) {
9334 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
John McCall711c52b2011-01-05 12:14:39 +00009335 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00009336 }
John McCall711c52b2011-01-05 12:14:39 +00009337
John McCallc6ac9c32011-02-04 18:33:18 +00009338#ifndef NDEBUG
9339 // In builds with assertions, make sure that we captured everything we
9340 // captured before.
Douglas Gregorfc921372011-05-20 15:32:55 +00009341 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
9342 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
9343 e = oldBlock->capture_end(); i != e; ++i) {
9344 VarDecl *oldCapture = i->getVariable();
John McCallc6ac9c32011-02-04 18:33:18 +00009345
Douglas Gregorfc921372011-05-20 15:32:55 +00009346 // Ignore parameter packs.
9347 if (isa<ParmVarDecl>(oldCapture) &&
9348 cast<ParmVarDecl>(oldCapture)->isParameterPack())
9349 continue;
John McCallc6ac9c32011-02-04 18:33:18 +00009350
Douglas Gregorfc921372011-05-20 15:32:55 +00009351 VarDecl *newCapture =
9352 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
9353 oldCapture));
9354 assert(blockScope->CaptureMap.count(newCapture));
9355 }
Douglas Gregorec79d872012-02-24 17:41:38 +00009356 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCallc6ac9c32011-02-04 18:33:18 +00009357 }
9358#endif
9359
9360 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
9361 /*Scope=*/0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009362}
9363
Mike Stump1eb44332009-09-09 15:08:12 +00009364template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009365ExprResult
Tanya Lattner61eee0c2011-06-04 00:47:47 +00009366TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikieb219cfc2011-09-23 05:06:16 +00009367 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner61eee0c2011-06-04 00:47:47 +00009368}
Eli Friedman276b0612011-10-11 02:20:01 +00009369
9370template<typename Derived>
9371ExprResult
9372TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedmandfa64ba2011-10-14 22:48:56 +00009373 QualType RetTy = getDerived().TransformType(E->getType());
9374 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00009375 SmallVector<Expr*, 8> SubExprs;
Eli Friedmandfa64ba2011-10-14 22:48:56 +00009376 SubExprs.reserve(E->getNumSubExprs());
9377 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
9378 SubExprs, &ArgumentChanged))
9379 return ExprError();
9380
9381 if (!getDerived().AlwaysRebuild() &&
9382 !ArgumentChanged)
9383 return SemaRef.Owned(E);
9384
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009385 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedmandfa64ba2011-10-14 22:48:56 +00009386 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedman276b0612011-10-11 02:20:01 +00009387}
Chad Rosier4a9d7952012-08-08 18:46:20 +00009388
Douglas Gregorb98b1992009-08-11 05:31:07 +00009389//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00009390// Type reconstruction
9391//===----------------------------------------------------------------------===//
9392
Mike Stump1eb44332009-09-09 15:08:12 +00009393template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00009394QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
9395 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00009396 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009397 getDerived().getBaseEntity());
9398}
9399
Mike Stump1eb44332009-09-09 15:08:12 +00009400template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00009401QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
9402 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00009403 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009404 getDerived().getBaseEntity());
9405}
9406
Mike Stump1eb44332009-09-09 15:08:12 +00009407template<typename Derived>
9408QualType
John McCall85737a72009-10-30 00:06:24 +00009409TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
9410 bool WrittenAsLValue,
9411 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00009412 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall85737a72009-10-30 00:06:24 +00009413 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00009414}
9415
9416template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009417QualType
John McCall85737a72009-10-30 00:06:24 +00009418TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
9419 QualType ClassType,
9420 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00009421 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall85737a72009-10-30 00:06:24 +00009422 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00009423}
9424
9425template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009426QualType
Douglas Gregor577f75a2009-08-04 16:50:30 +00009427TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
9428 ArrayType::ArraySizeModifier SizeMod,
9429 const llvm::APInt *Size,
9430 Expr *SizeExpr,
9431 unsigned IndexTypeQuals,
9432 SourceRange BracketsRange) {
9433 if (SizeExpr || !Size)
9434 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
9435 IndexTypeQuals, BracketsRange,
9436 getDerived().getBaseEntity());
Mike Stump1eb44332009-09-09 15:08:12 +00009437
9438 QualType Types[] = {
9439 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
9440 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
9441 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregor577f75a2009-08-04 16:50:30 +00009442 };
Craig Topperb9602322013-07-15 03:38:40 +00009443 const unsigned NumTypes = llvm::array_lengthof(Types);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009444 QualType SizeType;
9445 for (unsigned I = 0; I != NumTypes; ++I)
9446 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
9447 SizeType = Types[I];
9448 break;
9449 }
Mike Stump1eb44332009-09-09 15:08:12 +00009450
Eli Friedman01f276d2012-01-25 23:20:27 +00009451 // Note that we can return a VariableArrayType here in the case where
9452 // the element type was a dependent VariableArrayType.
9453 IntegerLiteral *ArraySize
9454 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
9455 /*FIXME*/BracketsRange.getBegin());
9456 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009457 IndexTypeQuals, BracketsRange,
Mike Stump1eb44332009-09-09 15:08:12 +00009458 getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00009459}
Mike Stump1eb44332009-09-09 15:08:12 +00009460
Douglas Gregor577f75a2009-08-04 16:50:30 +00009461template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009462QualType
9463TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009464 ArrayType::ArraySizeModifier SizeMod,
9465 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +00009466 unsigned IndexTypeQuals,
9467 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009468 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall85737a72009-10-30 00:06:24 +00009469 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009470}
9471
9472template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009473QualType
Mike Stump1eb44332009-09-09 15:08:12 +00009474TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009475 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +00009476 unsigned IndexTypeQuals,
9477 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009478 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall85737a72009-10-30 00:06:24 +00009479 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009480}
Mike Stump1eb44332009-09-09 15:08:12 +00009481
Douglas Gregor577f75a2009-08-04 16:50:30 +00009482template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009483QualType
9484TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009485 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00009486 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009487 unsigned IndexTypeQuals,
9488 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009489 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00009490 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009491 IndexTypeQuals, BracketsRange);
9492}
9493
9494template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009495QualType
9496TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009497 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00009498 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009499 unsigned IndexTypeQuals,
9500 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009501 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00009502 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009503 IndexTypeQuals, BracketsRange);
9504}
9505
9506template<typename Derived>
9507QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsone86d78c2010-11-10 21:56:12 +00009508 unsigned NumElements,
9509 VectorType::VectorKind VecKind) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00009510 // FIXME: semantic checking!
Bob Wilsone86d78c2010-11-10 21:56:12 +00009511 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009512}
Mike Stump1eb44332009-09-09 15:08:12 +00009513
Douglas Gregor577f75a2009-08-04 16:50:30 +00009514template<typename Derived>
9515QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
9516 unsigned NumElements,
9517 SourceLocation AttributeLoc) {
9518 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
9519 NumElements, true);
9520 IntegerLiteral *VectorSize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00009521 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
9522 AttributeLoc);
John McCall9ae2f072010-08-23 23:25:46 +00009523 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009524}
Mike Stump1eb44332009-09-09 15:08:12 +00009525
Douglas Gregor577f75a2009-08-04 16:50:30 +00009526template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009527QualType
9528TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00009529 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009530 SourceLocation AttributeLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00009531 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009532}
Mike Stump1eb44332009-09-09 15:08:12 +00009533
Douglas Gregor577f75a2009-08-04 16:50:30 +00009534template<typename Derived>
Jordan Rosebea522f2013-03-08 21:51:21 +00009535QualType TreeTransform<Derived>::RebuildFunctionProtoType(
9536 QualType T,
9537 llvm::MutableArrayRef<QualType> ParamTypes,
Jordan Rose09189892013-03-08 22:25:36 +00009538 const FunctionProtoType::ExtProtoInfo &EPI) {
9539 return SemaRef.BuildFunctionType(T, ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009540 getDerived().getBaseLocation(),
Eli Friedmanfa869542010-08-05 02:54:05 +00009541 getDerived().getBaseEntity(),
Jordan Rose09189892013-03-08 22:25:36 +00009542 EPI);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009543}
Mike Stump1eb44332009-09-09 15:08:12 +00009544
Douglas Gregor577f75a2009-08-04 16:50:30 +00009545template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00009546QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
9547 return SemaRef.Context.getFunctionNoProtoType(T);
9548}
9549
9550template<typename Derived>
John McCalled976492009-12-04 22:46:56 +00009551QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
9552 assert(D && "no decl found");
9553 if (D->isInvalidDecl()) return QualType();
9554
Douglas Gregor92e986e2010-04-22 16:44:27 +00009555 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCalled976492009-12-04 22:46:56 +00009556 TypeDecl *Ty;
9557 if (isa<UsingDecl>(D)) {
9558 UsingDecl *Using = cast<UsingDecl>(D);
Enea Zaffanella8d030c72013-07-22 10:54:09 +00009559 assert(Using->hasTypename() &&
John McCalled976492009-12-04 22:46:56 +00009560 "UnresolvedUsingTypenameDecl transformed to non-typename using");
9561
9562 // A valid resolved using typename decl points to exactly one type decl.
9563 assert(++Using->shadow_begin() == Using->shadow_end());
9564 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Chad Rosier4a9d7952012-08-08 18:46:20 +00009565
John McCalled976492009-12-04 22:46:56 +00009566 } else {
9567 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
9568 "UnresolvedUsingTypenameDecl transformed to non-using decl");
9569 Ty = cast<UnresolvedUsingTypenameDecl>(D);
9570 }
9571
9572 return SemaRef.Context.getTypeDeclType(Ty);
9573}
9574
9575template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00009576QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
9577 SourceLocation Loc) {
9578 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009579}
9580
9581template<typename Derived>
9582QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
9583 return SemaRef.Context.getTypeOfType(Underlying);
9584}
9585
9586template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00009587QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
9588 SourceLocation Loc) {
9589 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009590}
9591
9592template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00009593QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
9594 UnaryTransformType::UTTKind UKind,
9595 SourceLocation Loc) {
9596 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
9597}
9598
9599template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00009600QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00009601 TemplateName Template,
9602 SourceLocation TemplateNameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +00009603 TemplateArgumentListInfo &TemplateArgs) {
John McCalld5532b62009-11-23 01:53:49 +00009604 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009605}
Mike Stump1eb44332009-09-09 15:08:12 +00009606
Douglas Gregordcee1a12009-08-06 05:28:30 +00009607template<typename Derived>
Eli Friedmanb001de72011-10-06 23:00:33 +00009608QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
9609 SourceLocation KWLoc) {
9610 return SemaRef.BuildAtomicType(ValueType, KWLoc);
9611}
9612
9613template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009614TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009615TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +00009616 bool TemplateKW,
9617 TemplateDecl *Template) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009618 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregord1067e52009-08-06 06:41:21 +00009619 Template);
9620}
9621
9622template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009623TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009624TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
9625 const IdentifierInfo &Name,
9626 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +00009627 QualType ObjectType,
9628 NamedDecl *FirstQualifierInScope) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009629 UnqualifiedId TemplateName;
9630 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregord6ab2322010-06-16 23:00:59 +00009631 Sema::TemplateTy Template;
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009632 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00009633 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009634 SS, TemplateKWLoc, TemplateName,
John McCallb3d87482010-08-24 05:47:05 +00009635 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00009636 /*EnteringContext=*/false,
9637 Template);
John McCall43fed0d2010-11-12 08:19:04 +00009638 return Template.get();
Douglas Gregord1067e52009-08-06 06:41:21 +00009639}
Mike Stump1eb44332009-09-09 15:08:12 +00009640
Douglas Gregorb98b1992009-08-11 05:31:07 +00009641template<typename Derived>
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009642TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009643TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009644 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009645 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009646 QualType ObjectType) {
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009647 UnqualifiedId Name;
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009648 // FIXME: Bogus location information.
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009649 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009650 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009651 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00009652 Sema::TemplateTy Template;
9653 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009654 SS, TemplateKWLoc, Name,
John McCallb3d87482010-08-24 05:47:05 +00009655 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00009656 /*EnteringContext=*/false,
9657 Template);
Serge Pavlov18062392013-08-27 13:15:56 +00009658 return Template.get();
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009659}
Chad Rosier4a9d7952012-08-08 18:46:20 +00009660
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009661template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009662ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00009663TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
9664 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00009665 Expr *OrigCallee,
9666 Expr *First,
9667 Expr *Second) {
9668 Expr *Callee = OrigCallee->IgnoreParenCasts();
9669 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump1eb44332009-09-09 15:08:12 +00009670
Douglas Gregorb98b1992009-08-11 05:31:07 +00009671 // Determine whether this should be a builtin operation.
Sebastian Redlf322ed62009-10-29 20:17:01 +00009672 if (Op == OO_Subscript) {
John McCall9ae2f072010-08-23 23:25:46 +00009673 if (!First->getType()->isOverloadableType() &&
9674 !Second->getType()->isOverloadableType())
9675 return getSema().CreateBuiltinArraySubscriptExpr(First,
9676 Callee->getLocStart(),
9677 Second, OpLoc);
Eli Friedman1a3c75f2009-11-16 19:13:03 +00009678 } else if (Op == OO_Arrow) {
9679 // -> is never a builtin operation.
John McCall9ae2f072010-08-23 23:25:46 +00009680 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
9681 } else if (Second == 0 || isPostIncDec) {
9682 if (!First->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009683 // The argument is not of overloadable type, so try to create a
9684 // built-in unary operation.
John McCall2de56d12010-08-25 11:45:40 +00009685 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00009686 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump1eb44332009-09-09 15:08:12 +00009687
John McCall9ae2f072010-08-23 23:25:46 +00009688 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009689 }
9690 } else {
John McCall9ae2f072010-08-23 23:25:46 +00009691 if (!First->getType()->isOverloadableType() &&
9692 !Second->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009693 // Neither of the arguments is an overloadable type, so try to
9694 // create a built-in binary operation.
John McCall2de56d12010-08-25 11:45:40 +00009695 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00009696 ExprResult Result
John McCall9ae2f072010-08-23 23:25:46 +00009697 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009698 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009699 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009700
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009701 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00009702 }
9703 }
Mike Stump1eb44332009-09-09 15:08:12 +00009704
9705 // Compute the transformed set of functions (and function templates) to be
Douglas Gregorb98b1992009-08-11 05:31:07 +00009706 // used during overload resolution.
John McCall6e266892010-01-26 03:27:55 +00009707 UnresolvedSet<16> Functions;
Mike Stump1eb44332009-09-09 15:08:12 +00009708
John McCall9ae2f072010-08-23 23:25:46 +00009709 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCallba135432009-11-21 08:51:07 +00009710 assert(ULE->requiresADL());
9711
9712 // FIXME: Do we have to check
9713 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall6e266892010-01-26 03:27:55 +00009714 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCallba135432009-11-21 08:51:07 +00009715 } else {
Richard Smithf6411662012-11-28 21:47:39 +00009716 // If we've resolved this to a particular non-member function, just call
9717 // that function. If we resolved it to a member function,
9718 // CreateOverloaded* will find that function for us.
9719 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
9720 if (!isa<CXXMethodDecl>(ND))
9721 Functions.addDecl(ND);
John McCallba135432009-11-21 08:51:07 +00009722 }
Mike Stump1eb44332009-09-09 15:08:12 +00009723
Douglas Gregorb98b1992009-08-11 05:31:07 +00009724 // Add any functions found via argument-dependent lookup.
John McCall9ae2f072010-08-23 23:25:46 +00009725 Expr *Args[2] = { First, Second };
9726 unsigned NumArgs = 1 + (Second != 0);
Mike Stump1eb44332009-09-09 15:08:12 +00009727
Douglas Gregorb98b1992009-08-11 05:31:07 +00009728 // Create the overloaded operator invocation for unary operators.
9729 if (NumArgs == 1 || isPostIncDec) {
John McCall2de56d12010-08-25 11:45:40 +00009730 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00009731 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCall9ae2f072010-08-23 23:25:46 +00009732 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009733 }
Mike Stump1eb44332009-09-09 15:08:12 +00009734
Douglas Gregor5b8968c2011-07-15 16:25:15 +00009735 if (Op == OO_Subscript) {
9736 SourceLocation LBrace;
9737 SourceLocation RBrace;
9738
9739 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
9740 DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
9741 LBrace = SourceLocation::getFromRawEncoding(
9742 NameLoc.CXXOperatorName.BeginOpNameLoc);
9743 RBrace = SourceLocation::getFromRawEncoding(
9744 NameLoc.CXXOperatorName.EndOpNameLoc);
9745 } else {
9746 LBrace = Callee->getLocStart();
9747 RBrace = OpLoc;
9748 }
9749
9750 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
9751 First, Second);
9752 }
Sebastian Redlf322ed62009-10-29 20:17:01 +00009753
Douglas Gregorb98b1992009-08-11 05:31:07 +00009754 // Create the overloaded operator invocation for binary operators.
John McCall2de56d12010-08-25 11:45:40 +00009755 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00009756 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00009757 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
9758 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009759 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009760
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009761 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00009762}
Mike Stump1eb44332009-09-09 15:08:12 +00009763
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009764template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00009765ExprResult
John McCall9ae2f072010-08-23 23:25:46 +00009766TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009767 SourceLocation OperatorLoc,
9768 bool isArrow,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00009769 CXXScopeSpec &SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009770 TypeSourceInfo *ScopeType,
9771 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00009772 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009773 PseudoDestructorTypeStorage Destroyed) {
John McCall9ae2f072010-08-23 23:25:46 +00009774 QualType BaseType = Base->getType();
9775 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009776 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier4a9d7952012-08-08 18:46:20 +00009777 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greifbf2ca2f2010-02-25 13:04:33 +00009778 !BaseType->getAs<PointerType>()->getPointeeType()
9779 ->template getAs<RecordType>())){
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009780 // This pseudo-destructor expression is still a pseudo-destructor.
John McCall9ae2f072010-08-23 23:25:46 +00009781 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009782 isArrow? tok::arrow : tok::period,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00009783 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009784 Destroyed,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009785 /*FIXME?*/true);
9786 }
Abramo Bagnara25777432010-08-11 22:01:17 +00009787
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009788 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnara25777432010-08-11 22:01:17 +00009789 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
9790 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
9791 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
9792 NameInfo.setNamedTypeInfo(DestroyedType);
9793
Richard Smith6314db92012-05-15 06:15:11 +00009794 // The scope type is now known to be a valid nested name specifier
9795 // component. Tack it on to the end of the nested name specifier.
9796 if (ScopeType)
9797 SS.Extend(SemaRef.Context, SourceLocation(),
9798 ScopeType->getTypeLoc(), CCLoc);
Abramo Bagnara25777432010-08-11 22:01:17 +00009799
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009800 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCall9ae2f072010-08-23 23:25:46 +00009801 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009802 OperatorLoc, isArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009803 SS, TemplateKWLoc,
9804 /*FIXME: FirstQualifier*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00009805 NameInfo,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009806 /*TemplateArgs*/ 0);
9807}
9808
Tareq A. Siraj051303c2013-04-16 18:53:08 +00009809template<typename Derived>
9810StmtResult
9811TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
Wei Pan9fd6b8f2013-05-04 03:59:06 +00009812 SourceLocation Loc = S->getLocStart();
9813 unsigned NumParams = S->getCapturedDecl()->getNumParams();
9814 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/0,
9815 S->getCapturedRegionKind(), NumParams);
9816 StmtResult Body = getDerived().TransformStmt(S->getCapturedStmt());
9817
9818 if (Body.isInvalid()) {
9819 getSema().ActOnCapturedRegionError();
9820 return StmtError();
9821 }
9822
9823 return getSema().ActOnCapturedRegionEnd(Body.take());
Tareq A. Siraj051303c2013-04-16 18:53:08 +00009824}
9825
Douglas Gregor577f75a2009-08-04 16:50:30 +00009826} // end namespace clang
9827
9828#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H