blob: 9d62e7c4daee8e944d27cb09fa37543c70843bad [file] [log] [blame]
Chris Lattnercab02a62011-02-17 20:34:02 +00001//===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===//
Douglas Gregord6ff3322009-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 Lattnercab02a62011-02-17 20:34:02 +00007//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-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 Lattnercab02a62011-02-17 20:34:02 +000012//===----------------------------------------------------------------------===//
13
Douglas Gregord6ff3322009-08-04 16:50:30 +000014#ifndef LLVM_CLANG_SEMA_TREETRANSFORM_H
15#define LLVM_CLANG_SEMA_TREETRANSFORM_H
16
Chandler Carruth3a022472012-12-04 09:13:33 +000017#include "TypeLocBuilder.h"
Douglas Gregor2b6ca462009-09-03 21:38:09 +000018#include "clang/AST/Decl.h"
John McCallde6836a2010-08-24 07:21:54 +000019#include "clang/AST/DeclObjC.h"
Richard Smith3f1b5d02011-05-05 21:57:07 +000020#include "clang/AST/DeclTemplate.h"
Douglas Gregor766b0bb2009-08-06 22:17:10 +000021#include "clang/AST/Expr.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000022#include "clang/AST/ExprCXX.h"
23#include "clang/AST/ExprObjC.h"
Douglas Gregorebe10102009-08-20 07:17:43 +000024#include "clang/AST/Stmt.h"
25#include "clang/AST/StmtCXX.h"
26#include "clang/AST/StmtObjC.h"
Alexey Bataev5ec3eb12013-07-19 03:13:43 +000027#include "clang/AST/StmtOpenMP.h"
Chandler Carruth3a022472012-12-04 09:13:33 +000028#include "clang/Sema/Designator.h"
29#include "clang/Sema/Lookup.h"
30#include "clang/Sema/Ownership.h"
31#include "clang/Sema/ParsedTemplate.h"
32#include "clang/Sema/ScopeInfo.h"
33#include "clang/Sema/SemaDiagnostic.h"
34#include "clang/Sema/SemaInternal.h"
David Blaikieb9c168a2011-09-22 02:34:54 +000035#include "llvm/ADT/ArrayRef.h"
John McCall550e0c22009-10-21 00:40:46 +000036#include "llvm/Support/ErrorHandling.h"
Douglas Gregord6ff3322009-08-04 16:50:30 +000037#include <algorithm>
38
39namespace clang {
John McCallaab3e412010-08-25 08:40:02 +000040using namespace sema;
Mike Stump11289f42009-09-09 15:08:12 +000041
Douglas Gregord6ff3322009-08-04 16:50:30 +000042/// \brief A semantic tree transformation that allows one to transform one
43/// abstract syntax tree into another.
44///
Mike Stump11289f42009-09-09 15:08:12 +000045/// A new tree transformation is defined by creating a new subclass \c X of
46/// \c TreeTransform<X> and then overriding certain operations to provide
47/// behavior specific to that transformation. For example, template
Douglas Gregord6ff3322009-08-04 16:50:30 +000048/// instantiation is implemented as a tree transformation where the
49/// transformation of TemplateTypeParmType nodes involves substituting the
50/// template arguments for their corresponding template parameters; a similar
51/// transformation is performed for non-type template parameters and
52/// template template parameters.
53///
54/// This tree-transformation template uses static polymorphism to allow
Mike Stump11289f42009-09-09 15:08:12 +000055/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregord6ff3322009-08-04 16:50:30 +000056/// override any of the transformation or rebuild operators by providing an
57/// operation with the same signature as the default implementation. The
58/// overridding function should not be virtual.
59///
60/// Semantic tree transformations are split into two stages, either of which
61/// can be replaced by a subclass. The "transform" step transforms an AST node
62/// or the parts of an AST node using the various transformation functions,
63/// then passes the pieces on to the "rebuild" step, which constructs a new AST
64/// node of the appropriate kind from the pieces. The default transformation
65/// routines recursively transform the operands to composite AST nodes (e.g.,
66/// the pointee type of a PointerType node) and, if any of those operand nodes
67/// were changed by the transformation, invokes the rebuild operation to create
68/// a new AST node.
69///
Mike Stump11289f42009-09-09 15:08:12 +000070/// Subclasses can customize the transformation at various levels. The
Douglas Gregore922c772009-08-04 22:27:00 +000071/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregorfd35cde2011-03-02 18:50:38 +000072/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(),
Douglas Gregord6ff3322009-08-04 16:50:30 +000073/// TransformTemplateName(), or TransformTemplateArgument() with entirely
74/// new implementations.
75///
76/// For more fine-grained transformations, subclasses can replace any of the
77/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
Douglas Gregorebe10102009-08-20 07:17:43 +000078/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregord6ff3322009-08-04 16:50:30 +000079/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump11289f42009-09-09 15:08:12 +000080/// to substitute template arguments for their corresponding template
Douglas Gregord6ff3322009-08-04 16:50:30 +000081/// parameters. Additionally, subclasses can override the \c RebuildXXX
82/// functions to control how AST nodes are rebuilt when their operands change.
83/// By default, \c TreeTransform will invoke semantic analysis to rebuild
84/// AST nodes. However, certain other tree transformations (e.g, cloning) may
85/// be able to use more efficient rebuild steps.
86///
87/// There are a handful of other functions that can be overridden, allowing one
Mike Stump11289f42009-09-09 15:08:12 +000088/// to avoid traversing nodes that don't need any transformation
Douglas Gregord6ff3322009-08-04 16:50:30 +000089/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
90/// operands have not changed (\c AlwaysRebuild()), and customize the
91/// default locations and entity names used for type-checking
92/// (\c getBaseLocation(), \c getBaseEntity()).
Douglas Gregord6ff3322009-08-04 16:50:30 +000093template<typename Derived>
94class TreeTransform {
Douglas Gregora8bac7f2011-01-10 07:32:04 +000095 /// \brief Private RAII object that helps us forget and then re-remember
96 /// the template argument corresponding to a partially-substituted parameter
97 /// pack.
98 class ForgetPartiallySubstitutedPackRAII {
99 Derived &Self;
100 TemplateArgument Old;
Chad Rosier1dcde962012-08-08 18:46:20 +0000101
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000102 public:
103 ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) {
104 Old = Self.ForgetPartiallySubstitutedPack();
105 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000106
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000107 ~ForgetPartiallySubstitutedPackRAII() {
108 Self.RememberPartiallySubstitutedPack(Old);
109 }
110 };
Chad Rosier1dcde962012-08-08 18:46:20 +0000111
Douglas Gregord6ff3322009-08-04 16:50:30 +0000112protected:
113 Sema &SemaRef;
Chad Rosier1dcde962012-08-08 18:46:20 +0000114
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000115 /// \brief The set of local declarations that have been transformed, for
116 /// cases where we are forced to build new declarations within the transformer
117 /// rather than in the subclass (e.g., lambda closure types).
118 llvm::DenseMap<Decl *, Decl *> TransformedLocalDecls;
Chad Rosier1dcde962012-08-08 18:46:20 +0000119
Mike Stump11289f42009-09-09 15:08:12 +0000120public:
Douglas Gregord6ff3322009-08-04 16:50:30 +0000121 /// \brief Initializes a new tree transformer.
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000122 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump11289f42009-09-09 15:08:12 +0000123
Douglas Gregord6ff3322009-08-04 16:50:30 +0000124 /// \brief Retrieves a reference to the derived class.
125 Derived &getDerived() { return static_cast<Derived&>(*this); }
126
127 /// \brief Retrieves a reference to the derived class.
Mike Stump11289f42009-09-09 15:08:12 +0000128 const Derived &getDerived() const {
129 return static_cast<const Derived&>(*this);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000130 }
131
John McCalldadc5752010-08-24 06:29:42 +0000132 static inline ExprResult Owned(Expr *E) { return E; }
133 static inline StmtResult Owned(Stmt *S) { return S; }
John McCallb268a282010-08-23 23:25:46 +0000134
Douglas Gregord6ff3322009-08-04 16:50:30 +0000135 /// \brief Retrieves a reference to the semantic analysis object used for
136 /// this tree transform.
137 Sema &getSema() const { return SemaRef; }
Mike Stump11289f42009-09-09 15:08:12 +0000138
Douglas Gregord6ff3322009-08-04 16:50:30 +0000139 /// \brief Whether the transformation should always rebuild AST nodes, even
140 /// if none of the children have changed.
141 ///
142 /// Subclasses may override this function to specify when the transformation
143 /// should rebuild all AST nodes.
Richard Smith2aa81a72013-11-07 20:07:17 +0000144 ///
145 /// We must always rebuild all AST nodes when performing variadic template
146 /// pack expansion, in order to avoid violating the AST invariant that each
147 /// statement node appears at most once in its containing declaration.
148 bool AlwaysRebuild() { return SemaRef.ArgumentPackSubstitutionIndex != -1; }
Mike Stump11289f42009-09-09 15:08:12 +0000149
Douglas Gregord6ff3322009-08-04 16:50:30 +0000150 /// \brief Returns the location of the entity being transformed, if that
151 /// information was not available elsewhere in the AST.
152 ///
Mike Stump11289f42009-09-09 15:08:12 +0000153 /// By default, returns no source-location information. Subclasses can
Douglas Gregord6ff3322009-08-04 16:50:30 +0000154 /// provide an alternative implementation that provides better location
155 /// information.
156 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump11289f42009-09-09 15:08:12 +0000157
Douglas Gregord6ff3322009-08-04 16:50:30 +0000158 /// \brief Returns the name of the entity being transformed, if that
159 /// information was not available elsewhere in the AST.
160 ///
161 /// By default, returns an empty name. Subclasses can provide an alternative
162 /// implementation with a more precise name.
163 DeclarationName getBaseEntity() { return DeclarationName(); }
164
Douglas Gregora16548e2009-08-11 05:31:07 +0000165 /// \brief Sets the "base" location and entity when that
166 /// information is known based on another transformation.
167 ///
168 /// By default, the source location and entity are ignored. Subclasses can
169 /// override this function to provide a customized implementation.
170 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump11289f42009-09-09 15:08:12 +0000171
Douglas Gregora16548e2009-08-11 05:31:07 +0000172 /// \brief RAII object that temporarily sets the base location and entity
173 /// used for reporting diagnostics in types.
174 class TemporaryBase {
175 TreeTransform &Self;
176 SourceLocation OldLocation;
177 DeclarationName OldEntity;
Mike Stump11289f42009-09-09 15:08:12 +0000178
Douglas Gregora16548e2009-08-11 05:31:07 +0000179 public:
180 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump11289f42009-09-09 15:08:12 +0000181 DeclarationName Entity) : Self(Self) {
Douglas Gregora16548e2009-08-11 05:31:07 +0000182 OldLocation = Self.getDerived().getBaseLocation();
183 OldEntity = Self.getDerived().getBaseEntity();
Chad Rosier1dcde962012-08-08 18:46:20 +0000184
Douglas Gregora518d5b2011-01-25 17:51:48 +0000185 if (Location.isValid())
186 Self.getDerived().setBase(Location, Entity);
Douglas Gregora16548e2009-08-11 05:31:07 +0000187 }
Mike Stump11289f42009-09-09 15:08:12 +0000188
Douglas Gregora16548e2009-08-11 05:31:07 +0000189 ~TemporaryBase() {
190 Self.getDerived().setBase(OldLocation, OldEntity);
191 }
192 };
Mike Stump11289f42009-09-09 15:08:12 +0000193
194 /// \brief Determine whether the given type \p T has already been
Douglas Gregord6ff3322009-08-04 16:50:30 +0000195 /// transformed.
196 ///
197 /// Subclasses can provide an alternative implementation of this routine
Mike Stump11289f42009-09-09 15:08:12 +0000198 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregord6ff3322009-08-04 16:50:30 +0000199 /// not change. For example, template instantiation need not traverse
200 /// non-dependent types.
201 bool AlreadyTransformed(QualType T) {
202 return T.isNull();
203 }
204
Douglas Gregord196a582009-12-14 19:27:10 +0000205 /// \brief Determine whether the given call argument should be dropped, e.g.,
206 /// because it is a default argument.
207 ///
208 /// Subclasses can provide an alternative implementation of this routine to
209 /// determine which kinds of call arguments get dropped. By default,
210 /// CXXDefaultArgument nodes are dropped (prior to transformation).
211 bool DropCallArgument(Expr *E) {
212 return E->isDefaultArgument();
213 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000214
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000215 /// \brief Determine whether we should expand a pack expansion with the
216 /// given set of parameter packs into separate arguments by repeatedly
217 /// transforming the pattern.
218 ///
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000219 /// By default, the transformer never tries to expand pack expansions.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000220 /// Subclasses can override this routine to provide different behavior.
221 ///
222 /// \param EllipsisLoc The location of the ellipsis that identifies the
223 /// pack expansion.
224 ///
225 /// \param PatternRange The source range that covers the entire pattern of
226 /// the pack expansion.
227 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000228 /// \param Unexpanded The set of unexpanded parameter packs within the
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000229 /// pattern.
230 ///
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000231 /// \param ShouldExpand Will be set to \c true if the transformer should
232 /// expand the corresponding pack expansions into separate arguments. When
233 /// set, \c NumExpansions must also be set.
234 ///
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000235 /// \param RetainExpansion Whether the caller should add an unexpanded
236 /// pack expansion after all of the expanded arguments. This is used
237 /// when extending explicitly-specified template argument packs per
238 /// C++0x [temp.arg.explicit]p9.
239 ///
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000240 /// \param NumExpansions The number of separate arguments that will be in
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000241 /// the expanded form of the corresponding pack expansion. This is both an
242 /// input and an output parameter, which can be set by the caller if the
243 /// number of expansions is known a priori (e.g., due to a prior substitution)
244 /// and will be set by the callee when the number of expansions is known.
245 /// The callee must set this value when \c ShouldExpand is \c true; it may
246 /// set this value in other cases.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000247 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000248 /// \returns true if an error occurred (e.g., because the parameter packs
249 /// are to be instantiated with arguments of different lengths), false
250 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000251 /// must be set.
252 bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
253 SourceRange PatternRange,
Dmitri Gribenkof8579502013-01-12 19:30:44 +0000254 ArrayRef<UnexpandedParameterPack> Unexpanded,
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000255 bool &ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000256 bool &RetainExpansion,
David Blaikie05785d12013-02-20 22:23:23 +0000257 Optional<unsigned> &NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000258 ShouldExpand = false;
259 return false;
260 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000261
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000262 /// \brief "Forget" about the partially-substituted pack template argument,
263 /// when performing an instantiation that must preserve the parameter pack
264 /// use.
265 ///
266 /// This routine is meant to be overridden by the template instantiator.
267 TemplateArgument ForgetPartiallySubstitutedPack() {
268 return TemplateArgument();
269 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000270
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000271 /// \brief "Remember" the partially-substituted pack template argument
272 /// after performing an instantiation that must preserve the parameter pack
273 /// use.
274 ///
275 /// This routine is meant to be overridden by the template instantiator.
276 void RememberPartiallySubstitutedPack(TemplateArgument Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000277
Douglas Gregorf3010112011-01-07 16:43:16 +0000278 /// \brief Note to the derived class when a function parameter pack is
279 /// being expanded.
280 void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000281
Douglas Gregord6ff3322009-08-04 16:50:30 +0000282 /// \brief Transforms the given type into another type.
283 ///
John McCall550e0c22009-10-21 00:40:46 +0000284 /// By default, this routine transforms a type by creating a
John McCallbcd03502009-12-07 02:54:59 +0000285 /// TypeSourceInfo for it and delegating to the appropriate
John McCall550e0c22009-10-21 00:40:46 +0000286 /// function. This is expensive, but we don't mind, because
287 /// this method is deprecated anyway; all users should be
John McCallbcd03502009-12-07 02:54:59 +0000288 /// switched to storing TypeSourceInfos.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000289 ///
290 /// \returns the transformed type.
John McCall31f82722010-11-12 08:19:04 +0000291 QualType TransformType(QualType T);
Mike Stump11289f42009-09-09 15:08:12 +0000292
John McCall550e0c22009-10-21 00:40:46 +0000293 /// \brief Transforms the given type-with-location into a new
294 /// type-with-location.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000295 ///
John McCall550e0c22009-10-21 00:40:46 +0000296 /// By default, this routine transforms a type by delegating to the
297 /// appropriate TransformXXXType to build a new type. Subclasses
298 /// may override this function (to take over all type
299 /// transformations) or some set of the TransformXXXType functions
300 /// to alter the transformation.
John McCall31f82722010-11-12 08:19:04 +0000301 TypeSourceInfo *TransformType(TypeSourceInfo *DI);
John McCall550e0c22009-10-21 00:40:46 +0000302
303 /// \brief Transform the given type-with-location into a new
304 /// type, collecting location information in the given builder
305 /// as necessary.
306 ///
John McCall31f82722010-11-12 08:19:04 +0000307 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
Mike Stump11289f42009-09-09 15:08:12 +0000308
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000309 /// \brief Transform the given statement.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000310 ///
Mike Stump11289f42009-09-09 15:08:12 +0000311 /// By default, this routine transforms a statement by delegating to the
Douglas Gregorebe10102009-08-20 07:17:43 +0000312 /// appropriate TransformXXXStmt function to transform a specific kind of
313 /// statement or the TransformExpr() function to transform an expression.
314 /// Subclasses may override this function to transform statements using some
315 /// other mechanism.
316 ///
317 /// \returns the transformed statement.
John McCalldadc5752010-08-24 06:29:42 +0000318 StmtResult TransformStmt(Stmt *S);
Mike Stump11289f42009-09-09 15:08:12 +0000319
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000320 /// \brief Transform the given statement.
321 ///
322 /// By default, this routine transforms a statement by delegating to the
323 /// appropriate TransformOMPXXXClause function to transform a specific kind
324 /// of clause. Subclasses may override this function to transform statements
325 /// using some other mechanism.
326 ///
327 /// \returns the transformed OpenMP clause.
328 OMPClause *TransformOMPClause(OMPClause *S);
329
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000330 /// \brief Transform the given expression.
331 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000332 /// By default, this routine transforms an expression by delegating to the
333 /// appropriate TransformXXXExpr function to build a new expression.
334 /// Subclasses may override this function to transform expressions using some
335 /// other mechanism.
336 ///
337 /// \returns the transformed expression.
John McCalldadc5752010-08-24 06:29:42 +0000338 ExprResult TransformExpr(Expr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000339
Richard Smithd59b8322012-12-19 01:39:02 +0000340 /// \brief Transform the given initializer.
341 ///
342 /// By default, this routine transforms an initializer by stripping off the
343 /// semantic nodes added by initialization, then passing the result to
344 /// TransformExpr or TransformExprs.
345 ///
346 /// \returns the transformed initializer.
347 ExprResult TransformInitializer(Expr *Init, bool CXXDirectInit);
348
Douglas Gregora3efea12011-01-03 19:04:46 +0000349 /// \brief Transform the given list of expressions.
350 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000351 /// This routine transforms a list of expressions by invoking
352 /// \c TransformExpr() for each subexpression. However, it also provides
Douglas Gregora3efea12011-01-03 19:04:46 +0000353 /// support for variadic templates by expanding any pack expansions (if the
354 /// derived class permits such expansion) along the way. When pack expansions
355 /// are present, the number of outputs may not equal the number of inputs.
356 ///
357 /// \param Inputs The set of expressions to be transformed.
358 ///
359 /// \param NumInputs The number of expressions in \c Inputs.
360 ///
361 /// \param IsCall If \c true, then this transform is being performed on
Chad Rosier1dcde962012-08-08 18:46:20 +0000362 /// function-call arguments, and any arguments that should be dropped, will
Douglas Gregora3efea12011-01-03 19:04:46 +0000363 /// be.
364 ///
365 /// \param Outputs The transformed input expressions will be added to this
366 /// vector.
367 ///
368 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
369 /// due to transformation.
370 ///
371 /// \returns true if an error occurred, false otherwise.
372 bool TransformExprs(Expr **Inputs, unsigned NumInputs, bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +0000373 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregora3efea12011-01-03 19:04:46 +0000374 bool *ArgChanged = 0);
Chad Rosier1dcde962012-08-08 18:46:20 +0000375
Douglas Gregord6ff3322009-08-04 16:50:30 +0000376 /// \brief Transform the given declaration, which is referenced from a type
377 /// or expression.
378 ///
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000379 /// By default, acts as the identity function on declarations, unless the
380 /// transformer has had to transform the declaration itself. Subclasses
Douglas Gregor1135c352009-08-06 05:28:30 +0000381 /// may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000382 Decl *TransformDecl(SourceLocation Loc, Decl *D) {
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000383 llvm::DenseMap<Decl *, Decl *>::iterator Known
384 = TransformedLocalDecls.find(D);
385 if (Known != TransformedLocalDecls.end())
386 return Known->second;
Chad Rosier1dcde962012-08-08 18:46:20 +0000387
388 return D;
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000389 }
Douglas Gregorebe10102009-08-20 07:17:43 +0000390
Chad Rosier1dcde962012-08-08 18:46:20 +0000391 /// \brief Transform the attributes associated with the given declaration and
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000392 /// place them on the new declaration.
393 ///
394 /// By default, this operation does nothing. Subclasses may override this
395 /// behavior to transform attributes.
396 void transformAttrs(Decl *Old, Decl *New) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000397
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000398 /// \brief Note that a local declaration has been transformed by this
399 /// transformer.
400 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000401 /// Local declarations are typically transformed via a call to
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000402 /// TransformDefinition. However, in some cases (e.g., lambda expressions),
403 /// the transformer itself has to transform the declarations. This routine
404 /// can be overridden by a subclass that keeps track of such mappings.
405 void transformedLocalDecl(Decl *Old, Decl *New) {
406 TransformedLocalDecls[Old] = New;
407 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000408
Douglas Gregorebe10102009-08-20 07:17:43 +0000409 /// \brief Transform the definition of the given declaration.
410 ///
Mike Stump11289f42009-09-09 15:08:12 +0000411 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregorebe10102009-08-20 07:17:43 +0000412 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000413 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
414 return getDerived().TransformDecl(Loc, D);
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000415 }
Mike Stump11289f42009-09-09 15:08:12 +0000416
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000417 /// \brief Transform the given declaration, which was the first part of a
418 /// nested-name-specifier in a member access expression.
419 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000420 /// This specific declaration transformation only applies to the first
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000421 /// identifier in a nested-name-specifier of a member access expression, e.g.,
422 /// the \c T in \c x->T::member
423 ///
424 /// By default, invokes TransformDecl() to transform the declaration.
425 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000426 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
427 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000428 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000429
Douglas Gregor14454802011-02-25 02:25:35 +0000430 /// \brief Transform the given nested-name-specifier with source-location
431 /// information.
432 ///
433 /// By default, transforms all of the types and declarations within the
434 /// nested-name-specifier. Subclasses may override this function to provide
435 /// alternate behavior.
436 NestedNameSpecifierLoc TransformNestedNameSpecifierLoc(
437 NestedNameSpecifierLoc NNS,
438 QualType ObjectType = QualType(),
439 NamedDecl *FirstQualifierInScope = 0);
440
Douglas Gregorf816bd72009-09-03 22:13:48 +0000441 /// \brief Transform the given declaration name.
442 ///
443 /// By default, transforms the types of conversion function, constructor,
444 /// and destructor names and then (if needed) rebuilds the declaration name.
445 /// Identifiers and selectors are returned unmodified. Sublcasses may
446 /// override this function to provide alternate behavior.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000447 DeclarationNameInfo
John McCall31f82722010-11-12 08:19:04 +0000448 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump11289f42009-09-09 15:08:12 +0000449
Douglas Gregord6ff3322009-08-04 16:50:30 +0000450 /// \brief Transform the given template name.
Mike Stump11289f42009-09-09 15:08:12 +0000451 ///
Douglas Gregor9db53502011-03-02 18:07:45 +0000452 /// \param SS The nested-name-specifier that qualifies the template
453 /// name. This nested-name-specifier must already have been transformed.
454 ///
455 /// \param Name The template name to transform.
456 ///
457 /// \param NameLoc The source location of the template name.
458 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000459 /// \param ObjectType If we're translating a template name within a member
Douglas Gregor9db53502011-03-02 18:07:45 +0000460 /// access expression, this is the type of the object whose member template
461 /// is being referenced.
462 ///
463 /// \param FirstQualifierInScope If the first part of a nested-name-specifier
464 /// also refers to a name within the current (lexical) scope, this is the
465 /// declaration it refers to.
466 ///
467 /// By default, transforms the template name by transforming the declarations
468 /// and nested-name-specifiers that occur within the template name.
469 /// Subclasses may override this function to provide alternate behavior.
470 TemplateName TransformTemplateName(CXXScopeSpec &SS,
471 TemplateName Name,
Abramo Bagnara7945c982012-01-27 09:46:47 +0000472 SourceLocation NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +0000473 QualType ObjectType = QualType(),
474 NamedDecl *FirstQualifierInScope = 0);
475
Douglas Gregord6ff3322009-08-04 16:50:30 +0000476 /// \brief Transform the given template argument.
477 ///
Mike Stump11289f42009-09-09 15:08:12 +0000478 /// By default, this operation transforms the type, expression, or
479 /// declaration stored within the template argument and constructs a
Douglas Gregore922c772009-08-04 22:27:00 +0000480 /// new template argument from the transformed result. Subclasses may
481 /// override this function to provide alternate behavior.
John McCall0ad16662009-10-29 08:12:44 +0000482 ///
483 /// Returns true if there was an error.
484 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
485 TemplateArgumentLoc &Output);
486
Douglas Gregor62e06f22010-12-20 17:31:10 +0000487 /// \brief Transform the given set of template arguments.
488 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000489 /// By default, this operation transforms all of the template arguments
Douglas Gregor62e06f22010-12-20 17:31:10 +0000490 /// in the input set using \c TransformTemplateArgument(), and appends
491 /// the transformed arguments to the output list.
492 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000493 /// Note that this overload of \c TransformTemplateArguments() is merely
494 /// a convenience function. Subclasses that wish to override this behavior
495 /// should override the iterator-based member template version.
496 ///
Douglas Gregor62e06f22010-12-20 17:31:10 +0000497 /// \param Inputs The set of template arguments to be transformed.
498 ///
499 /// \param NumInputs The number of template arguments in \p Inputs.
500 ///
501 /// \param Outputs The set of transformed template arguments output by this
502 /// routine.
503 ///
504 /// Returns true if an error occurred.
505 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
506 unsigned NumInputs,
Douglas Gregorfe921a72010-12-20 23:36:19 +0000507 TemplateArgumentListInfo &Outputs) {
508 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs);
509 }
Douglas Gregor42cafa82010-12-20 17:42:22 +0000510
511 /// \brief Transform the given set of template arguments.
512 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000513 /// By default, this operation transforms all of the template arguments
Douglas Gregor42cafa82010-12-20 17:42:22 +0000514 /// in the input set using \c TransformTemplateArgument(), and appends
Chad Rosier1dcde962012-08-08 18:46:20 +0000515 /// the transformed arguments to the output list.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000516 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000517 /// \param First An iterator to the first template argument.
518 ///
519 /// \param Last An iterator one step past the last template argument.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000520 ///
521 /// \param Outputs The set of transformed template arguments output by this
522 /// routine.
523 ///
524 /// Returns true if an error occurred.
Douglas Gregorfe921a72010-12-20 23:36:19 +0000525 template<typename InputIterator>
526 bool TransformTemplateArguments(InputIterator First,
527 InputIterator Last,
528 TemplateArgumentListInfo &Outputs);
Douglas Gregor42cafa82010-12-20 17:42:22 +0000529
John McCall0ad16662009-10-29 08:12:44 +0000530 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
531 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
532 TemplateArgumentLoc &ArgLoc);
533
John McCallbcd03502009-12-07 02:54:59 +0000534 /// \brief Fakes up a TypeSourceInfo for a type.
535 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
536 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall0ad16662009-10-29 08:12:44 +0000537 getDerived().getBaseLocation());
538 }
Mike Stump11289f42009-09-09 15:08:12 +0000539
John McCall550e0c22009-10-21 00:40:46 +0000540#define ABSTRACT_TYPELOC(CLASS, PARENT)
541#define TYPELOC(CLASS, PARENT) \
John McCall31f82722010-11-12 08:19:04 +0000542 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCall550e0c22009-10-21 00:40:46 +0000543#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +0000544
Douglas Gregor3024f072012-04-16 07:05:22 +0000545 QualType TransformFunctionProtoType(TypeLocBuilder &TLB,
546 FunctionProtoTypeLoc TL,
547 CXXRecordDecl *ThisContext,
548 unsigned ThisTypeQuals);
549
David Majnemerfad8f482013-10-15 09:33:02 +0000550 StmtResult TransformSEHHandler(Stmt *Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +0000551
Chad Rosier1dcde962012-08-08 18:46:20 +0000552 QualType
John McCall31f82722010-11-12 08:19:04 +0000553 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
554 TemplateSpecializationTypeLoc TL,
555 TemplateName Template);
556
Chad Rosier1dcde962012-08-08 18:46:20 +0000557 QualType
John McCall31f82722010-11-12 08:19:04 +0000558 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
559 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +0000560 TemplateName Template,
561 CXXScopeSpec &SS);
Douglas Gregor5a064722011-02-28 17:23:35 +0000562
Chad Rosier1dcde962012-08-08 18:46:20 +0000563 QualType
Douglas Gregor5a064722011-02-28 17:23:35 +0000564 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
Douglas Gregora7a795b2011-03-01 20:11:18 +0000565 DependentTemplateSpecializationTypeLoc TL,
566 NestedNameSpecifierLoc QualifierLoc);
567
John McCall58f10c32010-03-11 09:03:00 +0000568 /// \brief Transforms the parameters of a function type into the
569 /// given vectors.
570 ///
571 /// The result vectors should be kept in sync; null entries in the
572 /// variables vector are acceptable.
573 ///
574 /// Return true on error.
Douglas Gregordd472162011-01-07 00:20:55 +0000575 bool TransformFunctionTypeParams(SourceLocation Loc,
576 ParmVarDecl **Params, unsigned NumParams,
577 const QualType *ParamTypes,
Chris Lattner01cf8db2011-07-20 06:58:45 +0000578 SmallVectorImpl<QualType> &PTypes,
579 SmallVectorImpl<ParmVarDecl*> *PVars);
John McCall58f10c32010-03-11 09:03:00 +0000580
581 /// \brief Transforms a single function-type parameter. Return null
582 /// on error.
John McCall8fb0d9d2011-05-01 22:35:37 +0000583 ///
584 /// \param indexAdjustment - A number to add to the parameter's
585 /// scope index; can be negative
Douglas Gregor715e4612011-01-14 22:40:04 +0000586 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +0000587 int indexAdjustment,
David Blaikie05785d12013-02-20 22:23:23 +0000588 Optional<unsigned> NumExpansions,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +0000589 bool ExpectParameterPack);
John McCall58f10c32010-03-11 09:03:00 +0000590
John McCall31f82722010-11-12 08:19:04 +0000591 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall0ad16662009-10-29 08:12:44 +0000592
John McCalldadc5752010-08-24 06:29:42 +0000593 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
594 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +0000595
596 typedef std::pair<ExprResult, QualType> InitCaptureInfoTy;
Richard Smith2589b9802012-07-25 03:56:55 +0000597 /// \brief Transform the captures and body of a lambda expression.
Faisal Vali5fb7c3c2013-12-05 01:40:41 +0000598 ExprResult TransformLambdaScope(LambdaExpr *E, CXXMethodDecl *CallOperator,
599 ArrayRef<InitCaptureInfoTy> InitCaptureExprsAndTypes);
Richard Smith2589b9802012-07-25 03:56:55 +0000600
Faisal Vali2cba1332013-10-23 06:44:28 +0000601 TemplateParameterList *TransformTemplateParameterList(
602 TemplateParameterList *TPL) {
603 return TPL;
604 }
605
Richard Smithdb2630f2012-10-21 03:28:35 +0000606 ExprResult TransformAddressOfOperand(Expr *E);
607 ExprResult TransformDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E,
608 bool IsAddressOfOperand);
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000609 StmtResult TransformOMPExecutableDirective(OMPExecutableDirective *S);
Richard Smithdb2630f2012-10-21 03:28:35 +0000610
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000611// FIXME: We use LLVM_ATTRIBUTE_NOINLINE because inlining causes a ridiculous
612// amount of stack usage with clang.
Douglas Gregorebe10102009-08-20 07:17:43 +0000613#define STMT(Node, Parent) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000614 LLVM_ATTRIBUTE_NOINLINE \
John McCalldadc5752010-08-24 06:29:42 +0000615 StmtResult Transform##Node(Node *S);
Douglas Gregora16548e2009-08-11 05:31:07 +0000616#define EXPR(Node, Parent) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000617 LLVM_ATTRIBUTE_NOINLINE \
John McCalldadc5752010-08-24 06:29:42 +0000618 ExprResult Transform##Node(Node *E);
Alexis Huntabb2ac82010-05-18 06:22:21 +0000619#define ABSTRACT_STMT(Stmt)
Alexis Hunt656bb312010-05-05 15:24:00 +0000620#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +0000621
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000622#define OPENMP_CLAUSE(Name, Class) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000623 LLVM_ATTRIBUTE_NOINLINE \
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000624 OMPClause *Transform ## Class(Class *S);
625#include "clang/Basic/OpenMPKinds.def"
626
Douglas Gregord6ff3322009-08-04 16:50:30 +0000627 /// \brief Build a new pointer type given its pointee type.
628 ///
629 /// By default, performs semantic analysis when building the pointer type.
630 /// Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000631 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000632
633 /// \brief Build a new block pointer type given its pointee type.
634 ///
Mike Stump11289f42009-09-09 15:08:12 +0000635 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000636 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000637 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000638
John McCall70dd5f62009-10-30 00:06:24 +0000639 /// \brief Build a new reference type given the type it references.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000640 ///
John McCall70dd5f62009-10-30 00:06:24 +0000641 /// By default, performs semantic analysis when building the
642 /// reference type. Subclasses may override this routine to provide
643 /// different behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000644 ///
John McCall70dd5f62009-10-30 00:06:24 +0000645 /// \param LValue whether the type was written with an lvalue sigil
646 /// or an rvalue sigil.
647 QualType RebuildReferenceType(QualType ReferentType,
648 bool LValue,
649 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000650
Douglas Gregord6ff3322009-08-04 16:50:30 +0000651 /// \brief Build a new member pointer type given the pointee type and the
652 /// class type it refers into.
653 ///
654 /// By default, performs semantic analysis when building the member pointer
655 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000656 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
657 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000658
Douglas Gregord6ff3322009-08-04 16:50:30 +0000659 /// \brief Build a new array type given the element type, size
660 /// modifier, size of the array (if known), size expression, and index type
661 /// qualifiers.
662 ///
663 /// By default, performs semantic analysis when building the array type.
664 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000665 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-08-04 16:50:30 +0000666 QualType RebuildArrayType(QualType ElementType,
667 ArrayType::ArraySizeModifier SizeMod,
668 const llvm::APInt *Size,
669 Expr *SizeExpr,
670 unsigned IndexTypeQuals,
671 SourceRange BracketsRange);
Mike Stump11289f42009-09-09 15:08:12 +0000672
Douglas Gregord6ff3322009-08-04 16:50:30 +0000673 /// \brief Build a new constant array type given the element type, size
674 /// modifier, (known) size of the array, and index type qualifiers.
675 ///
676 /// By default, performs semantic analysis when building the array type.
677 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000678 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000679 ArrayType::ArraySizeModifier SizeMod,
680 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +0000681 unsigned IndexTypeQuals,
682 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000683
Douglas Gregord6ff3322009-08-04 16:50:30 +0000684 /// \brief Build a new incomplete array type given the element type, size
685 /// modifier, and index type qualifiers.
686 ///
687 /// By default, performs semantic analysis when building the array type.
688 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000689 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000690 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +0000691 unsigned IndexTypeQuals,
692 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000693
Mike Stump11289f42009-09-09 15:08:12 +0000694 /// \brief Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000695 /// size modifier, size expression, and index type qualifiers.
696 ///
697 /// By default, performs semantic analysis when building the array type.
698 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000699 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000700 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000701 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000702 unsigned IndexTypeQuals,
703 SourceRange BracketsRange);
704
Mike Stump11289f42009-09-09 15:08:12 +0000705 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000706 /// size modifier, size expression, and index type qualifiers.
707 ///
708 /// By default, performs semantic analysis when building the array type.
709 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000710 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000711 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000712 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000713 unsigned IndexTypeQuals,
714 SourceRange BracketsRange);
715
716 /// \brief Build a new vector type given the element type and
717 /// number of elements.
718 ///
719 /// By default, performs semantic analysis when building the vector type.
720 /// Subclasses may override this routine to provide different behavior.
John Thompson22334602010-02-05 00:12:22 +0000721 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsonaeb56442010-11-10 21:56:12 +0000722 VectorType::VectorKind VecKind);
Mike Stump11289f42009-09-09 15:08:12 +0000723
Douglas Gregord6ff3322009-08-04 16:50:30 +0000724 /// \brief Build a new extended vector type given the element type and
725 /// number of elements.
726 ///
727 /// By default, performs semantic analysis when building the vector type.
728 /// Subclasses may override this routine to provide different behavior.
729 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
730 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000731
732 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000733 /// given the element type and number of elements.
734 ///
735 /// By default, performs semantic analysis when building the vector type.
736 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000737 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +0000738 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000739 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000740
Douglas Gregord6ff3322009-08-04 16:50:30 +0000741 /// \brief Build a new function type.
742 ///
743 /// By default, performs semantic analysis when building the function type.
744 /// Subclasses may override this routine to provide different behavior.
745 QualType RebuildFunctionProtoType(QualType T,
Jordan Rose5c382722013-03-08 21:51:21 +0000746 llvm::MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +0000747 const FunctionProtoType::ExtProtoInfo &EPI);
Mike Stump11289f42009-09-09 15:08:12 +0000748
John McCall550e0c22009-10-21 00:40:46 +0000749 /// \brief Build a new unprototyped function type.
750 QualType RebuildFunctionNoProtoType(QualType ResultType);
751
John McCallb96ec562009-12-04 22:46:56 +0000752 /// \brief Rebuild an unresolved typename type, given the decl that
753 /// the UnresolvedUsingTypenameDecl was transformed to.
754 QualType RebuildUnresolvedUsingType(Decl *D);
755
Douglas Gregord6ff3322009-08-04 16:50:30 +0000756 /// \brief Build a new typedef type.
Richard Smithdda56e42011-04-15 14:24:37 +0000757 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
Douglas Gregord6ff3322009-08-04 16:50:30 +0000758 return SemaRef.Context.getTypeDeclType(Typedef);
759 }
760
761 /// \brief Build a new class/struct/union type.
762 QualType RebuildRecordType(RecordDecl *Record) {
763 return SemaRef.Context.getTypeDeclType(Record);
764 }
765
766 /// \brief Build a new Enum type.
767 QualType RebuildEnumType(EnumDecl *Enum) {
768 return SemaRef.Context.getTypeDeclType(Enum);
769 }
John McCallfcc33b02009-09-05 00:15:47 +0000770
Mike Stump11289f42009-09-09 15:08:12 +0000771 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000772 ///
773 /// By default, performs semantic analysis when building the typeof type.
774 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000775 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000776
Mike Stump11289f42009-09-09 15:08:12 +0000777 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000778 ///
779 /// By default, builds a new TypeOfType with the given underlying type.
780 QualType RebuildTypeOfType(QualType Underlying);
781
Alexis Hunte852b102011-05-24 22:41:36 +0000782 /// \brief Build a new unary transform type.
783 QualType RebuildUnaryTransformType(QualType BaseType,
784 UnaryTransformType::UTTKind UKind,
785 SourceLocation Loc);
786
Richard Smith74aeef52013-04-26 16:15:35 +0000787 /// \brief Build a new C++11 decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000788 ///
789 /// By default, performs semantic analysis when building the decltype type.
790 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000791 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump11289f42009-09-09 15:08:12 +0000792
Richard Smith74aeef52013-04-26 16:15:35 +0000793 /// \brief Build a new C++11 auto type.
Richard Smith30482bc2011-02-20 03:19:35 +0000794 ///
795 /// By default, builds a new AutoType with the given deduced type.
Richard Smith74aeef52013-04-26 16:15:35 +0000796 QualType RebuildAutoType(QualType Deduced, bool IsDecltypeAuto) {
Richard Smith27d807c2013-04-30 13:56:41 +0000797 // Note, IsDependent is always false here: we implicitly convert an 'auto'
798 // which has been deduced to a dependent type into an undeduced 'auto', so
799 // that we'll retry deduction after the transformation.
Faisal Vali2b391ab2013-09-26 19:54:12 +0000800 return SemaRef.Context.getAutoType(Deduced, IsDecltypeAuto,
801 /*IsDependent*/ false);
Richard Smith30482bc2011-02-20 03:19:35 +0000802 }
803
Douglas Gregord6ff3322009-08-04 16:50:30 +0000804 /// \brief Build a new template specialization type.
805 ///
806 /// By default, performs semantic analysis when building the template
807 /// specialization type. Subclasses may override this routine to provide
808 /// different behavior.
809 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000810 SourceLocation TemplateLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000811 TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000812
Abramo Bagnara924a8f32010-12-10 16:29:40 +0000813 /// \brief Build a new parenthesized type.
814 ///
815 /// By default, builds a new ParenType type from the inner type.
816 /// Subclasses may override this routine to provide different behavior.
817 QualType RebuildParenType(QualType InnerType) {
818 return SemaRef.Context.getParenType(InnerType);
819 }
820
Douglas Gregord6ff3322009-08-04 16:50:30 +0000821 /// \brief Build a new qualified name type.
822 ///
Abramo Bagnara6150c882010-05-11 21:36:43 +0000823 /// By default, builds a new ElaboratedType type from the keyword,
824 /// the nested-name-specifier and the named type.
825 /// Subclasses may override this routine to provide different behavior.
John McCall954b5de2010-11-04 19:04:38 +0000826 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
827 ElaboratedTypeKeyword Keyword,
Douglas Gregor844cb502011-03-01 18:12:44 +0000828 NestedNameSpecifierLoc QualifierLoc,
829 QualType Named) {
Chad Rosier1dcde962012-08-08 18:46:20 +0000830 return SemaRef.Context.getElaboratedType(Keyword,
831 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor844cb502011-03-01 18:12:44 +0000832 Named);
Mike Stump11289f42009-09-09 15:08:12 +0000833 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000834
835 /// \brief Build a new typename type that refers to a template-id.
836 ///
Abramo Bagnarad7548482010-05-19 21:37:53 +0000837 /// By default, builds a new DependentNameType type from the
838 /// nested-name-specifier and the given type. Subclasses may override
839 /// this routine to provide different behavior.
John McCallc392f372010-06-11 00:33:02 +0000840 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregora7a795b2011-03-01 20:11:18 +0000841 ElaboratedTypeKeyword Keyword,
842 NestedNameSpecifierLoc QualifierLoc,
843 const IdentifierInfo *Name,
844 SourceLocation NameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000845 TemplateArgumentListInfo &Args) {
Douglas Gregora7a795b2011-03-01 20:11:18 +0000846 // Rebuild the template name.
847 // TODO: avoid TemplateName abstraction
Douglas Gregor9db53502011-03-02 18:07:45 +0000848 CXXScopeSpec SS;
849 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +0000850 TemplateName InstName
Douglas Gregor9db53502011-03-02 18:07:45 +0000851 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(), 0);
Chad Rosier1dcde962012-08-08 18:46:20 +0000852
Douglas Gregora7a795b2011-03-01 20:11:18 +0000853 if (InstName.isNull())
854 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +0000855
Douglas Gregora7a795b2011-03-01 20:11:18 +0000856 // If it's still dependent, make a dependent specialization.
857 if (InstName.getAsDependentTemplateName())
Chad Rosier1dcde962012-08-08 18:46:20 +0000858 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
859 QualifierLoc.getNestedNameSpecifier(),
860 Name,
Douglas Gregora7a795b2011-03-01 20:11:18 +0000861 Args);
Chad Rosier1dcde962012-08-08 18:46:20 +0000862
Douglas Gregora7a795b2011-03-01 20:11:18 +0000863 // Otherwise, make an elaborated type wrapping a non-dependent
864 // specialization.
865 QualType T =
866 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
867 if (T.isNull()) return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +0000868
Douglas Gregora7a795b2011-03-01 20:11:18 +0000869 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == 0)
870 return T;
Chad Rosier1dcde962012-08-08 18:46:20 +0000871
872 return SemaRef.Context.getElaboratedType(Keyword,
873 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregora7a795b2011-03-01 20:11:18 +0000874 T);
875 }
876
Douglas Gregord6ff3322009-08-04 16:50:30 +0000877 /// \brief Build a new typename type that refers to an identifier.
878 ///
879 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarad7548482010-05-19 21:37:53 +0000880 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000881 /// different behavior.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000882 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000883 SourceLocation KeywordLoc,
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000884 NestedNameSpecifierLoc QualifierLoc,
885 const IdentifierInfo *Id,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000886 SourceLocation IdLoc) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000887 CXXScopeSpec SS;
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000888 SS.Adopt(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +0000889
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000890 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000891 // If the name is still dependent, just build a new dependent name type.
892 if (!SemaRef.computeDeclContext(SS))
Chad Rosier1dcde962012-08-08 18:46:20 +0000893 return SemaRef.Context.getDependentNameType(Keyword,
894 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000895 Id);
Douglas Gregore677daf2010-03-31 22:19:08 +0000896 }
897
Abramo Bagnara6150c882010-05-11 21:36:43 +0000898 if (Keyword == ETK_None || Keyword == ETK_Typename)
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000899 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
Douglas Gregor9cbc22b2011-02-28 22:42:13 +0000900 *Id, IdLoc);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000901
902 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
903
Abramo Bagnarad7548482010-05-19 21:37:53 +0000904 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregore677daf2010-03-31 22:19:08 +0000905 // into a non-dependent elaborated-type-specifier. Find the tag we're
906 // referring to.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000907 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregore677daf2010-03-31 22:19:08 +0000908 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
909 if (!DC)
910 return QualType();
911
John McCallbf8c5192010-05-27 06:40:31 +0000912 if (SemaRef.RequireCompleteDeclContext(SS, DC))
913 return QualType();
914
Douglas Gregore677daf2010-03-31 22:19:08 +0000915 TagDecl *Tag = 0;
916 SemaRef.LookupQualifiedName(Result, DC);
917 switch (Result.getResultKind()) {
918 case LookupResult::NotFound:
919 case LookupResult::NotFoundInCurrentInstantiation:
920 break;
Chad Rosier1dcde962012-08-08 18:46:20 +0000921
Douglas Gregore677daf2010-03-31 22:19:08 +0000922 case LookupResult::Found:
923 Tag = Result.getAsSingle<TagDecl>();
924 break;
Chad Rosier1dcde962012-08-08 18:46:20 +0000925
Douglas Gregore677daf2010-03-31 22:19:08 +0000926 case LookupResult::FoundOverloaded:
927 case LookupResult::FoundUnresolvedValue:
928 llvm_unreachable("Tag lookup cannot find non-tags");
Chad Rosier1dcde962012-08-08 18:46:20 +0000929
Douglas Gregore677daf2010-03-31 22:19:08 +0000930 case LookupResult::Ambiguous:
931 // Let the LookupResult structure handle ambiguities.
932 return QualType();
933 }
934
935 if (!Tag) {
Nick Lewycky0c438082011-01-24 19:01:04 +0000936 // Check where the name exists but isn't a tag type and use that to emit
937 // better diagnostics.
938 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
939 SemaRef.LookupQualifiedName(Result, DC);
940 switch (Result.getResultKind()) {
941 case LookupResult::Found:
942 case LookupResult::FoundOverloaded:
943 case LookupResult::FoundUnresolvedValue: {
Richard Smith3f1b5d02011-05-05 21:57:07 +0000944 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
Nick Lewycky0c438082011-01-24 19:01:04 +0000945 unsigned Kind = 0;
946 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
Richard Smithdda56e42011-04-15 14:24:37 +0000947 else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2;
948 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3;
Nick Lewycky0c438082011-01-24 19:01:04 +0000949 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
950 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
951 break;
Richard Smith3f1b5d02011-05-05 21:57:07 +0000952 }
Nick Lewycky0c438082011-01-24 19:01:04 +0000953 default:
Nick Lewycky0c438082011-01-24 19:01:04 +0000954 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
Stephan Tolksdorfeb7708d2014-03-13 20:34:03 +0000955 << Kind << Id << DC << QualifierLoc.getSourceRange();
Nick Lewycky0c438082011-01-24 19:01:04 +0000956 break;
957 }
Douglas Gregore677daf2010-03-31 22:19:08 +0000958 return QualType();
959 }
Abramo Bagnara6150c882010-05-11 21:36:43 +0000960
Richard Trieucaa33d32011-06-10 03:11:26 +0000961 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
962 IdLoc, *Id)) {
Abramo Bagnarad7548482010-05-19 21:37:53 +0000963 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregore677daf2010-03-31 22:19:08 +0000964 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
965 return QualType();
966 }
967
968 // Build the elaborated-type-specifier type.
969 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Chad Rosier1dcde962012-08-08 18:46:20 +0000970 return SemaRef.Context.getElaboratedType(Keyword,
971 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000972 T);
Douglas Gregor1135c352009-08-06 05:28:30 +0000973 }
Mike Stump11289f42009-09-09 15:08:12 +0000974
Douglas Gregor822d0302011-01-12 17:07:58 +0000975 /// \brief Build a new pack expansion type.
976 ///
977 /// By default, builds a new PackExpansionType type from the given pattern.
978 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000979 QualType RebuildPackExpansionType(QualType Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +0000980 SourceRange PatternRange,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000981 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +0000982 Optional<unsigned> NumExpansions) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000983 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
984 NumExpansions);
Douglas Gregor822d0302011-01-12 17:07:58 +0000985 }
986
Eli Friedman0dfb8892011-10-06 23:00:33 +0000987 /// \brief Build a new atomic type given its value type.
988 ///
989 /// By default, performs semantic analysis when building the atomic type.
990 /// Subclasses may override this routine to provide different behavior.
991 QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
992
Douglas Gregor71dc5092009-08-06 06:41:21 +0000993 /// \brief Build a new template name given a nested name specifier, a flag
994 /// indicating whether the "template" keyword was provided, and the template
995 /// that the template name refers to.
996 ///
997 /// By default, builds the new template name directly. Subclasses may override
998 /// this routine to provide different behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +0000999 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +00001000 bool TemplateKW,
1001 TemplateDecl *Template);
1002
Douglas Gregor71dc5092009-08-06 06:41:21 +00001003 /// \brief Build a new template name given a nested name specifier and the
1004 /// name that is referred to as a template.
1005 ///
1006 /// By default, performs semantic analysis to determine whether the name can
1007 /// be resolved to a specific template, then builds the appropriate kind of
1008 /// template name. Subclasses may override this routine to provide different
1009 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001010 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
1011 const IdentifierInfo &Name,
1012 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +00001013 QualType ObjectType,
1014 NamedDecl *FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00001015
Douglas Gregor71395fa2009-11-04 00:56:37 +00001016 /// \brief Build a new template name given a nested name specifier and the
1017 /// overloaded operator name that is referred to as a template.
1018 ///
1019 /// By default, performs semantic analysis to determine whether the name can
1020 /// be resolved to a specific template, then builds the appropriate kind of
1021 /// template name. Subclasses may override this routine to provide different
1022 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001023 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +00001024 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +00001025 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +00001026 QualType ObjectType);
Douglas Gregor5590be02011-01-15 06:45:20 +00001027
1028 /// \brief Build a new template name given a template template parameter pack
Chad Rosier1dcde962012-08-08 18:46:20 +00001029 /// and the
Douglas Gregor5590be02011-01-15 06:45:20 +00001030 ///
1031 /// By default, performs semantic analysis to determine whether the name can
1032 /// be resolved to a specific template, then builds the appropriate kind of
1033 /// template name. Subclasses may override this routine to provide different
1034 /// behavior.
1035 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
1036 const TemplateArgument &ArgPack) {
1037 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
1038 }
1039
Douglas Gregorebe10102009-08-20 07:17:43 +00001040 /// \brief Build a new compound statement.
1041 ///
1042 /// By default, performs semantic analysis to build the new statement.
1043 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001044 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001045 MultiStmtArg Statements,
1046 SourceLocation RBraceLoc,
1047 bool IsStmtExpr) {
John McCallb268a282010-08-23 23:25:46 +00001048 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00001049 IsStmtExpr);
1050 }
1051
1052 /// \brief Build a new case statement.
1053 ///
1054 /// By default, performs semantic analysis to build the new statement.
1055 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001056 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCallb268a282010-08-23 23:25:46 +00001057 Expr *LHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001058 SourceLocation EllipsisLoc,
John McCallb268a282010-08-23 23:25:46 +00001059 Expr *RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001060 SourceLocation ColonLoc) {
John McCallb268a282010-08-23 23:25:46 +00001061 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001062 ColonLoc);
1063 }
Mike Stump11289f42009-09-09 15:08:12 +00001064
Douglas Gregorebe10102009-08-20 07:17:43 +00001065 /// \brief Attach the body to a new case statement.
1066 ///
1067 /// By default, performs semantic analysis to build the new statement.
1068 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001069 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001070 getSema().ActOnCaseStmtBody(S, Body);
1071 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00001072 }
Mike Stump11289f42009-09-09 15:08:12 +00001073
Douglas Gregorebe10102009-08-20 07:17:43 +00001074 /// \brief Build a new default statement.
1075 ///
1076 /// By default, performs semantic analysis to build the new statement.
1077 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001078 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001079 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +00001080 Stmt *SubStmt) {
1081 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregorebe10102009-08-20 07:17:43 +00001082 /*CurScope=*/0);
1083 }
Mike Stump11289f42009-09-09 15:08:12 +00001084
Douglas Gregorebe10102009-08-20 07:17:43 +00001085 /// \brief Build a new label statement.
1086 ///
1087 /// By default, performs semantic analysis to build the new statement.
1088 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001089 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1090 SourceLocation ColonLoc, Stmt *SubStmt) {
1091 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregorebe10102009-08-20 07:17:43 +00001092 }
Mike Stump11289f42009-09-09 15:08:12 +00001093
Richard Smithc202b282012-04-14 00:33:13 +00001094 /// \brief Build a new label statement.
1095 ///
1096 /// By default, performs semantic analysis to build the new statement.
1097 /// Subclasses may override this routine to provide different behavior.
Alexander Kornienko20f6fc62012-07-09 10:04:07 +00001098 StmtResult RebuildAttributedStmt(SourceLocation AttrLoc,
1099 ArrayRef<const Attr*> Attrs,
Richard Smithc202b282012-04-14 00:33:13 +00001100 Stmt *SubStmt) {
1101 return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt);
1102 }
1103
Douglas Gregorebe10102009-08-20 07:17:43 +00001104 /// \brief Build a new "if" statement.
1105 ///
1106 /// By default, performs semantic analysis to build the new statement.
1107 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001108 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Chad Rosier1dcde962012-08-08 18:46:20 +00001109 VarDecl *CondVar, Stmt *Then,
Chris Lattnercab02a62011-02-17 20:34:02 +00001110 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00001111 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregorebe10102009-08-20 07:17:43 +00001112 }
Mike Stump11289f42009-09-09 15:08:12 +00001113
Douglas Gregorebe10102009-08-20 07:17:43 +00001114 /// \brief Start building a new switch statement.
1115 ///
1116 /// By default, performs semantic analysis to build the new statement.
1117 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001118 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001119 Expr *Cond, VarDecl *CondVar) {
Chad Rosier1dcde962012-08-08 18:46:20 +00001120 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCall48871652010-08-21 09:40:31 +00001121 CondVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00001122 }
Mike Stump11289f42009-09-09 15:08:12 +00001123
Douglas Gregorebe10102009-08-20 07:17:43 +00001124 /// \brief Attach the body to the switch statement.
1125 ///
1126 /// By default, performs semantic analysis to build the new statement.
1127 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001128 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001129 Stmt *Switch, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001130 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001131 }
1132
1133 /// \brief Build a new while statement.
1134 ///
1135 /// By default, performs semantic analysis to build the new statement.
1136 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001137 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1138 VarDecl *CondVar, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001139 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001140 }
Mike Stump11289f42009-09-09 15:08:12 +00001141
Douglas Gregorebe10102009-08-20 07:17:43 +00001142 /// \brief Build a new do-while statement.
1143 ///
1144 /// By default, performs semantic analysis to build the new statement.
1145 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001146 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001147 SourceLocation WhileLoc, SourceLocation LParenLoc,
1148 Expr *Cond, SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001149 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1150 Cond, RParenLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001151 }
1152
1153 /// \brief Build a new for statement.
1154 ///
1155 /// By default, performs semantic analysis to build the new statement.
1156 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001157 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
Chad Rosier1dcde962012-08-08 18:46:20 +00001158 Stmt *Init, Sema::FullExprArg Cond,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001159 VarDecl *CondVar, Sema::FullExprArg Inc,
1160 SourceLocation RParenLoc, Stmt *Body) {
Chad Rosier1dcde962012-08-08 18:46:20 +00001161 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001162 CondVar, Inc, RParenLoc, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001163 }
Mike Stump11289f42009-09-09 15:08:12 +00001164
Douglas Gregorebe10102009-08-20 07:17:43 +00001165 /// \brief Build a new goto statement.
1166 ///
1167 /// By default, performs semantic analysis to build the new statement.
1168 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001169 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1170 LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001171 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregorebe10102009-08-20 07:17:43 +00001172 }
1173
1174 /// \brief Build a new indirect goto statement.
1175 ///
1176 /// By default, performs semantic analysis to build the new statement.
1177 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001178 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001179 SourceLocation StarLoc,
1180 Expr *Target) {
John McCallb268a282010-08-23 23:25:46 +00001181 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregorebe10102009-08-20 07:17:43 +00001182 }
Mike Stump11289f42009-09-09 15:08:12 +00001183
Douglas Gregorebe10102009-08-20 07:17:43 +00001184 /// \brief Build a new return statement.
1185 ///
1186 /// By default, performs semantic analysis to build the new statement.
1187 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001188 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
Nick Lewyckyd78f92f2014-05-03 00:41:18 +00001189 return getSema().BuildReturnStmt(ReturnLoc, Result);
Douglas Gregorebe10102009-08-20 07:17:43 +00001190 }
Mike Stump11289f42009-09-09 15:08:12 +00001191
Douglas Gregorebe10102009-08-20 07:17:43 +00001192 /// \brief Build a new declaration statement.
1193 ///
1194 /// By default, performs semantic analysis to build the new statement.
1195 /// Subclasses may override this routine to provide different behavior.
Rafael Espindolaab417692013-07-09 12:05:01 +00001196 StmtResult RebuildDeclStmt(llvm::MutableArrayRef<Decl *> Decls,
1197 SourceLocation StartLoc, SourceLocation EndLoc) {
1198 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls);
Richard Smith2abf6762011-02-23 00:37:57 +00001199 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001200 }
Mike Stump11289f42009-09-09 15:08:12 +00001201
Anders Carlssonaaeef072010-01-24 05:50:09 +00001202 /// \brief Build a new inline asm statement.
1203 ///
1204 /// By default, performs semantic analysis to build the new statement.
1205 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001206 StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
1207 bool IsVolatile, unsigned NumOutputs,
1208 unsigned NumInputs, IdentifierInfo **Names,
1209 MultiExprArg Constraints, MultiExprArg Exprs,
1210 Expr *AsmString, MultiExprArg Clobbers,
1211 SourceLocation RParenLoc) {
1212 return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1213 NumInputs, Names, Constraints, Exprs,
1214 AsmString, Clobbers, RParenLoc);
Anders Carlssonaaeef072010-01-24 05:50:09 +00001215 }
Douglas Gregor306de2f2010-04-22 23:59:56 +00001216
Chad Rosier32503022012-06-11 20:47:18 +00001217 /// \brief Build a new MS style inline asm statement.
1218 ///
1219 /// By default, performs semantic analysis to build the new statement.
1220 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001221 StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc,
John McCallf413f5e2013-05-03 00:10:13 +00001222 ArrayRef<Token> AsmToks,
1223 StringRef AsmString,
1224 unsigned NumOutputs, unsigned NumInputs,
1225 ArrayRef<StringRef> Constraints,
1226 ArrayRef<StringRef> Clobbers,
1227 ArrayRef<Expr*> Exprs,
1228 SourceLocation EndLoc) {
1229 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString,
1230 NumOutputs, NumInputs,
1231 Constraints, Clobbers, Exprs, EndLoc);
Chad Rosier32503022012-06-11 20:47:18 +00001232 }
1233
James Dennett2a4d13c2012-06-15 07:13:21 +00001234 /// \brief Build a new Objective-C \@try statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001235 ///
1236 /// By default, performs semantic analysis to build the new statement.
1237 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001238 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001239 Stmt *TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +00001240 MultiStmtArg CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001241 Stmt *Finally) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001242 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001243 Finally);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001244 }
1245
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001246 /// \brief Rebuild an Objective-C exception declaration.
1247 ///
1248 /// By default, performs semantic analysis to build the new declaration.
1249 /// Subclasses may override this routine to provide different behavior.
1250 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1251 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaradff19302011-03-08 08:55:46 +00001252 return getSema().BuildObjCExceptionDecl(TInfo, T,
1253 ExceptionDecl->getInnerLocStart(),
1254 ExceptionDecl->getLocation(),
1255 ExceptionDecl->getIdentifier());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001256 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001257
James Dennett2a4d13c2012-06-15 07:13:21 +00001258 /// \brief Build a new Objective-C \@catch statement.
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001259 ///
1260 /// By default, performs semantic analysis to build the new statement.
1261 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001262 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001263 SourceLocation RParenLoc,
1264 VarDecl *Var,
John McCallb268a282010-08-23 23:25:46 +00001265 Stmt *Body) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001266 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001267 Var, Body);
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001268 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001269
James Dennett2a4d13c2012-06-15 07:13:21 +00001270 /// \brief Build a new Objective-C \@finally statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001271 ///
1272 /// By default, performs semantic analysis to build the new statement.
1273 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001274 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001275 Stmt *Body) {
1276 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001277 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001278
James Dennett2a4d13c2012-06-15 07:13:21 +00001279 /// \brief Build a new Objective-C \@throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +00001280 ///
1281 /// By default, performs semantic analysis to build the new statement.
1282 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001283 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001284 Expr *Operand) {
1285 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregor2900c162010-04-22 21:44:01 +00001286 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001287
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001288 /// \brief Build a new OpenMP executable directive.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001289 ///
1290 /// By default, performs semantic analysis to build the new statement.
1291 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001292 StmtResult RebuildOMPExecutableDirective(OpenMPDirectiveKind Kind,
1293 ArrayRef<OMPClause *> Clauses,
1294 Stmt *AStmt,
1295 SourceLocation StartLoc,
1296 SourceLocation EndLoc) {
1297 return getSema().ActOnOpenMPExecutableDirective(Kind, Clauses, AStmt,
1298 StartLoc, EndLoc);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001299 }
1300
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001301 /// \brief Build a new OpenMP 'if' clause.
1302 ///
1303 /// By default, performs semantic analysis to build the new statement.
1304 /// Subclasses may override this routine to provide different behavior.
1305 OMPClause *RebuildOMPIfClause(Expr *Condition,
1306 SourceLocation StartLoc,
1307 SourceLocation LParenLoc,
1308 SourceLocation EndLoc) {
1309 return getSema().ActOnOpenMPIfClause(Condition, StartLoc,
1310 LParenLoc, EndLoc);
1311 }
1312
Alexey Bataev568a8332014-03-06 06:15:19 +00001313 /// \brief Build a new OpenMP 'num_threads' clause.
1314 ///
1315 /// By default, performs semantic analysis to build the new statement.
1316 /// Subclasses may override this routine to provide different behavior.
1317 OMPClause *RebuildOMPNumThreadsClause(Expr *NumThreads,
1318 SourceLocation StartLoc,
1319 SourceLocation LParenLoc,
1320 SourceLocation EndLoc) {
1321 return getSema().ActOnOpenMPNumThreadsClause(NumThreads, StartLoc,
1322 LParenLoc, EndLoc);
1323 }
1324
Alexey Bataev62c87d22014-03-21 04:51:18 +00001325 /// \brief Build a new OpenMP 'safelen' clause.
1326 ///
1327 /// By default, performs semantic analysis to build the new statement.
1328 /// Subclasses may override this routine to provide different behavior.
1329 OMPClause *RebuildOMPSafelenClause(Expr *Len, SourceLocation StartLoc,
1330 SourceLocation LParenLoc,
1331 SourceLocation EndLoc) {
1332 return getSema().ActOnOpenMPSafelenClause(Len, StartLoc, LParenLoc, EndLoc);
1333 }
1334
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001335 /// \brief Build a new OpenMP 'default' clause.
1336 ///
1337 /// By default, performs semantic analysis to build the new statement.
1338 /// Subclasses may override this routine to provide different behavior.
1339 OMPClause *RebuildOMPDefaultClause(OpenMPDefaultClauseKind Kind,
1340 SourceLocation KindKwLoc,
1341 SourceLocation StartLoc,
1342 SourceLocation LParenLoc,
1343 SourceLocation EndLoc) {
1344 return getSema().ActOnOpenMPDefaultClause(Kind, KindKwLoc,
1345 StartLoc, LParenLoc, EndLoc);
1346 }
1347
1348 /// \brief Build a new OpenMP 'private' clause.
1349 ///
1350 /// By default, performs semantic analysis to build the new statement.
1351 /// Subclasses may override this routine to provide different behavior.
1352 OMPClause *RebuildOMPPrivateClause(ArrayRef<Expr *> VarList,
1353 SourceLocation StartLoc,
1354 SourceLocation LParenLoc,
1355 SourceLocation EndLoc) {
1356 return getSema().ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc,
1357 EndLoc);
1358 }
1359
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001360 /// \brief Build a new OpenMP 'firstprivate' clause.
1361 ///
1362 /// By default, performs semantic analysis to build the new statement.
1363 /// Subclasses may override this routine to provide different behavior.
1364 OMPClause *RebuildOMPFirstprivateClause(ArrayRef<Expr *> VarList,
1365 SourceLocation StartLoc,
1366 SourceLocation LParenLoc,
1367 SourceLocation EndLoc) {
1368 return getSema().ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc,
1369 EndLoc);
1370 }
1371
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001372 /// \brief Build a new OpenMP 'shared' clause.
1373 ///
1374 /// By default, performs semantic analysis to build the new statement.
1375 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev758e55e2013-09-06 18:03:48 +00001376 OMPClause *RebuildOMPSharedClause(ArrayRef<Expr *> VarList,
1377 SourceLocation StartLoc,
1378 SourceLocation LParenLoc,
1379 SourceLocation EndLoc) {
1380 return getSema().ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc,
1381 EndLoc);
1382 }
1383
Alexander Musman8dba6642014-04-22 13:09:42 +00001384 /// \brief Build a new OpenMP 'linear' clause.
1385 ///
1386 /// By default, performs semantic analysis to build the new statement.
1387 /// Subclasses may override this routine to provide different behavior.
1388 OMPClause *RebuildOMPLinearClause(ArrayRef<Expr *> VarList, Expr *Step,
1389 SourceLocation StartLoc,
1390 SourceLocation LParenLoc,
1391 SourceLocation ColonLoc,
1392 SourceLocation EndLoc) {
1393 return getSema().ActOnOpenMPLinearClause(VarList, Step, StartLoc, LParenLoc,
1394 ColonLoc, EndLoc);
1395 }
1396
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001397 /// \brief Build a new OpenMP 'copyin' clause.
1398 ///
1399 /// By default, performs semantic analysis to build the new statement.
1400 /// Subclasses may override this routine to provide different behavior.
1401 OMPClause *RebuildOMPCopyinClause(ArrayRef<Expr *> VarList,
1402 SourceLocation StartLoc,
1403 SourceLocation LParenLoc,
1404 SourceLocation EndLoc) {
1405 return getSema().ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc,
1406 EndLoc);
1407 }
1408
James Dennett2a4d13c2012-06-15 07:13:21 +00001409 /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
John McCalld9bb7432011-07-27 21:50:02 +00001410 ///
1411 /// By default, performs semantic analysis to build the new statement.
1412 /// Subclasses may override this routine to provide different behavior.
1413 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1414 Expr *object) {
1415 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1416 }
1417
James Dennett2a4d13c2012-06-15 07:13:21 +00001418 /// \brief Build a new Objective-C \@synchronized statement.
Douglas Gregor6148de72010-04-22 22:01:21 +00001419 ///
Douglas Gregor6148de72010-04-22 22:01:21 +00001420 /// By default, performs semantic analysis to build the new statement.
1421 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001422 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCalld9bb7432011-07-27 21:50:02 +00001423 Expr *Object, Stmt *Body) {
1424 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor6148de72010-04-22 22:01:21 +00001425 }
Douglas Gregorf68a5082010-04-22 23:10:45 +00001426
James Dennett2a4d13c2012-06-15 07:13:21 +00001427 /// \brief Build a new Objective-C \@autoreleasepool statement.
John McCall31168b02011-06-15 23:02:42 +00001428 ///
1429 /// By default, performs semantic analysis to build the new statement.
1430 /// Subclasses may override this routine to provide different behavior.
1431 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1432 Stmt *Body) {
1433 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1434 }
John McCall53848232011-07-27 01:07:15 +00001435
Douglas Gregorf68a5082010-04-22 23:10:45 +00001436 /// \brief Build a new Objective-C fast enumeration statement.
1437 ///
1438 /// By default, performs semantic analysis to build the new statement.
1439 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001440 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001441 Stmt *Element,
1442 Expr *Collection,
1443 SourceLocation RParenLoc,
1444 Stmt *Body) {
Sam Panzer2c4ca0f2012-08-16 21:47:25 +00001445 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001446 Element,
John McCallb268a282010-08-23 23:25:46 +00001447 Collection,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001448 RParenLoc);
1449 if (ForEachStmt.isInvalid())
1450 return StmtError();
1451
1452 return getSema().FinishObjCForCollectionStmt(ForEachStmt.take(), Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +00001453 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001454
Douglas Gregorebe10102009-08-20 07:17:43 +00001455 /// \brief Build a new C++ exception declaration.
1456 ///
1457 /// By default, performs semantic analysis to build the new decaration.
1458 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaradff19302011-03-08 08:55:46 +00001459 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +00001460 TypeSourceInfo *Declarator,
Abramo Bagnaradff19302011-03-08 08:55:46 +00001461 SourceLocation StartLoc,
1462 SourceLocation IdLoc,
1463 IdentifierInfo *Id) {
Douglas Gregor40965fa2011-04-14 22:32:28 +00001464 VarDecl *Var = getSema().BuildExceptionDeclaration(0, Declarator,
1465 StartLoc, IdLoc, Id);
1466 if (Var)
1467 getSema().CurContext->addDecl(Var);
1468 return Var;
Douglas Gregorebe10102009-08-20 07:17:43 +00001469 }
1470
1471 /// \brief Build a new C++ catch statement.
1472 ///
1473 /// By default, performs semantic analysis to build the new statement.
1474 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001475 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001476 VarDecl *ExceptionDecl,
1477 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00001478 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1479 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00001480 }
Mike Stump11289f42009-09-09 15:08:12 +00001481
Douglas Gregorebe10102009-08-20 07:17:43 +00001482 /// \brief Build a new C++ try statement.
1483 ///
1484 /// By default, performs semantic analysis to build the new statement.
1485 /// Subclasses may override this routine to provide different behavior.
Robert Wilhelmcafda822013-08-22 09:20:03 +00001486 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock,
1487 ArrayRef<Stmt *> Handlers) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001488 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00001489 }
Mike Stump11289f42009-09-09 15:08:12 +00001490
Richard Smith02e85f32011-04-14 22:09:26 +00001491 /// \brief Build a new C++0x range-based for statement.
1492 ///
1493 /// By default, performs semantic analysis to build the new statement.
1494 /// Subclasses may override this routine to provide different behavior.
1495 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1496 SourceLocation ColonLoc,
1497 Stmt *Range, Stmt *BeginEnd,
1498 Expr *Cond, Expr *Inc,
1499 Stmt *LoopVar,
1500 SourceLocation RParenLoc) {
Douglas Gregorf7106af2013-04-08 18:40:13 +00001501 // If we've just learned that the range is actually an Objective-C
1502 // collection, treat this as an Objective-C fast enumeration loop.
1503 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
1504 if (RangeStmt->isSingleDecl()) {
1505 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
Douglas Gregor39aaeef2013-05-02 18:35:56 +00001506 if (RangeVar->isInvalidDecl())
1507 return StmtError();
1508
Douglas Gregorf7106af2013-04-08 18:40:13 +00001509 Expr *RangeExpr = RangeVar->getInit();
1510 if (!RangeExpr->isTypeDependent() &&
1511 RangeExpr->getType()->isObjCObjectPointerType())
1512 return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, RangeExpr,
1513 RParenLoc);
1514 }
1515 }
1516 }
1517
Richard Smith02e85f32011-04-14 22:09:26 +00001518 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
Richard Smitha05b3b52012-09-20 21:52:32 +00001519 Cond, Inc, LoopVar, RParenLoc,
1520 Sema::BFRK_Rebuild);
Richard Smith02e85f32011-04-14 22:09:26 +00001521 }
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001522
1523 /// \brief Build a new C++0x range-based for statement.
1524 ///
1525 /// By default, performs semantic analysis to build the new statement.
1526 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00001527 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001528 bool IsIfExists,
1529 NestedNameSpecifierLoc QualifierLoc,
1530 DeclarationNameInfo NameInfo,
1531 Stmt *Nested) {
1532 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1533 QualifierLoc, NameInfo, Nested);
1534 }
1535
Richard Smith02e85f32011-04-14 22:09:26 +00001536 /// \brief Attach body to a C++0x range-based for statement.
1537 ///
1538 /// By default, performs semantic analysis to finish the new statement.
1539 /// Subclasses may override this routine to provide different behavior.
1540 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1541 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1542 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001543
David Majnemerfad8f482013-10-15 09:33:02 +00001544 StmtResult RebuildSEHTryStmt(bool IsCXXTry, SourceLocation TryLoc,
1545 Stmt *TryBlock, Stmt *Handler) {
1546 return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +00001547 }
1548
David Majnemerfad8f482013-10-15 09:33:02 +00001549 StmtResult RebuildSEHExceptStmt(SourceLocation Loc, Expr *FilterExpr,
John Wiegley1c0675e2011-04-28 01:08:34 +00001550 Stmt *Block) {
David Majnemerfad8f482013-10-15 09:33:02 +00001551 return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001552 }
1553
David Majnemerfad8f482013-10-15 09:33:02 +00001554 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, Stmt *Block) {
1555 return getSema().ActOnSEHFinallyBlock(Loc, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001556 }
1557
Douglas Gregora16548e2009-08-11 05:31:07 +00001558 /// \brief Build a new expression that references a declaration.
1559 ///
1560 /// By default, performs semantic analysis to build the new expression.
1561 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001562 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00001563 LookupResult &R,
1564 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00001565 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1566 }
1567
1568
1569 /// \brief Build a new expression that references a declaration.
1570 ///
1571 /// By default, performs semantic analysis to build the new expression.
1572 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorea972d32011-02-28 21:54:11 +00001573 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001574 ValueDecl *VD,
1575 const DeclarationNameInfo &NameInfo,
1576 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001577 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001578 SS.Adopt(QualifierLoc);
John McCallce546572009-12-08 09:08:17 +00001579
1580 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001581
1582 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001583 }
Mike Stump11289f42009-09-09 15:08:12 +00001584
Douglas Gregora16548e2009-08-11 05:31:07 +00001585 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001586 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001587 /// By default, performs semantic analysis to build the new expression.
1588 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001589 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00001590 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00001591 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001592 }
1593
Douglas Gregorad8a3362009-09-04 17:36:40 +00001594 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001595 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001596 /// By default, performs semantic analysis to build the new expression.
1597 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001598 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora6ce6082011-02-25 18:19:59 +00001599 SourceLocation OperatorLoc,
1600 bool isArrow,
1601 CXXScopeSpec &SS,
1602 TypeSourceInfo *ScopeType,
1603 SourceLocation CCLoc,
1604 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001605 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001606
Douglas Gregora16548e2009-08-11 05:31:07 +00001607 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001608 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001609 /// By default, performs semantic analysis to build the new expression.
1610 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001611 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001612 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001613 Expr *SubExpr) {
1614 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001615 }
Mike Stump11289f42009-09-09 15:08:12 +00001616
Douglas Gregor882211c2010-04-28 22:16:22 +00001617 /// \brief Build a new builtin offsetof expression.
1618 ///
1619 /// By default, performs semantic analysis to build the new expression.
1620 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001621 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor882211c2010-04-28 22:16:22 +00001622 TypeSourceInfo *Type,
John McCallfaf5fb42010-08-26 23:41:50 +00001623 Sema::OffsetOfComponent *Components,
Douglas Gregor882211c2010-04-28 22:16:22 +00001624 unsigned NumComponents,
1625 SourceLocation RParenLoc) {
1626 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1627 NumComponents, RParenLoc);
1628 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001629
1630 /// \brief Build a new sizeof, alignof or vec_step expression with a
Peter Collingbournee190dee2011-03-11 19:24:49 +00001631 /// type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001632 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001633 /// By default, performs semantic analysis to build the new expression.
1634 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001635 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1636 SourceLocation OpLoc,
1637 UnaryExprOrTypeTrait ExprKind,
1638 SourceRange R) {
1639 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001640 }
1641
Peter Collingbournee190dee2011-03-11 19:24:49 +00001642 /// \brief Build a new sizeof, alignof or vec step expression with an
1643 /// expression argument.
Mike Stump11289f42009-09-09 15:08:12 +00001644 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001645 /// By default, performs semantic analysis to build the new expression.
1646 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001647 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1648 UnaryExprOrTypeTrait ExprKind,
1649 SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00001650 ExprResult Result
Chandler Carrutha923fb22011-05-29 07:32:14 +00001651 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregora16548e2009-08-11 05:31:07 +00001652 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001653 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001654
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001655 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001656 }
Mike Stump11289f42009-09-09 15:08:12 +00001657
Douglas Gregora16548e2009-08-11 05:31:07 +00001658 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001659 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001660 /// By default, performs semantic analysis to build the new expression.
1661 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001662 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001663 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00001664 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001665 SourceLocation RBracketLoc) {
John McCallb268a282010-08-23 23:25:46 +00001666 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1667 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001668 RBracketLoc);
1669 }
1670
1671 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00001672 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001673 /// By default, performs semantic analysis to build the new expression.
1674 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001675 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001676 MultiExprArg Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00001677 SourceLocation RParenLoc,
1678 Expr *ExecConfig = 0) {
John McCallb268a282010-08-23 23:25:46 +00001679 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001680 Args, RParenLoc, ExecConfig);
Douglas Gregora16548e2009-08-11 05:31:07 +00001681 }
1682
1683 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001684 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001685 /// By default, performs semantic analysis to build the new expression.
1686 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001687 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001688 bool isArrow,
Douglas Gregorea972d32011-02-28 21:54:11 +00001689 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001690 SourceLocation TemplateKWLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001691 const DeclarationNameInfo &MemberNameInfo,
1692 ValueDecl *Member,
1693 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001694 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00001695 NamedDecl *FirstQualifierInScope) {
Richard Smithcab9a7d2011-10-26 19:06:56 +00001696 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
1697 isArrow);
Anders Carlsson5da84842009-09-01 04:26:58 +00001698 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00001699 // We have a reference to an unnamed field. This is always the
1700 // base of an anonymous struct/union member access, i.e. the
1701 // field is always of record type.
Douglas Gregorea972d32011-02-28 21:54:11 +00001702 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCall7decc9e2010-11-18 06:31:45 +00001703 assert(Member->getType()->isRecordType() &&
1704 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00001705
Richard Smithcab9a7d2011-10-26 19:06:56 +00001706 BaseResult =
1707 getSema().PerformObjectMemberConversion(BaseResult.take(),
John Wiegley01296292011-04-08 18:41:53 +00001708 QualifierLoc.getNestedNameSpecifier(),
1709 FoundDecl, Member);
1710 if (BaseResult.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001711 return ExprError();
John Wiegley01296292011-04-08 18:41:53 +00001712 Base = BaseResult.take();
John McCall7decc9e2010-11-18 06:31:45 +00001713 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump11289f42009-09-09 15:08:12 +00001714 MemberExpr *ME =
John McCallb268a282010-08-23 23:25:46 +00001715 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001716 Member, MemberNameInfo,
John McCall7decc9e2010-11-18 06:31:45 +00001717 cast<FieldDecl>(Member)->getType(),
1718 VK, OK_Ordinary);
Anders Carlsson5da84842009-09-01 04:26:58 +00001719 return getSema().Owned(ME);
1720 }
Mike Stump11289f42009-09-09 15:08:12 +00001721
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001722 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001723 SS.Adopt(QualifierLoc);
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001724
John Wiegley01296292011-04-08 18:41:53 +00001725 Base = BaseResult.take();
John McCallb268a282010-08-23 23:25:46 +00001726 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00001727
John McCall16df1e52010-03-30 21:47:33 +00001728 // FIXME: this involves duplicating earlier analysis in a lot of
1729 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001730 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001731 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001732 R.resolveKind();
1733
John McCallb268a282010-08-23 23:25:46 +00001734 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001735 SS, TemplateKWLoc,
1736 FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001737 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001738 }
Mike Stump11289f42009-09-09 15:08:12 +00001739
Douglas Gregora16548e2009-08-11 05:31:07 +00001740 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001741 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001742 /// By default, performs semantic analysis to build the new expression.
1743 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001744 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001745 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001746 Expr *LHS, Expr *RHS) {
1747 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001748 }
1749
1750 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001751 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001752 /// By default, performs semantic analysis to build the new expression.
1753 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001754 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCallc07a0c72011-02-17 10:25:35 +00001755 SourceLocation QuestionLoc,
1756 Expr *LHS,
1757 SourceLocation ColonLoc,
1758 Expr *RHS) {
John McCallb268a282010-08-23 23:25:46 +00001759 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1760 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001761 }
1762
Douglas Gregora16548e2009-08-11 05:31:07 +00001763 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001764 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001765 /// By default, performs semantic analysis to build the new expression.
1766 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001767 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00001768 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001769 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001770 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001771 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001772 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001773 }
Mike Stump11289f42009-09-09 15:08:12 +00001774
Douglas Gregora16548e2009-08-11 05:31:07 +00001775 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001776 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001777 /// By default, performs semantic analysis to build the new expression.
1778 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001779 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001780 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001781 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001782 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001783 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001784 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001785 }
Mike Stump11289f42009-09-09 15:08:12 +00001786
Douglas Gregora16548e2009-08-11 05:31:07 +00001787 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001788 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001789 /// By default, performs semantic analysis to build the new expression.
1790 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001791 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001792 SourceLocation OpLoc,
1793 SourceLocation AccessorLoc,
1794 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001795
John McCall10eae182009-11-30 22:42:35 +00001796 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001797 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00001798 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00001799 OpLoc, /*IsArrow*/ false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001800 SS, SourceLocation(),
1801 /*FirstQualifierInScope*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001802 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00001803 /* TemplateArgs */ 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00001804 }
Mike Stump11289f42009-09-09 15:08:12 +00001805
Douglas Gregora16548e2009-08-11 05:31:07 +00001806 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001807 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001808 /// By default, performs semantic analysis to build the new expression.
1809 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001810 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCall542e7c62011-07-06 07:30:07 +00001811 MultiExprArg Inits,
1812 SourceLocation RBraceLoc,
1813 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00001814 ExprResult Result
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001815 = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
Douglas Gregord3d93062009-11-09 17:16:50 +00001816 if (Result.isInvalid() || ResultTy->isDependentType())
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001817 return Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00001818
Douglas Gregord3d93062009-11-09 17:16:50 +00001819 // Patch in the result type we were given, which may have been computed
1820 // when the initial InitListExpr was built.
1821 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1822 ILE->setType(ResultTy);
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001823 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001824 }
Mike Stump11289f42009-09-09 15:08:12 +00001825
Douglas Gregora16548e2009-08-11 05:31:07 +00001826 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001827 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001828 /// By default, performs semantic analysis to build the new expression.
1829 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001830 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00001831 MultiExprArg ArrayExprs,
1832 SourceLocation EqualOrColonLoc,
1833 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001834 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00001835 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001836 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001837 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001838 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001839 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001840
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001841 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001842 }
Mike Stump11289f42009-09-09 15:08:12 +00001843
Douglas Gregora16548e2009-08-11 05:31:07 +00001844 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001845 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001846 /// By default, builds the implicit value initialization without performing
1847 /// any semantic analysis. Subclasses may override this routine to provide
1848 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001849 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001850 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1851 }
Mike Stump11289f42009-09-09 15:08:12 +00001852
Douglas Gregora16548e2009-08-11 05:31:07 +00001853 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001854 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001855 /// By default, performs semantic analysis to build the new expression.
1856 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001857 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001858 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001859 SourceLocation RParenLoc) {
1860 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001861 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001862 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001863 }
1864
1865 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001866 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001867 /// By default, performs semantic analysis to build the new expression.
1868 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001869 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redla9351792012-02-11 23:51:47 +00001870 MultiExprArg SubExprs,
1871 SourceLocation RParenLoc) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001872 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001873 }
Mike Stump11289f42009-09-09 15:08:12 +00001874
Douglas Gregora16548e2009-08-11 05:31:07 +00001875 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001876 ///
1877 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00001878 /// rather than attempting to map the label statement itself.
1879 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001880 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001881 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001882 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregora16548e2009-08-11 05:31:07 +00001883 }
Mike Stump11289f42009-09-09 15:08:12 +00001884
Douglas Gregora16548e2009-08-11 05:31:07 +00001885 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00001886 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001887 /// By default, performs semantic analysis to build the new expression.
1888 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001889 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001890 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00001891 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001892 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001893 }
Mike Stump11289f42009-09-09 15:08:12 +00001894
Douglas Gregora16548e2009-08-11 05:31:07 +00001895 /// \brief Build a new __builtin_choose_expr expression.
1896 ///
1897 /// By default, performs semantic analysis to build the new expression.
1898 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001899 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001900 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001901 SourceLocation RParenLoc) {
1902 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001903 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001904 RParenLoc);
1905 }
Mike Stump11289f42009-09-09 15:08:12 +00001906
Peter Collingbourne91147592011-04-15 00:35:48 +00001907 /// \brief Build a new generic selection expression.
1908 ///
1909 /// By default, performs semantic analysis to build the new expression.
1910 /// Subclasses may override this routine to provide different behavior.
1911 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
1912 SourceLocation DefaultLoc,
1913 SourceLocation RParenLoc,
1914 Expr *ControllingExpr,
Dmitri Gribenko82360372013-05-10 13:06:58 +00001915 ArrayRef<TypeSourceInfo *> Types,
1916 ArrayRef<Expr *> Exprs) {
Peter Collingbourne91147592011-04-15 00:35:48 +00001917 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
Dmitri Gribenko82360372013-05-10 13:06:58 +00001918 ControllingExpr, Types, Exprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00001919 }
1920
Douglas Gregora16548e2009-08-11 05:31:07 +00001921 /// \brief Build a new overloaded operator call expression.
1922 ///
1923 /// By default, performs semantic analysis to build the new expression.
1924 /// The semantic analysis provides the behavior of template instantiation,
1925 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00001926 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00001927 /// argument-dependent lookup, etc. Subclasses may override this routine to
1928 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001929 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00001930 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00001931 Expr *Callee,
1932 Expr *First,
1933 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00001934
1935 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00001936 /// reinterpret_cast.
1937 ///
1938 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00001939 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00001940 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001941 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001942 Stmt::StmtClass Class,
1943 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001944 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001945 SourceLocation RAngleLoc,
1946 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001947 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001948 SourceLocation RParenLoc) {
1949 switch (Class) {
1950 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001951 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001952 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001953 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001954
1955 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001956 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001957 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001958 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001959
Douglas Gregora16548e2009-08-11 05:31:07 +00001960 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001961 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001962 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001963 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001964 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001965
Douglas Gregora16548e2009-08-11 05:31:07 +00001966 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001967 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001968 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001969 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001970
Douglas Gregora16548e2009-08-11 05:31:07 +00001971 default:
David Blaikie83d382b2011-09-23 05:06:16 +00001972 llvm_unreachable("Invalid C++ named cast");
Douglas Gregora16548e2009-08-11 05:31:07 +00001973 }
Douglas Gregora16548e2009-08-11 05:31:07 +00001974 }
Mike Stump11289f42009-09-09 15:08:12 +00001975
Douglas Gregora16548e2009-08-11 05:31:07 +00001976 /// \brief Build a new C++ static_cast expression.
1977 ///
1978 /// By default, performs semantic analysis to build the new expression.
1979 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001980 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001981 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001982 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001983 SourceLocation RAngleLoc,
1984 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001985 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001986 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001987 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00001988 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001989 SourceRange(LAngleLoc, RAngleLoc),
1990 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001991 }
1992
1993 /// \brief Build a new C++ dynamic_cast expression.
1994 ///
1995 /// By default, performs semantic analysis to build the new expression.
1996 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001997 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001998 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001999 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002000 SourceLocation RAngleLoc,
2001 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002002 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002003 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002004 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00002005 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002006 SourceRange(LAngleLoc, RAngleLoc),
2007 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002008 }
2009
2010 /// \brief Build a new C++ reinterpret_cast expression.
2011 ///
2012 /// By default, performs semantic analysis to build the new expression.
2013 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002014 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002015 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002016 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002017 SourceLocation RAngleLoc,
2018 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002019 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002020 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002021 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00002022 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002023 SourceRange(LAngleLoc, RAngleLoc),
2024 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002025 }
2026
2027 /// \brief Build a new C++ const_cast expression.
2028 ///
2029 /// By default, performs semantic analysis to build the new expression.
2030 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002031 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002032 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002033 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002034 SourceLocation RAngleLoc,
2035 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002036 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002037 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002038 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00002039 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002040 SourceRange(LAngleLoc, RAngleLoc),
2041 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002042 }
Mike Stump11289f42009-09-09 15:08:12 +00002043
Douglas Gregora16548e2009-08-11 05:31:07 +00002044 /// \brief Build a new C++ functional-style cast expression.
2045 ///
2046 /// By default, performs semantic analysis to build the new expression.
2047 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002048 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
2049 SourceLocation LParenLoc,
2050 Expr *Sub,
2051 SourceLocation RParenLoc) {
2052 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00002053 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00002054 RParenLoc);
2055 }
Mike Stump11289f42009-09-09 15:08:12 +00002056
Douglas Gregora16548e2009-08-11 05:31:07 +00002057 /// \brief Build a new C++ typeid(type) expression.
2058 ///
2059 /// By default, performs semantic analysis to build the new expression.
2060 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002061 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002062 SourceLocation TypeidLoc,
2063 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002064 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002065 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002066 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002067 }
Mike Stump11289f42009-09-09 15:08:12 +00002068
Francois Pichet9f4f2072010-09-08 12:20:18 +00002069
Douglas Gregora16548e2009-08-11 05:31:07 +00002070 /// \brief Build a new C++ typeid(expr) expression.
2071 ///
2072 /// By default, performs semantic analysis to build the new expression.
2073 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002074 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002075 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00002076 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002077 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002078 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002079 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002080 }
2081
Francois Pichet9f4f2072010-09-08 12:20:18 +00002082 /// \brief Build a new C++ __uuidof(type) expression.
2083 ///
2084 /// By default, performs semantic analysis to build the new expression.
2085 /// Subclasses may override this routine to provide different behavior.
2086 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2087 SourceLocation TypeidLoc,
2088 TypeSourceInfo *Operand,
2089 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002090 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
Francois Pichet9f4f2072010-09-08 12:20:18 +00002091 RParenLoc);
2092 }
2093
2094 /// \brief Build a new C++ __uuidof(expr) expression.
2095 ///
2096 /// By default, performs semantic analysis to build the new expression.
2097 /// Subclasses may override this routine to provide different behavior.
2098 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2099 SourceLocation TypeidLoc,
2100 Expr *Operand,
2101 SourceLocation RParenLoc) {
2102 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
2103 RParenLoc);
2104 }
2105
Douglas Gregora16548e2009-08-11 05:31:07 +00002106 /// \brief Build a new C++ "this" expression.
2107 ///
2108 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00002109 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00002110 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002111 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00002112 QualType ThisType,
2113 bool isImplicit) {
Eli Friedman20139d32012-01-11 02:36:31 +00002114 getSema().CheckCXXThisCapture(ThisLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002115 return getSema().Owned(
Douglas Gregorb15af892010-01-07 23:12:05 +00002116 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
2117 isImplicit));
Douglas Gregora16548e2009-08-11 05:31:07 +00002118 }
2119
2120 /// \brief Build a new C++ throw expression.
2121 ///
2122 /// By default, performs semantic analysis to build the new expression.
2123 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor53e191ed2011-07-06 22:04:06 +00002124 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
2125 bool IsThrownVariableInScope) {
2126 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00002127 }
2128
2129 /// \brief Build a new C++ default-argument expression.
2130 ///
2131 /// By default, builds a new default-argument expression, which does not
2132 /// require any semantic analysis. Subclasses may override this routine to
2133 /// provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002134 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00002135 ParmVarDecl *Param) {
2136 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
2137 Param));
Douglas Gregora16548e2009-08-11 05:31:07 +00002138 }
2139
Richard Smith852c9db2013-04-20 22:23:05 +00002140 /// \brief Build a new C++11 default-initialization expression.
2141 ///
2142 /// By default, builds a new default field initialization expression, which
2143 /// does not require any semantic analysis. Subclasses may override this
2144 /// routine to provide different behavior.
2145 ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc,
2146 FieldDecl *Field) {
2147 return getSema().Owned(CXXDefaultInitExpr::Create(getSema().Context, Loc,
2148 Field));
2149 }
2150
Douglas Gregora16548e2009-08-11 05:31:07 +00002151 /// \brief Build a new C++ zero-initialization expression.
2152 ///
2153 /// By default, performs semantic analysis to build the new expression.
2154 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002155 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
2156 SourceLocation LParenLoc,
2157 SourceLocation RParenLoc) {
2158 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002159 None, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002160 }
Mike Stump11289f42009-09-09 15:08:12 +00002161
Douglas Gregora16548e2009-08-11 05:31:07 +00002162 /// \brief Build a new C++ "new" expression.
2163 ///
2164 /// By default, performs semantic analysis to build the new expression.
2165 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002166 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002167 bool UseGlobal,
2168 SourceLocation PlacementLParen,
2169 MultiExprArg PlacementArgs,
2170 SourceLocation PlacementRParen,
2171 SourceRange TypeIdParens,
2172 QualType AllocatedType,
2173 TypeSourceInfo *AllocatedTypeInfo,
2174 Expr *ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002175 SourceRange DirectInitRange,
2176 Expr *Initializer) {
Mike Stump11289f42009-09-09 15:08:12 +00002177 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00002178 PlacementLParen,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002179 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00002180 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00002181 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002182 AllocatedType,
2183 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00002184 ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002185 DirectInitRange,
2186 Initializer);
Douglas Gregora16548e2009-08-11 05:31:07 +00002187 }
Mike Stump11289f42009-09-09 15:08:12 +00002188
Douglas Gregora16548e2009-08-11 05:31:07 +00002189 /// \brief Build a new C++ "delete" expression.
2190 ///
2191 /// By default, performs semantic analysis to build the new expression.
2192 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002193 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002194 bool IsGlobalDelete,
2195 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002196 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002197 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002198 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00002199 }
Mike Stump11289f42009-09-09 15:08:12 +00002200
Douglas Gregor29c42f22012-02-24 07:38:34 +00002201 /// \brief Build a new type trait expression.
2202 ///
2203 /// By default, performs semantic analysis to build the new expression.
2204 /// Subclasses may override this routine to provide different behavior.
2205 ExprResult RebuildTypeTrait(TypeTrait Trait,
2206 SourceLocation StartLoc,
2207 ArrayRef<TypeSourceInfo *> Args,
2208 SourceLocation RParenLoc) {
2209 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2210 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002211
John Wiegley6242b6a2011-04-28 00:16:57 +00002212 /// \brief Build a new array type trait expression.
2213 ///
2214 /// By default, performs semantic analysis to build the new expression.
2215 /// Subclasses may override this routine to provide different behavior.
2216 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2217 SourceLocation StartLoc,
2218 TypeSourceInfo *TSInfo,
2219 Expr *DimExpr,
2220 SourceLocation RParenLoc) {
2221 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2222 }
2223
John Wiegleyf9f65842011-04-25 06:54:41 +00002224 /// \brief Build a new expression trait expression.
2225 ///
2226 /// By default, performs semantic analysis to build the new expression.
2227 /// Subclasses may override this routine to provide different behavior.
2228 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2229 SourceLocation StartLoc,
2230 Expr *Queried,
2231 SourceLocation RParenLoc) {
2232 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2233 }
2234
Mike Stump11289f42009-09-09 15:08:12 +00002235 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00002236 /// expression.
2237 ///
2238 /// By default, performs semantic analysis to build the new expression.
2239 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002240 ExprResult RebuildDependentScopeDeclRefExpr(
2241 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002242 SourceLocation TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002243 const DeclarationNameInfo &NameInfo,
Richard Smithdb2630f2012-10-21 03:28:35 +00002244 const TemplateArgumentListInfo *TemplateArgs,
2245 bool IsAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002246 CXXScopeSpec SS;
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002247 SS.Adopt(QualifierLoc);
John McCalle66edc12009-11-24 19:00:30 +00002248
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002249 if (TemplateArgs || TemplateKWLoc.isValid())
Abramo Bagnara7945c982012-01-27 09:46:47 +00002250 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002251 NameInfo, TemplateArgs);
John McCalle66edc12009-11-24 19:00:30 +00002252
Richard Smithdb2630f2012-10-21 03:28:35 +00002253 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo,
2254 IsAddressOfOperand);
Douglas Gregora16548e2009-08-11 05:31:07 +00002255 }
2256
2257 /// \brief Build a new template-id expression.
2258 ///
2259 /// By default, performs semantic analysis to build the new expression.
2260 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002261 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002262 SourceLocation TemplateKWLoc,
2263 LookupResult &R,
2264 bool RequiresADL,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002265 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnara7945c982012-01-27 09:46:47 +00002266 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2267 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002268 }
2269
2270 /// \brief Build a new object-construction expression.
2271 ///
2272 /// By default, performs semantic analysis to build the new expression.
2273 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002274 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002275 SourceLocation Loc,
2276 CXXConstructorDecl *Constructor,
2277 bool IsElidable,
2278 MultiExprArg Args,
2279 bool HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002280 bool ListInitialization,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002281 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00002282 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002283 SourceRange ParenRange) {
Benjamin Kramerf0623432012-08-23 22:51:59 +00002284 SmallVector<Expr*, 8> ConvertedArgs;
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002285 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00002286 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00002287 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002288
Douglas Gregordb121ba2009-12-14 16:27:04 +00002289 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002290 ConvertedArgs,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002291 HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002292 ListInitialization,
Chandler Carruth01718152010-10-25 08:47:36 +00002293 RequiresZeroInit, ConstructKind,
2294 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00002295 }
2296
2297 /// \brief Build a new object-construction expression.
2298 ///
2299 /// By default, performs semantic analysis to build the new expression.
2300 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002301 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2302 SourceLocation LParenLoc,
2303 MultiExprArg Args,
2304 SourceLocation RParenLoc) {
2305 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002306 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002307 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002308 RParenLoc);
2309 }
2310
2311 /// \brief Build a new object-construction expression.
2312 ///
2313 /// By default, performs semantic analysis to build the new expression.
2314 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002315 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2316 SourceLocation LParenLoc,
2317 MultiExprArg Args,
2318 SourceLocation RParenLoc) {
2319 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002320 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002321 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002322 RParenLoc);
2323 }
Mike Stump11289f42009-09-09 15:08:12 +00002324
Douglas Gregora16548e2009-08-11 05:31:07 +00002325 /// \brief Build a new member reference expression.
2326 ///
2327 /// By default, performs semantic analysis to build the new expression.
2328 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002329 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregore16af532011-02-28 18:50:33 +00002330 QualType BaseType,
2331 bool IsArrow,
2332 SourceLocation OperatorLoc,
2333 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002334 SourceLocation TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00002335 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002336 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00002337 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002338 CXXScopeSpec SS;
Douglas Gregore16af532011-02-28 18:50:33 +00002339 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002340
John McCallb268a282010-08-23 23:25:46 +00002341 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002342 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002343 SS, TemplateKWLoc,
2344 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002345 MemberNameInfo,
2346 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002347 }
2348
John McCall10eae182009-11-30 22:42:35 +00002349 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00002350 ///
2351 /// By default, performs semantic analysis to build the new expression.
2352 /// Subclasses may override this routine to provide different behavior.
Richard Smithcab9a7d2011-10-26 19:06:56 +00002353 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2354 SourceLocation OperatorLoc,
2355 bool IsArrow,
2356 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002357 SourceLocation TemplateKWLoc,
Richard Smithcab9a7d2011-10-26 19:06:56 +00002358 NamedDecl *FirstQualifierInScope,
2359 LookupResult &R,
John McCall10eae182009-11-30 22:42:35 +00002360 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00002361 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00002362 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002363
John McCallb268a282010-08-23 23:25:46 +00002364 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002365 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002366 SS, TemplateKWLoc,
2367 FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00002368 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00002369 }
Mike Stump11289f42009-09-09 15:08:12 +00002370
Sebastian Redl4202c0f2010-09-10 20:55:43 +00002371 /// \brief Build a new noexcept expression.
2372 ///
2373 /// By default, performs semantic analysis to build the new expression.
2374 /// Subclasses may override this routine to provide different behavior.
2375 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2376 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2377 }
2378
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002379 /// \brief Build a new expression to compute the length of a parameter pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00002380 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2381 SourceLocation PackLoc,
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002382 SourceLocation RParenLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002383 Optional<unsigned> Length) {
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002384 if (Length)
Chad Rosier1dcde962012-08-08 18:46:20 +00002385 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2386 OperatorLoc, Pack, PackLoc,
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002387 RParenLoc, *Length);
Chad Rosier1dcde962012-08-08 18:46:20 +00002388
2389 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2390 OperatorLoc, Pack, PackLoc,
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002391 RParenLoc);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002392 }
Ted Kremeneke65b0862012-03-06 20:05:56 +00002393
Patrick Beard0caa3942012-04-19 00:25:12 +00002394 /// \brief Build a new Objective-C boxed expression.
2395 ///
2396 /// By default, performs semantic analysis to build the new expression.
2397 /// Subclasses may override this routine to provide different behavior.
2398 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2399 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2400 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002401
Ted Kremeneke65b0862012-03-06 20:05:56 +00002402 /// \brief Build a new Objective-C array literal.
2403 ///
2404 /// By default, performs semantic analysis to build the new expression.
2405 /// Subclasses may override this routine to provide different behavior.
2406 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2407 Expr **Elements, unsigned NumElements) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002408 return getSema().BuildObjCArrayLiteral(Range,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002409 MultiExprArg(Elements, NumElements));
2410 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002411
2412 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002413 Expr *Base, Expr *Key,
2414 ObjCMethodDecl *getterMethod,
2415 ObjCMethodDecl *setterMethod) {
2416 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2417 getterMethod, setterMethod);
2418 }
2419
2420 /// \brief Build a new Objective-C dictionary literal.
2421 ///
2422 /// By default, performs semantic analysis to build the new expression.
2423 /// Subclasses may override this routine to provide different behavior.
2424 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
2425 ObjCDictionaryElement *Elements,
2426 unsigned NumElements) {
2427 return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements);
2428 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002429
James Dennett2a4d13c2012-06-15 07:13:21 +00002430 /// \brief Build a new Objective-C \@encode expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002431 ///
2432 /// By default, performs semantic analysis to build the new expression.
2433 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002434 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00002435 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002436 SourceLocation RParenLoc) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00002437 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002438 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00002439 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002440
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002441 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00002442 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002443 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002444 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002445 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002446 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002447 MultiExprArg Args,
2448 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002449 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2450 ReceiverTypeInfo->getType(),
2451 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002452 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002453 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002454 }
2455
2456 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00002457 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002458 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002459 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002460 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002461 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002462 MultiExprArg Args,
2463 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00002464 return SemaRef.BuildInstanceMessage(Receiver,
2465 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002466 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002467 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002468 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002469 }
2470
Douglas Gregord51d90d2010-04-26 20:11:03 +00002471 /// \brief Build a new Objective-C ivar reference expression.
2472 ///
2473 /// By default, performs semantic analysis to build the new expression.
2474 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002475 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002476 SourceLocation IvarLoc,
2477 bool IsArrow, bool IsFreeIvar) {
2478 // FIXME: We lose track of the IsFreeIvar bit.
2479 CXXScopeSpec SS;
John Wiegley01296292011-04-08 18:41:53 +00002480 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002481 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2482 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00002483 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002484 /*FIME:*/IvarLoc,
John McCall48871652010-08-21 09:40:31 +00002485 SS, 0,
John McCalle9cccd82010-06-16 08:42:20 +00002486 false);
John Wiegley01296292011-04-08 18:41:53 +00002487 if (Result.isInvalid() || Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002488 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002489
Douglas Gregord51d90d2010-04-26 20:11:03 +00002490 if (Result.get())
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002491 return Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00002492
John Wiegley01296292011-04-08 18:41:53 +00002493 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Abramo Bagnara7945c982012-01-27 09:46:47 +00002494 /*FIXME:*/IvarLoc, IsArrow,
2495 SS, SourceLocation(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00002496 /*FirstQualifierInScope=*/0,
Chad Rosier1dcde962012-08-08 18:46:20 +00002497 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002498 /*TemplateArgs=*/0);
2499 }
Douglas Gregor9faee212010-04-26 20:47:02 +00002500
2501 /// \brief Build a new Objective-C property reference expression.
2502 ///
2503 /// By default, performs semantic analysis to build the new expression.
2504 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002505 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall526ab472011-10-25 17:37:35 +00002506 ObjCPropertyDecl *Property,
2507 SourceLocation PropertyLoc) {
Douglas Gregor9faee212010-04-26 20:47:02 +00002508 CXXScopeSpec SS;
John Wiegley01296292011-04-08 18:41:53 +00002509 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregor9faee212010-04-26 20:47:02 +00002510 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2511 Sema::LookupMemberName);
2512 bool IsArrow = false;
John McCalldadc5752010-08-24 06:29:42 +00002513 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregor9faee212010-04-26 20:47:02 +00002514 /*FIME:*/PropertyLoc,
John McCall48871652010-08-21 09:40:31 +00002515 SS, 0, false);
John Wiegley01296292011-04-08 18:41:53 +00002516 if (Result.isInvalid() || Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002517 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002518
Douglas Gregor9faee212010-04-26 20:47:02 +00002519 if (Result.get())
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002520 return Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00002521
John Wiegley01296292011-04-08 18:41:53 +00002522 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Chad Rosier1dcde962012-08-08 18:46:20 +00002523 /*FIXME:*/PropertyLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002524 SS, SourceLocation(),
Douglas Gregor9faee212010-04-26 20:47:02 +00002525 /*FirstQualifierInScope=*/0,
Chad Rosier1dcde962012-08-08 18:46:20 +00002526 R,
Douglas Gregor9faee212010-04-26 20:47:02 +00002527 /*TemplateArgs=*/0);
2528 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002529
John McCallb7bd14f2010-12-02 01:19:52 +00002530 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002531 ///
2532 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00002533 /// Subclasses may override this routine to provide different behavior.
2534 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2535 ObjCMethodDecl *Getter,
2536 ObjCMethodDecl *Setter,
2537 SourceLocation PropertyLoc) {
2538 // Since these expressions can only be value-dependent, we do not
2539 // need to perform semantic analysis again.
2540 return Owned(
2541 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2542 VK_LValue, OK_ObjCProperty,
2543 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002544 }
2545
Douglas Gregord51d90d2010-04-26 20:11:03 +00002546 /// \brief Build a new Objective-C "isa" expression.
2547 ///
2548 /// By default, performs semantic analysis to build the new expression.
2549 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002550 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00002551 SourceLocation OpLoc,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002552 bool IsArrow) {
2553 CXXScopeSpec SS;
John Wiegley01296292011-04-08 18:41:53 +00002554 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002555 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2556 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00002557 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00002558 OpLoc,
John McCall48871652010-08-21 09:40:31 +00002559 SS, 0, false);
John Wiegley01296292011-04-08 18:41:53 +00002560 if (Result.isInvalid() || Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002561 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002562
Douglas Gregord51d90d2010-04-26 20:11:03 +00002563 if (Result.get())
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002564 return Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00002565
John Wiegley01296292011-04-08 18:41:53 +00002566 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00002567 OpLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002568 SS, SourceLocation(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00002569 /*FirstQualifierInScope=*/0,
Chad Rosier1dcde962012-08-08 18:46:20 +00002570 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002571 /*TemplateArgs=*/0);
2572 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002573
Douglas Gregora16548e2009-08-11 05:31:07 +00002574 /// \brief Build a new shuffle vector expression.
2575 ///
2576 /// By default, performs semantic analysis to build the new expression.
2577 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002578 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002579 MultiExprArg SubExprs,
2580 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002581 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00002582 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00002583 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2584 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2585 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
David Blaikieff7d47a2012-12-19 00:45:41 +00002586 assert(!Lookup.empty() && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00002587
Douglas Gregora16548e2009-08-11 05:31:07 +00002588 // Build a reference to the __builtin_shufflevector builtin
David Blaikieff7d47a2012-12-19 00:45:41 +00002589 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
Eli Friedman34866c72012-08-31 00:14:07 +00002590 Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false,
2591 SemaRef.Context.BuiltinFnTy,
2592 VK_RValue, BuiltinLoc);
2593 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
2594 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
2595 CK_BuiltinFnToFnPtr).take();
Mike Stump11289f42009-09-09 15:08:12 +00002596
2597 // Build the CallExpr
Alp Toker314cc812014-01-25 16:55:45 +00002598 ExprResult TheCall = SemaRef.Owned(new (SemaRef.Context) CallExpr(
2599 SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(),
2600 Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00002601
Douglas Gregora16548e2009-08-11 05:31:07 +00002602 // Type-check the __builtin_shufflevector expression.
John Wiegley01296292011-04-08 18:41:53 +00002603 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.take()));
Douglas Gregora16548e2009-08-11 05:31:07 +00002604 }
John McCall31f82722010-11-12 08:19:04 +00002605
Hal Finkelc4d7c822013-09-18 03:29:45 +00002606 /// \brief Build a new convert vector expression.
2607 ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc,
2608 Expr *SrcExpr, TypeSourceInfo *DstTInfo,
2609 SourceLocation RParenLoc) {
2610 return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo,
2611 BuiltinLoc, RParenLoc);
2612 }
2613
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002614 /// \brief Build a new template argument pack expansion.
2615 ///
2616 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00002617 /// for a template argument. Subclasses may override this routine to provide
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002618 /// different behavior.
2619 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002620 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002621 Optional<unsigned> NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002622 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00002623 case TemplateArgument::Expression: {
2624 ExprResult Result
Douglas Gregorb8840002011-01-14 21:20:45 +00002625 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2626 EllipsisLoc, NumExpansions);
Douglas Gregor98318c22011-01-03 21:37:45 +00002627 if (Result.isInvalid())
2628 return TemplateArgumentLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00002629
Douglas Gregor98318c22011-01-03 21:37:45 +00002630 return TemplateArgumentLoc(Result.get(), Result.get());
2631 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002632
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002633 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002634 return TemplateArgumentLoc(TemplateArgument(
2635 Pattern.getArgument().getAsTemplate(),
Douglas Gregore1d60df2011-01-14 23:41:42 +00002636 NumExpansions),
Douglas Gregor9d802122011-03-02 17:09:35 +00002637 Pattern.getTemplateQualifierLoc(),
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002638 Pattern.getTemplateNameLoc(),
2639 EllipsisLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00002640
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002641 case TemplateArgument::Null:
2642 case TemplateArgument::Integral:
2643 case TemplateArgument::Declaration:
2644 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002645 case TemplateArgument::TemplateExpansion:
Eli Friedmanb826a002012-09-26 02:36:12 +00002646 case TemplateArgument::NullPtr:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002647 llvm_unreachable("Pack expansion pattern has no parameter packs");
Chad Rosier1dcde962012-08-08 18:46:20 +00002648
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002649 case TemplateArgument::Type:
Chad Rosier1dcde962012-08-08 18:46:20 +00002650 if (TypeSourceInfo *Expansion
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002651 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002652 EllipsisLoc,
2653 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002654 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2655 Expansion);
2656 break;
2657 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002658
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002659 return TemplateArgumentLoc();
2660 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002661
Douglas Gregor968f23a2011-01-03 19:31:53 +00002662 /// \brief Build a new expression pack expansion.
2663 ///
2664 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00002665 /// for an expression. Subclasses may override this routine to provide
Douglas Gregor968f23a2011-01-03 19:31:53 +00002666 /// different behavior.
Douglas Gregorb8840002011-01-14 21:20:45 +00002667 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002668 Optional<unsigned> NumExpansions) {
Douglas Gregorb8840002011-01-14 21:20:45 +00002669 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002670 }
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002671
2672 /// \brief Build a new atomic operation expression.
2673 ///
2674 /// By default, performs semantic analysis to build the new expression.
2675 /// Subclasses may override this routine to provide different behavior.
2676 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2677 MultiExprArg SubExprs,
2678 QualType RetTy,
2679 AtomicExpr::AtomicOp Op,
2680 SourceLocation RParenLoc) {
2681 // Just create the expression; there is not any interesting semantic
2682 // analysis here because we can't actually build an AtomicExpr until
2683 // we are sure it is semantically sound.
Benjamin Kramerc215e762012-08-24 11:54:20 +00002684 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002685 RParenLoc);
2686 }
2687
John McCall31f82722010-11-12 08:19:04 +00002688private:
Douglas Gregor14454802011-02-25 02:25:35 +00002689 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2690 QualType ObjectType,
2691 NamedDecl *FirstQualifierInScope,
2692 CXXScopeSpec &SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00002693
2694 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2695 QualType ObjectType,
2696 NamedDecl *FirstQualifierInScope,
2697 CXXScopeSpec &SS);
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00002698
2699 TypeSourceInfo *TransformTSIInObjectScope(TypeLoc TL, QualType ObjectType,
2700 NamedDecl *FirstQualifierInScope,
2701 CXXScopeSpec &SS);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002702};
Douglas Gregora16548e2009-08-11 05:31:07 +00002703
Douglas Gregorebe10102009-08-20 07:17:43 +00002704template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002705StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002706 if (!S)
2707 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00002708
Douglas Gregorebe10102009-08-20 07:17:43 +00002709 switch (S->getStmtClass()) {
2710 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00002711
Douglas Gregorebe10102009-08-20 07:17:43 +00002712 // Transform individual statement nodes
2713#define STMT(Node, Parent) \
2714 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCallbd066782011-02-09 08:16:59 +00002715#define ABSTRACT_STMT(Node)
Douglas Gregorebe10102009-08-20 07:17:43 +00002716#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00002717#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002718
Douglas Gregorebe10102009-08-20 07:17:43 +00002719 // Transform expressions by calling TransformExpr.
2720#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00002721#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00002722#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00002723#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00002724 {
John McCalldadc5752010-08-24 06:29:42 +00002725 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00002726 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002727 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002728
Richard Smith945f8d32013-01-14 22:39:08 +00002729 return getSema().ActOnExprStmt(E);
Douglas Gregorebe10102009-08-20 07:17:43 +00002730 }
Mike Stump11289f42009-09-09 15:08:12 +00002731 }
2732
John McCallc3007a22010-10-26 07:05:15 +00002733 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00002734}
Mike Stump11289f42009-09-09 15:08:12 +00002735
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00002736template<typename Derived>
2737OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) {
2738 if (!S)
2739 return S;
2740
2741 switch (S->getClauseKind()) {
2742 default: break;
2743 // Transform individual clause nodes
2744#define OPENMP_CLAUSE(Name, Class) \
2745 case OMPC_ ## Name : \
2746 return getDerived().Transform ## Class(cast<Class>(S));
2747#include "clang/Basic/OpenMPKinds.def"
2748 }
2749
2750 return S;
2751}
2752
Mike Stump11289f42009-09-09 15:08:12 +00002753
Douglas Gregore922c772009-08-04 22:27:00 +00002754template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002755ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002756 if (!E)
2757 return SemaRef.Owned(E);
2758
2759 switch (E->getStmtClass()) {
2760 case Stmt::NoStmtClass: break;
2761#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00002762#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00002763#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00002764 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00002765#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002766 }
2767
John McCallc3007a22010-10-26 07:05:15 +00002768 return SemaRef.Owned(E);
Douglas Gregor766b0bb2009-08-06 22:17:10 +00002769}
2770
2771template<typename Derived>
Richard Smithd59b8322012-12-19 01:39:02 +00002772ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
2773 bool CXXDirectInit) {
2774 // Initializers are instantiated like expressions, except that various outer
2775 // layers are stripped.
2776 if (!Init)
2777 return SemaRef.Owned(Init);
2778
2779 if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init))
2780 Init = ExprTemp->getSubExpr();
2781
Richard Smithe6ca4752013-05-30 22:40:16 +00002782 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
2783 Init = MTE->GetTemporaryExpr();
2784
Richard Smithd59b8322012-12-19 01:39:02 +00002785 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
2786 Init = Binder->getSubExpr();
2787
2788 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
2789 Init = ICE->getSubExprAsWritten();
2790
Richard Smithcc1b96d2013-06-12 22:31:48 +00002791 if (CXXStdInitializerListExpr *ILE =
2792 dyn_cast<CXXStdInitializerListExpr>(Init))
2793 return TransformInitializer(ILE->getSubExpr(), CXXDirectInit);
2794
Richard Smith38a549b2012-12-21 08:13:35 +00002795 // If this is not a direct-initializer, we only need to reconstruct
2796 // InitListExprs. Other forms of copy-initialization will be a no-op if
2797 // the initializer is already the right type.
2798 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
2799 if (!CXXDirectInit && !(Construct && Construct->isListInitialization()))
2800 return getDerived().TransformExpr(Init);
2801
2802 // Revert value-initialization back to empty parens.
2803 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
2804 SourceRange Parens = VIE->getSourceRange();
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002805 return getDerived().RebuildParenListExpr(Parens.getBegin(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00002806 Parens.getEnd());
2807 }
2808
2809 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
2810 if (isa<ImplicitValueInitExpr>(Init))
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002811 return getDerived().RebuildParenListExpr(SourceLocation(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00002812 SourceLocation());
2813
2814 // Revert initialization by constructor back to a parenthesized or braced list
2815 // of expressions. Any other form of initializer can just be reused directly.
2816 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
Richard Smithd59b8322012-12-19 01:39:02 +00002817 return getDerived().TransformExpr(Init);
2818
2819 SmallVector<Expr*, 8> NewArgs;
2820 bool ArgChanged = false;
2821 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
2822 /*IsCall*/true, NewArgs, &ArgChanged))
2823 return ExprError();
2824
2825 // If this was list initialization, revert to list form.
2826 if (Construct->isListInitialization())
2827 return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs,
2828 Construct->getLocEnd(),
2829 Construct->getType());
2830
Richard Smithd59b8322012-12-19 01:39:02 +00002831 // Build a ParenListExpr to represent anything else.
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00002832 SourceRange Parens = Construct->getParenOrBraceRange();
Richard Smithd59b8322012-12-19 01:39:02 +00002833 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
2834 Parens.getEnd());
2835}
2836
2837template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00002838bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2839 unsigned NumInputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00002840 bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +00002841 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00002842 bool *ArgChanged) {
2843 for (unsigned I = 0; I != NumInputs; ++I) {
2844 // If requested, drop call arguments that need to be dropped.
2845 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2846 if (ArgChanged)
2847 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002848
Douglas Gregora3efea12011-01-03 19:04:46 +00002849 break;
2850 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002851
Douglas Gregor968f23a2011-01-03 19:31:53 +00002852 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2853 Expr *Pattern = Expansion->getPattern();
Chad Rosier1dcde962012-08-08 18:46:20 +00002854
Chris Lattner01cf8db2011-07-20 06:58:45 +00002855 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor968f23a2011-01-03 19:31:53 +00002856 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2857 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00002858
Douglas Gregor968f23a2011-01-03 19:31:53 +00002859 // Determine whether the set of unexpanded parameter packs can and should
2860 // be expanded.
2861 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002862 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00002863 Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
2864 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor968f23a2011-01-03 19:31:53 +00002865 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2866 Pattern->getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00002867 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002868 Expand, RetainExpansion,
2869 NumExpansions))
Douglas Gregor968f23a2011-01-03 19:31:53 +00002870 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002871
Douglas Gregor968f23a2011-01-03 19:31:53 +00002872 if (!Expand) {
2873 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00002874 // transformation on the pack expansion, producing another pack
Douglas Gregor968f23a2011-01-03 19:31:53 +00002875 // expansion.
2876 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2877 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2878 if (OutPattern.isInvalid())
2879 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002880
2881 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregorb8840002011-01-14 21:20:45 +00002882 Expansion->getEllipsisLoc(),
2883 NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002884 if (Out.isInvalid())
2885 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002886
Douglas Gregor968f23a2011-01-03 19:31:53 +00002887 if (ArgChanged)
2888 *ArgChanged = true;
2889 Outputs.push_back(Out.get());
2890 continue;
2891 }
John McCall542e7c62011-07-06 07:30:07 +00002892
2893 // Record right away that the argument was changed. This needs
2894 // to happen even if the array expands to nothing.
2895 if (ArgChanged) *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002896
Douglas Gregor968f23a2011-01-03 19:31:53 +00002897 // The transform has determined that we should perform an elementwise
2898 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002899 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor968f23a2011-01-03 19:31:53 +00002900 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2901 ExprResult Out = getDerived().TransformExpr(Pattern);
2902 if (Out.isInvalid())
2903 return true;
2904
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002905 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregorb8840002011-01-14 21:20:45 +00002906 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2907 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002908 if (Out.isInvalid())
2909 return true;
2910 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002911
Douglas Gregor968f23a2011-01-03 19:31:53 +00002912 Outputs.push_back(Out.get());
2913 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002914
Douglas Gregor968f23a2011-01-03 19:31:53 +00002915 continue;
2916 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002917
Richard Smithd59b8322012-12-19 01:39:02 +00002918 ExprResult Result =
2919 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
2920 : getDerived().TransformExpr(Inputs[I]);
Douglas Gregora3efea12011-01-03 19:04:46 +00002921 if (Result.isInvalid())
2922 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002923
Douglas Gregora3efea12011-01-03 19:04:46 +00002924 if (Result.get() != Inputs[I] && ArgChanged)
2925 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002926
2927 Outputs.push_back(Result.get());
Douglas Gregora3efea12011-01-03 19:04:46 +00002928 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002929
Douglas Gregora3efea12011-01-03 19:04:46 +00002930 return false;
2931}
2932
2933template<typename Derived>
Douglas Gregor14454802011-02-25 02:25:35 +00002934NestedNameSpecifierLoc
2935TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2936 NestedNameSpecifierLoc NNS,
2937 QualType ObjectType,
2938 NamedDecl *FirstQualifierInScope) {
Chris Lattner01cf8db2011-07-20 06:58:45 +00002939 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier1dcde962012-08-08 18:46:20 +00002940 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregor14454802011-02-25 02:25:35 +00002941 Qualifier = Qualifier.getPrefix())
2942 Qualifiers.push_back(Qualifier);
2943
2944 CXXScopeSpec SS;
2945 while (!Qualifiers.empty()) {
2946 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2947 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier1dcde962012-08-08 18:46:20 +00002948
Douglas Gregor14454802011-02-25 02:25:35 +00002949 switch (QNNS->getKind()) {
2950 case NestedNameSpecifier::Identifier:
Chad Rosier1dcde962012-08-08 18:46:20 +00002951 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
Douglas Gregor14454802011-02-25 02:25:35 +00002952 *QNNS->getAsIdentifier(),
Chad Rosier1dcde962012-08-08 18:46:20 +00002953 Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00002954 Q.getLocalEndLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00002955 ObjectType, false, SS,
Douglas Gregor14454802011-02-25 02:25:35 +00002956 FirstQualifierInScope, false))
2957 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00002958
Douglas Gregor14454802011-02-25 02:25:35 +00002959 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00002960
Douglas Gregor14454802011-02-25 02:25:35 +00002961 case NestedNameSpecifier::Namespace: {
2962 NamespaceDecl *NS
2963 = cast_or_null<NamespaceDecl>(
2964 getDerived().TransformDecl(
2965 Q.getLocalBeginLoc(),
2966 QNNS->getAsNamespace()));
2967 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2968 break;
2969 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002970
Douglas Gregor14454802011-02-25 02:25:35 +00002971 case NestedNameSpecifier::NamespaceAlias: {
2972 NamespaceAliasDecl *Alias
2973 = cast_or_null<NamespaceAliasDecl>(
2974 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2975 QNNS->getAsNamespaceAlias()));
Chad Rosier1dcde962012-08-08 18:46:20 +00002976 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00002977 Q.getLocalEndLoc());
2978 break;
2979 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002980
Douglas Gregor14454802011-02-25 02:25:35 +00002981 case NestedNameSpecifier::Global:
2982 // There is no meaningful transformation that one could perform on the
2983 // global scope.
2984 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2985 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00002986
Douglas Gregor14454802011-02-25 02:25:35 +00002987 case NestedNameSpecifier::TypeSpecWithTemplate:
2988 case NestedNameSpecifier::TypeSpec: {
2989 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2990 FirstQualifierInScope, SS);
Chad Rosier1dcde962012-08-08 18:46:20 +00002991
Douglas Gregor14454802011-02-25 02:25:35 +00002992 if (!TL)
2993 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00002994
Douglas Gregor14454802011-02-25 02:25:35 +00002995 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Richard Smith2bf7fdb2013-01-02 11:42:31 +00002996 (SemaRef.getLangOpts().CPlusPlus11 &&
Douglas Gregor14454802011-02-25 02:25:35 +00002997 TL.getType()->isEnumeralType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002998 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregor14454802011-02-25 02:25:35 +00002999 "Can't get cv-qualifiers here");
Richard Smith91c7bbd2011-10-20 03:28:47 +00003000 if (TL.getType()->isEnumeralType())
3001 SemaRef.Diag(TL.getBeginLoc(),
3002 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregor14454802011-02-25 02:25:35 +00003003 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
3004 Q.getLocalEndLoc());
3005 break;
3006 }
Richard Trieude756fb2011-05-07 01:36:37 +00003007 // If the nested-name-specifier is an invalid type def, don't emit an
3008 // error because a previous error should have already been emitted.
David Blaikie6adc78e2013-02-18 22:06:02 +00003009 TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
3010 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003011 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieude756fb2011-05-07 01:36:37 +00003012 << TL.getType() << SS.getRange();
3013 }
Douglas Gregor14454802011-02-25 02:25:35 +00003014 return NestedNameSpecifierLoc();
3015 }
Douglas Gregore16af532011-02-28 18:50:33 +00003016 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003017
Douglas Gregore16af532011-02-28 18:50:33 +00003018 // The qualifier-in-scope and object type only apply to the leftmost entity.
Douglas Gregor14454802011-02-25 02:25:35 +00003019 FirstQualifierInScope = 0;
Douglas Gregore16af532011-02-28 18:50:33 +00003020 ObjectType = QualType();
Douglas Gregor14454802011-02-25 02:25:35 +00003021 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003022
Douglas Gregor14454802011-02-25 02:25:35 +00003023 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier1dcde962012-08-08 18:46:20 +00003024 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003025 !getDerived().AlwaysRebuild())
3026 return NNS;
Chad Rosier1dcde962012-08-08 18:46:20 +00003027
3028 // If we can re-use the source-location data from the original
Douglas Gregor14454802011-02-25 02:25:35 +00003029 // nested-name-specifier, do so.
3030 if (SS.location_size() == NNS.getDataLength() &&
3031 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
3032 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
3033
3034 // Allocate new nested-name-specifier location information.
3035 return SS.getWithLocInContext(SemaRef.Context);
3036}
3037
3038template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003039DeclarationNameInfo
3040TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00003041::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003042 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003043 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003044 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003045
3046 switch (Name.getNameKind()) {
3047 case DeclarationName::Identifier:
3048 case DeclarationName::ObjCZeroArgSelector:
3049 case DeclarationName::ObjCOneArgSelector:
3050 case DeclarationName::ObjCMultiArgSelector:
3051 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00003052 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00003053 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003054 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00003055
Douglas Gregorf816bd72009-09-03 22:13:48 +00003056 case DeclarationName::CXXConstructorName:
3057 case DeclarationName::CXXDestructorName:
3058 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003059 TypeSourceInfo *NewTInfo;
3060 CanQualType NewCanTy;
3061 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00003062 NewTInfo = getDerived().TransformType(OldTInfo);
3063 if (!NewTInfo)
3064 return DeclarationNameInfo();
3065 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003066 }
3067 else {
3068 NewTInfo = 0;
3069 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00003070 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003071 if (NewT.isNull())
3072 return DeclarationNameInfo();
3073 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
3074 }
Mike Stump11289f42009-09-09 15:08:12 +00003075
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003076 DeclarationName NewName
3077 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
3078 NewCanTy);
3079 DeclarationNameInfo NewNameInfo(NameInfo);
3080 NewNameInfo.setName(NewName);
3081 NewNameInfo.setNamedTypeInfo(NewTInfo);
3082 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00003083 }
Mike Stump11289f42009-09-09 15:08:12 +00003084 }
3085
David Blaikie83d382b2011-09-23 05:06:16 +00003086 llvm_unreachable("Unknown name kind.");
Douglas Gregorf816bd72009-09-03 22:13:48 +00003087}
3088
3089template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003090TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00003091TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
3092 TemplateName Name,
3093 SourceLocation NameLoc,
3094 QualType ObjectType,
3095 NamedDecl *FirstQualifierInScope) {
3096 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
3097 TemplateDecl *Template = QTN->getTemplateDecl();
3098 assert(Template && "qualified template name must refer to a template");
Chad Rosier1dcde962012-08-08 18:46:20 +00003099
Douglas Gregor9db53502011-03-02 18:07:45 +00003100 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003101 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003102 Template));
3103 if (!TransTemplate)
3104 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003105
Douglas Gregor9db53502011-03-02 18:07:45 +00003106 if (!getDerived().AlwaysRebuild() &&
3107 SS.getScopeRep() == QTN->getQualifier() &&
3108 TransTemplate == Template)
3109 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003110
Douglas Gregor9db53502011-03-02 18:07:45 +00003111 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
3112 TransTemplate);
3113 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003114
Douglas Gregor9db53502011-03-02 18:07:45 +00003115 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
3116 if (SS.getScopeRep()) {
3117 // These apply to the scope specifier, not the template.
3118 ObjectType = QualType();
3119 FirstQualifierInScope = 0;
Chad Rosier1dcde962012-08-08 18:46:20 +00003120 }
3121
Douglas Gregor9db53502011-03-02 18:07:45 +00003122 if (!getDerived().AlwaysRebuild() &&
3123 SS.getScopeRep() == DTN->getQualifier() &&
3124 ObjectType.isNull())
3125 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003126
Douglas Gregor9db53502011-03-02 18:07:45 +00003127 if (DTN->isIdentifier()) {
3128 return getDerived().RebuildTemplateName(SS,
Chad Rosier1dcde962012-08-08 18:46:20 +00003129 *DTN->getIdentifier(),
Douglas Gregor9db53502011-03-02 18:07:45 +00003130 NameLoc,
3131 ObjectType,
3132 FirstQualifierInScope);
3133 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003134
Douglas Gregor9db53502011-03-02 18:07:45 +00003135 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
3136 ObjectType);
3137 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003138
Douglas Gregor9db53502011-03-02 18:07:45 +00003139 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
3140 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003141 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003142 Template));
3143 if (!TransTemplate)
3144 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003145
Douglas Gregor9db53502011-03-02 18:07:45 +00003146 if (!getDerived().AlwaysRebuild() &&
3147 TransTemplate == Template)
3148 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003149
Douglas Gregor9db53502011-03-02 18:07:45 +00003150 return TemplateName(TransTemplate);
3151 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003152
Douglas Gregor9db53502011-03-02 18:07:45 +00003153 if (SubstTemplateTemplateParmPackStorage *SubstPack
3154 = Name.getAsSubstTemplateTemplateParmPack()) {
3155 TemplateTemplateParmDecl *TransParam
3156 = cast_or_null<TemplateTemplateParmDecl>(
3157 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
3158 if (!TransParam)
3159 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003160
Douglas Gregor9db53502011-03-02 18:07:45 +00003161 if (!getDerived().AlwaysRebuild() &&
3162 TransParam == SubstPack->getParameterPack())
3163 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003164
3165 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregor9db53502011-03-02 18:07:45 +00003166 SubstPack->getArgumentPack());
3167 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003168
Douglas Gregor9db53502011-03-02 18:07:45 +00003169 // These should be getting filtered out before they reach the AST.
3170 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregor9db53502011-03-02 18:07:45 +00003171}
3172
3173template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003174void TreeTransform<Derived>::InventTemplateArgumentLoc(
3175 const TemplateArgument &Arg,
3176 TemplateArgumentLoc &Output) {
3177 SourceLocation Loc = getDerived().getBaseLocation();
3178 switch (Arg.getKind()) {
3179 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003180 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00003181 break;
3182
3183 case TemplateArgument::Type:
3184 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00003185 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier1dcde962012-08-08 18:46:20 +00003186
John McCall0ad16662009-10-29 08:12:44 +00003187 break;
3188
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003189 case TemplateArgument::Template:
Douglas Gregor9d802122011-03-02 17:09:35 +00003190 case TemplateArgument::TemplateExpansion: {
3191 NestedNameSpecifierLocBuilder Builder;
3192 TemplateName Template = Arg.getAsTemplate();
3193 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3194 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3195 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3196 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003197
Douglas Gregor9d802122011-03-02 17:09:35 +00003198 if (Arg.getKind() == TemplateArgument::Template)
Chad Rosier1dcde962012-08-08 18:46:20 +00003199 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003200 Builder.getWithLocInContext(SemaRef.Context),
3201 Loc);
3202 else
Chad Rosier1dcde962012-08-08 18:46:20 +00003203 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003204 Builder.getWithLocInContext(SemaRef.Context),
3205 Loc, Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003206
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003207 break;
Douglas Gregor9d802122011-03-02 17:09:35 +00003208 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003209
John McCall0ad16662009-10-29 08:12:44 +00003210 case TemplateArgument::Expression:
3211 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3212 break;
3213
3214 case TemplateArgument::Declaration:
3215 case TemplateArgument::Integral:
3216 case TemplateArgument::Pack:
Eli Friedmanb826a002012-09-26 02:36:12 +00003217 case TemplateArgument::NullPtr:
John McCall0d07eb32009-10-29 18:45:58 +00003218 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00003219 break;
3220 }
3221}
3222
3223template<typename Derived>
3224bool TreeTransform<Derived>::TransformTemplateArgument(
3225 const TemplateArgumentLoc &Input,
3226 TemplateArgumentLoc &Output) {
3227 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00003228 switch (Arg.getKind()) {
3229 case TemplateArgument::Null:
3230 case TemplateArgument::Integral:
Eli Friedmancda3db82012-09-25 01:02:42 +00003231 case TemplateArgument::Pack:
3232 case TemplateArgument::Declaration:
Eli Friedmanb826a002012-09-26 02:36:12 +00003233 case TemplateArgument::NullPtr:
3234 llvm_unreachable("Unexpected TemplateArgument");
Mike Stump11289f42009-09-09 15:08:12 +00003235
Douglas Gregore922c772009-08-04 22:27:00 +00003236 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00003237 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall0ad16662009-10-29 08:12:44 +00003238 if (DI == NULL)
John McCallbcd03502009-12-07 02:54:59 +00003239 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00003240
3241 DI = getDerived().TransformType(DI);
3242 if (!DI) return true;
3243
3244 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3245 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003246 }
Mike Stump11289f42009-09-09 15:08:12 +00003247
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003248 case TemplateArgument::Template: {
Douglas Gregor9d802122011-03-02 17:09:35 +00003249 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3250 if (QualifierLoc) {
3251 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3252 if (!QualifierLoc)
3253 return true;
3254 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003255
Douglas Gregordf846d12011-03-02 18:46:51 +00003256 CXXScopeSpec SS;
3257 SS.Adopt(QualifierLoc);
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003258 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00003259 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3260 Input.getTemplateNameLoc());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003261 if (Template.isNull())
3262 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003263
Douglas Gregor9d802122011-03-02 17:09:35 +00003264 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003265 Input.getTemplateNameLoc());
3266 return false;
3267 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003268
3269 case TemplateArgument::TemplateExpansion:
3270 llvm_unreachable("Caller should expand pack expansions");
3271
Douglas Gregore922c772009-08-04 22:27:00 +00003272 case TemplateArgument::Expression: {
Richard Smith764d2fe2011-12-20 02:08:33 +00003273 // Template argument expressions are constant expressions.
Mike Stump11289f42009-09-09 15:08:12 +00003274 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smith764d2fe2011-12-20 02:08:33 +00003275 Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003276
John McCall0ad16662009-10-29 08:12:44 +00003277 Expr *InputExpr = Input.getSourceExpression();
3278 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3279
Chris Lattnercdb591a2011-04-25 20:37:58 +00003280 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanc6237c62012-02-29 03:16:56 +00003281 E = SemaRef.ActOnConstantExpression(E);
John McCall0ad16662009-10-29 08:12:44 +00003282 if (E.isInvalid()) return true;
John McCallb268a282010-08-23 23:25:46 +00003283 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall0ad16662009-10-29 08:12:44 +00003284 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003285 }
Douglas Gregore922c772009-08-04 22:27:00 +00003286 }
Mike Stump11289f42009-09-09 15:08:12 +00003287
Douglas Gregore922c772009-08-04 22:27:00 +00003288 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00003289 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00003290}
3291
Douglas Gregorfe921a72010-12-20 23:36:19 +00003292/// \brief Iterator adaptor that invents template argument location information
3293/// for each of the template arguments in its underlying iterator.
3294template<typename Derived, typename InputIterator>
3295class TemplateArgumentLocInventIterator {
3296 TreeTransform<Derived> &Self;
3297 InputIterator Iter;
Chad Rosier1dcde962012-08-08 18:46:20 +00003298
Douglas Gregorfe921a72010-12-20 23:36:19 +00003299public:
3300 typedef TemplateArgumentLoc value_type;
3301 typedef TemplateArgumentLoc reference;
3302 typedef typename std::iterator_traits<InputIterator>::difference_type
3303 difference_type;
3304 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00003305
Douglas Gregorfe921a72010-12-20 23:36:19 +00003306 class pointer {
3307 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00003308
Douglas Gregorfe921a72010-12-20 23:36:19 +00003309 public:
3310 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003311
Douglas Gregorfe921a72010-12-20 23:36:19 +00003312 const TemplateArgumentLoc *operator->() const { return &Arg; }
3313 };
Chad Rosier1dcde962012-08-08 18:46:20 +00003314
Douglas Gregorfe921a72010-12-20 23:36:19 +00003315 TemplateArgumentLocInventIterator() { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003316
Douglas Gregorfe921a72010-12-20 23:36:19 +00003317 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3318 InputIterator Iter)
3319 : Self(Self), Iter(Iter) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003320
Douglas Gregorfe921a72010-12-20 23:36:19 +00003321 TemplateArgumentLocInventIterator &operator++() {
3322 ++Iter;
3323 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00003324 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003325
Douglas Gregorfe921a72010-12-20 23:36:19 +00003326 TemplateArgumentLocInventIterator operator++(int) {
3327 TemplateArgumentLocInventIterator Old(*this);
3328 ++(*this);
3329 return Old;
3330 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003331
Douglas Gregorfe921a72010-12-20 23:36:19 +00003332 reference operator*() const {
3333 TemplateArgumentLoc Result;
3334 Self.InventTemplateArgumentLoc(*Iter, Result);
3335 return Result;
3336 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003337
Douglas Gregorfe921a72010-12-20 23:36:19 +00003338 pointer operator->() const { return pointer(**this); }
Chad Rosier1dcde962012-08-08 18:46:20 +00003339
Douglas Gregorfe921a72010-12-20 23:36:19 +00003340 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3341 const TemplateArgumentLocInventIterator &Y) {
3342 return X.Iter == Y.Iter;
3343 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00003344
Douglas Gregorfe921a72010-12-20 23:36:19 +00003345 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3346 const TemplateArgumentLocInventIterator &Y) {
3347 return X.Iter != Y.Iter;
3348 }
3349};
Chad Rosier1dcde962012-08-08 18:46:20 +00003350
Douglas Gregor42cafa82010-12-20 17:42:22 +00003351template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00003352template<typename InputIterator>
3353bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3354 InputIterator Last,
Douglas Gregor42cafa82010-12-20 17:42:22 +00003355 TemplateArgumentListInfo &Outputs) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00003356 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00003357 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00003358 TemplateArgumentLoc In = *First;
Chad Rosier1dcde962012-08-08 18:46:20 +00003359
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003360 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3361 // Unpack argument packs, which we translate them into separate
3362 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00003363 // FIXME: We could do much better if we could guarantee that the
3364 // TemplateArgumentLocInfo for the pack expansion would be usable for
3365 // all of the template arguments in the argument pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00003366 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003367 TemplateArgument::pack_iterator>
3368 PackLocIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00003369 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003370 In.getArgument().pack_begin()),
3371 PackLocIterator(*this,
3372 In.getArgument().pack_end()),
3373 Outputs))
3374 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003375
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003376 continue;
3377 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003378
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003379 if (In.getArgument().isPackExpansion()) {
3380 // We have a pack expansion, for which we will be substituting into
3381 // the pattern.
3382 SourceLocation Ellipsis;
David Blaikie05785d12013-02-20 22:23:23 +00003383 Optional<unsigned> OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003384 TemplateArgumentLoc Pattern
Eli Friedman94e9eaa2013-06-20 04:11:21 +00003385 = getSema().getTemplateArgumentPackExpansionPattern(
3386 In, Ellipsis, OrigNumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00003387
Chris Lattner01cf8db2011-07-20 06:58:45 +00003388 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003389 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3390 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00003391
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003392 // Determine whether the set of unexpanded parameter packs can and should
3393 // be expanded.
3394 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003395 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00003396 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003397 if (getDerived().TryExpandParameterPacks(Ellipsis,
3398 Pattern.getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003399 Unexpanded,
Chad Rosier1dcde962012-08-08 18:46:20 +00003400 Expand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003401 RetainExpansion,
3402 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003403 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003404
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003405 if (!Expand) {
3406 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00003407 // transformation on the pack expansion, producing another pack
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003408 // expansion.
3409 TemplateArgumentLoc OutPattern;
3410 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3411 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3412 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003413
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003414 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3415 NumExpansions);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003416 if (Out.getArgument().isNull())
3417 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003418
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003419 Outputs.addArgument(Out);
3420 continue;
3421 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003422
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003423 // The transform has determined that we should perform an elementwise
3424 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003425 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003426 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3427
3428 if (getDerived().TransformTemplateArgument(Pattern, Out))
3429 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003430
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003431 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003432 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3433 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003434 if (Out.getArgument().isNull())
3435 return true;
3436 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003437
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003438 Outputs.addArgument(Out);
3439 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003440
Douglas Gregor48d24112011-01-10 20:53:55 +00003441 // If we're supposed to retain a pack expansion, do so by temporarily
3442 // forgetting the partially-substituted parameter pack.
3443 if (RetainExpansion) {
3444 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00003445
Douglas Gregor48d24112011-01-10 20:53:55 +00003446 if (getDerived().TransformTemplateArgument(Pattern, Out))
3447 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003448
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003449 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3450 OrigNumExpansions);
Douglas Gregor48d24112011-01-10 20:53:55 +00003451 if (Out.getArgument().isNull())
3452 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003453
Douglas Gregor48d24112011-01-10 20:53:55 +00003454 Outputs.addArgument(Out);
3455 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003456
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003457 continue;
3458 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003459
3460 // The simple case:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003461 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor42cafa82010-12-20 17:42:22 +00003462 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003463
Douglas Gregor42cafa82010-12-20 17:42:22 +00003464 Outputs.addArgument(Out);
3465 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003466
Douglas Gregor42cafa82010-12-20 17:42:22 +00003467 return false;
3468
3469}
3470
Douglas Gregord6ff3322009-08-04 16:50:30 +00003471//===----------------------------------------------------------------------===//
3472// Type transformation
3473//===----------------------------------------------------------------------===//
3474
3475template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003476QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00003477 if (getDerived().AlreadyTransformed(T))
3478 return T;
Mike Stump11289f42009-09-09 15:08:12 +00003479
John McCall550e0c22009-10-21 00:40:46 +00003480 // Temporary workaround. All of these transformations should
3481 // eventually turn into transformations on TypeLocs.
Douglas Gregor2d525f02011-01-25 19:13:18 +00003482 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3483 getDerived().getBaseLocation());
Chad Rosier1dcde962012-08-08 18:46:20 +00003484
John McCall31f82722010-11-12 08:19:04 +00003485 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00003486
John McCall550e0c22009-10-21 00:40:46 +00003487 if (!NewDI)
3488 return QualType();
3489
3490 return NewDI->getType();
3491}
3492
3493template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003494TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smith764d2fe2011-12-20 02:08:33 +00003495 // Refine the base location to the type's location.
3496 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3497 getDerived().getBaseEntity());
John McCall550e0c22009-10-21 00:40:46 +00003498 if (getDerived().AlreadyTransformed(DI->getType()))
3499 return DI;
3500
3501 TypeLocBuilder TLB;
3502
3503 TypeLoc TL = DI->getTypeLoc();
3504 TLB.reserve(TL.getFullDataSize());
3505
John McCall31f82722010-11-12 08:19:04 +00003506 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00003507 if (Result.isNull())
3508 return 0;
3509
John McCallbcd03502009-12-07 02:54:59 +00003510 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00003511}
3512
3513template<typename Derived>
3514QualType
John McCall31f82722010-11-12 08:19:04 +00003515TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003516 switch (T.getTypeLocClass()) {
3517#define ABSTRACT_TYPELOC(CLASS, PARENT)
David Blaikie6adc78e2013-02-18 22:06:02 +00003518#define TYPELOC(CLASS, PARENT) \
3519 case TypeLoc::CLASS: \
3520 return getDerived().Transform##CLASS##Type(TLB, \
3521 T.castAs<CLASS##TypeLoc>());
John McCall550e0c22009-10-21 00:40:46 +00003522#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00003523 }
Mike Stump11289f42009-09-09 15:08:12 +00003524
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003525 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00003526}
3527
3528/// FIXME: By default, this routine adds type qualifiers only to types
3529/// that can have qualifiers, and silently suppresses those qualifiers
3530/// that are not permitted (e.g., qualifiers on reference or function
3531/// types). This is the right thing for template instantiation, but
3532/// probably not for other clients.
3533template<typename Derived>
3534QualType
3535TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003536 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00003537 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00003538
John McCall31f82722010-11-12 08:19:04 +00003539 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00003540 if (Result.isNull())
3541 return QualType();
3542
3543 // Silently suppress qualifiers if the result type can't be qualified.
3544 // FIXME: this is the right thing for template instantiation, but
3545 // probably not for other clients.
3546 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00003547 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00003548
John McCall31168b02011-06-15 23:02:42 +00003549 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore46db902011-06-17 22:11:49 +00003550 // resulting type.
3551 if (Quals.hasObjCLifetime()) {
3552 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3553 Quals.removeObjCLifetime();
Douglas Gregord7357a92011-06-17 23:16:24 +00003554 else if (Result.getObjCLifetime()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003555 // Objective-C ARC:
Douglas Gregore46db902011-06-17 22:11:49 +00003556 // A lifetime qualifier applied to a substituted template parameter
3557 // overrides the lifetime qualifier from the template argument.
Douglas Gregorf4e43312013-01-17 23:59:28 +00003558 const AutoType *AutoTy;
Chad Rosier1dcde962012-08-08 18:46:20 +00003559 if (const SubstTemplateTypeParmType *SubstTypeParam
Douglas Gregore46db902011-06-17 22:11:49 +00003560 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3561 QualType Replacement = SubstTypeParam->getReplacementType();
3562 Qualifiers Qs = Replacement.getQualifiers();
3563 Qs.removeObjCLifetime();
Chad Rosier1dcde962012-08-08 18:46:20 +00003564 Replacement
Douglas Gregore46db902011-06-17 22:11:49 +00003565 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3566 Qs);
3567 Result = SemaRef.Context.getSubstTemplateTypeParmType(
Chad Rosier1dcde962012-08-08 18:46:20 +00003568 SubstTypeParam->getReplacedParameter(),
Douglas Gregore46db902011-06-17 22:11:49 +00003569 Replacement);
3570 TLB.TypeWasModifiedSafely(Result);
Douglas Gregorf4e43312013-01-17 23:59:28 +00003571 } else if ((AutoTy = dyn_cast<AutoType>(Result)) && AutoTy->isDeduced()) {
3572 // 'auto' types behave the same way as template parameters.
3573 QualType Deduced = AutoTy->getDeducedType();
3574 Qualifiers Qs = Deduced.getQualifiers();
3575 Qs.removeObjCLifetime();
3576 Deduced = SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(),
3577 Qs);
Faisal Vali2b391ab2013-09-26 19:54:12 +00003578 Result = SemaRef.Context.getAutoType(Deduced, AutoTy->isDecltypeAuto(),
3579 AutoTy->isDependentType());
Douglas Gregorf4e43312013-01-17 23:59:28 +00003580 TLB.TypeWasModifiedSafely(Result);
Douglas Gregore46db902011-06-17 22:11:49 +00003581 } else {
Douglas Gregord7357a92011-06-17 23:16:24 +00003582 // Otherwise, complain about the addition of a qualifier to an
3583 // already-qualified type.
Eli Friedman7152fbe2013-06-07 20:31:48 +00003584 SourceRange R = T.getUnqualifiedLoc().getSourceRange();
Argyrios Kyrtzidiscff00d92011-06-24 00:08:59 +00003585 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregord7357a92011-06-17 23:16:24 +00003586 << Result << R;
Chad Rosier1dcde962012-08-08 18:46:20 +00003587
Douglas Gregore46db902011-06-17 22:11:49 +00003588 Quals.removeObjCLifetime();
3589 }
3590 }
3591 }
John McCallcb0f89a2010-06-05 06:41:15 +00003592 if (!Quals.empty()) {
3593 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
Richard Smithdeec0742013-03-27 23:36:39 +00003594 // BuildQualifiedType might not add qualifiers if they are invalid.
3595 if (Result.hasLocalQualifiers())
3596 TLB.push<QualifiedTypeLoc>(Result);
John McCallcb0f89a2010-06-05 06:41:15 +00003597 // No location information to preserve.
3598 }
John McCall550e0c22009-10-21 00:40:46 +00003599
3600 return Result;
3601}
3602
Douglas Gregor14454802011-02-25 02:25:35 +00003603template<typename Derived>
3604TypeLoc
3605TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3606 QualType ObjectType,
3607 NamedDecl *UnqualLookup,
3608 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003609 if (getDerived().AlreadyTransformed(TL.getType()))
Douglas Gregor14454802011-02-25 02:25:35 +00003610 return TL;
Chad Rosier1dcde962012-08-08 18:46:20 +00003611
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003612 TypeSourceInfo *TSI =
3613 TransformTSIInObjectScope(TL, ObjectType, UnqualLookup, SS);
3614 if (TSI)
3615 return TSI->getTypeLoc();
3616 return TypeLoc();
Douglas Gregor14454802011-02-25 02:25:35 +00003617}
3618
Douglas Gregor579c15f2011-03-02 18:32:08 +00003619template<typename Derived>
3620TypeSourceInfo *
3621TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3622 QualType ObjectType,
3623 NamedDecl *UnqualLookup,
3624 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003625 if (getDerived().AlreadyTransformed(TSInfo->getType()))
Douglas Gregor579c15f2011-03-02 18:32:08 +00003626 return TSInfo;
Chad Rosier1dcde962012-08-08 18:46:20 +00003627
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003628 return TransformTSIInObjectScope(TSInfo->getTypeLoc(), ObjectType,
3629 UnqualLookup, SS);
3630}
3631
3632template <typename Derived>
3633TypeSourceInfo *TreeTransform<Derived>::TransformTSIInObjectScope(
3634 TypeLoc TL, QualType ObjectType, NamedDecl *UnqualLookup,
3635 CXXScopeSpec &SS) {
3636 QualType T = TL.getType();
3637 assert(!getDerived().AlreadyTransformed(T));
3638
Douglas Gregor579c15f2011-03-02 18:32:08 +00003639 TypeLocBuilder TLB;
3640 QualType Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00003641
Douglas Gregor579c15f2011-03-02 18:32:08 +00003642 if (isa<TemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00003643 TemplateSpecializationTypeLoc SpecTL =
3644 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00003645
Douglas Gregor579c15f2011-03-02 18:32:08 +00003646 TemplateName Template
3647 = getDerived().TransformTemplateName(SS,
3648 SpecTL.getTypePtr()->getTemplateName(),
3649 SpecTL.getTemplateNameLoc(),
3650 ObjectType, UnqualLookup);
Chad Rosier1dcde962012-08-08 18:46:20 +00003651 if (Template.isNull())
Douglas Gregor579c15f2011-03-02 18:32:08 +00003652 return 0;
Chad Rosier1dcde962012-08-08 18:46:20 +00003653
3654 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregor579c15f2011-03-02 18:32:08 +00003655 Template);
3656 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00003657 DependentTemplateSpecializationTypeLoc SpecTL =
3658 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00003659
Douglas Gregor579c15f2011-03-02 18:32:08 +00003660 TemplateName Template
Chad Rosier1dcde962012-08-08 18:46:20 +00003661 = getDerived().RebuildTemplateName(SS,
3662 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00003663 SpecTL.getTemplateNameLoc(),
Douglas Gregor579c15f2011-03-02 18:32:08 +00003664 ObjectType, UnqualLookup);
3665 if (Template.isNull())
3666 return 0;
Chad Rosier1dcde962012-08-08 18:46:20 +00003667
3668 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregor579c15f2011-03-02 18:32:08 +00003669 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00003670 Template,
3671 SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00003672 } else {
3673 // Nothing special needs to be done for these.
3674 Result = getDerived().TransformType(TLB, TL);
3675 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003676
3677 if (Result.isNull())
Douglas Gregor579c15f2011-03-02 18:32:08 +00003678 return 0;
Chad Rosier1dcde962012-08-08 18:46:20 +00003679
Douglas Gregor579c15f2011-03-02 18:32:08 +00003680 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3681}
3682
John McCall550e0c22009-10-21 00:40:46 +00003683template <class TyLoc> static inline
3684QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3685 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3686 NewT.setNameLoc(T.getNameLoc());
3687 return T.getType();
3688}
3689
John McCall550e0c22009-10-21 00:40:46 +00003690template<typename Derived>
3691QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003692 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00003693 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3694 NewT.setBuiltinLoc(T.getBuiltinLoc());
3695 if (T.needsExtraLocalData())
3696 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3697 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003698}
Mike Stump11289f42009-09-09 15:08:12 +00003699
Douglas Gregord6ff3322009-08-04 16:50:30 +00003700template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003701QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003702 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003703 // FIXME: recurse?
3704 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003705}
Mike Stump11289f42009-09-09 15:08:12 +00003706
Reid Kleckner0503a872013-12-05 01:23:43 +00003707template <typename Derived>
3708QualType TreeTransform<Derived>::TransformAdjustedType(TypeLocBuilder &TLB,
3709 AdjustedTypeLoc TL) {
3710 // Adjustments applied during transformation are handled elsewhere.
3711 return getDerived().TransformType(TLB, TL.getOriginalLoc());
3712}
3713
Douglas Gregord6ff3322009-08-04 16:50:30 +00003714template<typename Derived>
Reid Kleckner8a365022013-06-24 17:51:48 +00003715QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
3716 DecayedTypeLoc TL) {
3717 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
3718 if (OriginalType.isNull())
3719 return QualType();
3720
3721 QualType Result = TL.getType();
3722 if (getDerived().AlwaysRebuild() ||
3723 OriginalType != TL.getOriginalLoc().getType())
3724 Result = SemaRef.Context.getDecayedType(OriginalType);
3725 TLB.push<DecayedTypeLoc>(Result);
3726 // Nothing to set for DecayedTypeLoc.
3727 return Result;
3728}
3729
3730template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003731QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003732 PointerTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003733 QualType PointeeType
3734 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003735 if (PointeeType.isNull())
3736 return QualType();
3737
3738 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00003739 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003740 // A dependent pointer type 'T *' has is being transformed such
3741 // that an Objective-C class type is being replaced for 'T'. The
3742 // resulting pointer type is an ObjCObjectPointerType, not a
3743 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00003744 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier1dcde962012-08-08 18:46:20 +00003745
John McCall8b07ec22010-05-15 11:32:37 +00003746 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3747 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003748 return Result;
3749 }
John McCall31f82722010-11-12 08:19:04 +00003750
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003751 if (getDerived().AlwaysRebuild() ||
3752 PointeeType != TL.getPointeeLoc().getType()) {
3753 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3754 if (Result.isNull())
3755 return QualType();
3756 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003757
John McCall31168b02011-06-15 23:02:42 +00003758 // Objective-C ARC can add lifetime qualifiers to the type that we're
3759 // pointing to.
3760 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier1dcde962012-08-08 18:46:20 +00003761
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003762 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3763 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00003764 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003765}
Mike Stump11289f42009-09-09 15:08:12 +00003766
3767template<typename Derived>
3768QualType
John McCall550e0c22009-10-21 00:40:46 +00003769TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003770 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00003771 QualType PointeeType
Chad Rosier1dcde962012-08-08 18:46:20 +00003772 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3773 if (PointeeType.isNull())
3774 return QualType();
3775
3776 QualType Result = TL.getType();
3777 if (getDerived().AlwaysRebuild() ||
3778 PointeeType != TL.getPointeeLoc().getType()) {
3779 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00003780 TL.getSigilLoc());
3781 if (Result.isNull())
3782 return QualType();
3783 }
3784
Douglas Gregor049211a2010-04-22 16:50:51 +00003785 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00003786 NewT.setSigilLoc(TL.getSigilLoc());
3787 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003788}
3789
John McCall70dd5f62009-10-30 00:06:24 +00003790/// Transforms a reference type. Note that somewhat paradoxically we
3791/// don't care whether the type itself is an l-value type or an r-value
3792/// type; we only care if the type was *written* as an l-value type
3793/// or an r-value type.
3794template<typename Derived>
3795QualType
3796TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003797 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00003798 const ReferenceType *T = TL.getTypePtr();
3799
3800 // Note that this works with the pointee-as-written.
3801 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3802 if (PointeeType.isNull())
3803 return QualType();
3804
3805 QualType Result = TL.getType();
3806 if (getDerived().AlwaysRebuild() ||
3807 PointeeType != T->getPointeeTypeAsWritten()) {
3808 Result = getDerived().RebuildReferenceType(PointeeType,
3809 T->isSpelledAsLValue(),
3810 TL.getSigilLoc());
3811 if (Result.isNull())
3812 return QualType();
3813 }
3814
John McCall31168b02011-06-15 23:02:42 +00003815 // Objective-C ARC can add lifetime qualifiers to the type that we're
3816 // referring to.
3817 TLB.TypeWasModifiedSafely(
3818 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3819
John McCall70dd5f62009-10-30 00:06:24 +00003820 // r-value references can be rebuilt as l-value references.
3821 ReferenceTypeLoc NewTL;
3822 if (isa<LValueReferenceType>(Result))
3823 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3824 else
3825 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3826 NewTL.setSigilLoc(TL.getSigilLoc());
3827
3828 return Result;
3829}
3830
Mike Stump11289f42009-09-09 15:08:12 +00003831template<typename Derived>
3832QualType
John McCall550e0c22009-10-21 00:40:46 +00003833TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003834 LValueReferenceTypeLoc TL) {
3835 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003836}
3837
Mike Stump11289f42009-09-09 15:08:12 +00003838template<typename Derived>
3839QualType
John McCall550e0c22009-10-21 00:40:46 +00003840TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003841 RValueReferenceTypeLoc TL) {
3842 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003843}
Mike Stump11289f42009-09-09 15:08:12 +00003844
Douglas Gregord6ff3322009-08-04 16:50:30 +00003845template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003846QualType
John McCall550e0c22009-10-21 00:40:46 +00003847TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003848 MemberPointerTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003849 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003850 if (PointeeType.isNull())
3851 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003852
Abramo Bagnara509357842011-03-05 14:42:21 +00003853 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
3854 TypeSourceInfo* NewClsTInfo = 0;
3855 if (OldClsTInfo) {
3856 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3857 if (!NewClsTInfo)
3858 return QualType();
3859 }
3860
3861 const MemberPointerType *T = TL.getTypePtr();
3862 QualType OldClsType = QualType(T->getClass(), 0);
3863 QualType NewClsType;
3864 if (NewClsTInfo)
3865 NewClsType = NewClsTInfo->getType();
3866 else {
3867 NewClsType = getDerived().TransformType(OldClsType);
3868 if (NewClsType.isNull())
3869 return QualType();
3870 }
Mike Stump11289f42009-09-09 15:08:12 +00003871
John McCall550e0c22009-10-21 00:40:46 +00003872 QualType Result = TL.getType();
3873 if (getDerived().AlwaysRebuild() ||
3874 PointeeType != T->getPointeeType() ||
Abramo Bagnara509357842011-03-05 14:42:21 +00003875 NewClsType != OldClsType) {
3876 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall70dd5f62009-10-30 00:06:24 +00003877 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00003878 if (Result.isNull())
3879 return QualType();
3880 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00003881
Reid Kleckner0503a872013-12-05 01:23:43 +00003882 // If we had to adjust the pointee type when building a member pointer, make
3883 // sure to push TypeLoc info for it.
3884 const MemberPointerType *MPT = Result->getAs<MemberPointerType>();
3885 if (MPT && PointeeType != MPT->getPointeeType()) {
3886 assert(isa<AdjustedType>(MPT->getPointeeType()));
3887 TLB.push<AdjustedTypeLoc>(MPT->getPointeeType());
3888 }
3889
John McCall550e0c22009-10-21 00:40:46 +00003890 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3891 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnara509357842011-03-05 14:42:21 +00003892 NewTL.setClassTInfo(NewClsTInfo);
John McCall550e0c22009-10-21 00:40:46 +00003893
3894 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003895}
3896
Mike Stump11289f42009-09-09 15:08:12 +00003897template<typename Derived>
3898QualType
John McCall550e0c22009-10-21 00:40:46 +00003899TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003900 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003901 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003902 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003903 if (ElementType.isNull())
3904 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003905
John McCall550e0c22009-10-21 00:40:46 +00003906 QualType Result = TL.getType();
3907 if (getDerived().AlwaysRebuild() ||
3908 ElementType != T->getElementType()) {
3909 Result = getDerived().RebuildConstantArrayType(ElementType,
3910 T->getSizeModifier(),
3911 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00003912 T->getIndexTypeCVRQualifiers(),
3913 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003914 if (Result.isNull())
3915 return QualType();
3916 }
Eli Friedmanf7f102f2012-01-25 22:19:07 +00003917
3918 // We might have either a ConstantArrayType or a VariableArrayType now:
3919 // a ConstantArrayType is allowed to have an element type which is a
3920 // VariableArrayType if the type is dependent. Fortunately, all array
3921 // types have the same location layout.
3922 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00003923 NewTL.setLBracketLoc(TL.getLBracketLoc());
3924 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00003925
John McCall550e0c22009-10-21 00:40:46 +00003926 Expr *Size = TL.getSizeExpr();
3927 if (Size) {
Richard Smith764d2fe2011-12-20 02:08:33 +00003928 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3929 Sema::ConstantEvaluated);
John McCall550e0c22009-10-21 00:40:46 +00003930 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
Eli Friedmanc6237c62012-02-29 03:16:56 +00003931 Size = SemaRef.ActOnConstantExpression(Size).take();
John McCall550e0c22009-10-21 00:40:46 +00003932 }
3933 NewTL.setSizeExpr(Size);
3934
3935 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003936}
Mike Stump11289f42009-09-09 15:08:12 +00003937
Douglas Gregord6ff3322009-08-04 16:50:30 +00003938template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003939QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00003940 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003941 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003942 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003943 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003944 if (ElementType.isNull())
3945 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003946
John McCall550e0c22009-10-21 00:40:46 +00003947 QualType Result = TL.getType();
3948 if (getDerived().AlwaysRebuild() ||
3949 ElementType != T->getElementType()) {
3950 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00003951 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00003952 T->getIndexTypeCVRQualifiers(),
3953 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003954 if (Result.isNull())
3955 return QualType();
3956 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003957
John McCall550e0c22009-10-21 00:40:46 +00003958 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3959 NewTL.setLBracketLoc(TL.getLBracketLoc());
3960 NewTL.setRBracketLoc(TL.getRBracketLoc());
3961 NewTL.setSizeExpr(0);
3962
3963 return Result;
3964}
3965
3966template<typename Derived>
3967QualType
3968TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003969 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003970 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003971 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3972 if (ElementType.isNull())
3973 return QualType();
3974
John McCalldadc5752010-08-24 06:29:42 +00003975 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00003976 = getDerived().TransformExpr(T->getSizeExpr());
3977 if (SizeResult.isInvalid())
3978 return QualType();
3979
John McCallb268a282010-08-23 23:25:46 +00003980 Expr *Size = SizeResult.take();
John McCall550e0c22009-10-21 00:40:46 +00003981
3982 QualType Result = TL.getType();
3983 if (getDerived().AlwaysRebuild() ||
3984 ElementType != T->getElementType() ||
3985 Size != T->getSizeExpr()) {
3986 Result = getDerived().RebuildVariableArrayType(ElementType,
3987 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00003988 Size,
John McCall550e0c22009-10-21 00:40:46 +00003989 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00003990 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003991 if (Result.isNull())
3992 return QualType();
3993 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003994
Serge Pavlov774c6d02014-02-06 03:49:11 +00003995 // We might have constant size array now, but fortunately it has the same
3996 // location layout.
3997 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00003998 NewTL.setLBracketLoc(TL.getLBracketLoc());
3999 NewTL.setRBracketLoc(TL.getRBracketLoc());
4000 NewTL.setSizeExpr(Size);
4001
4002 return Result;
4003}
4004
4005template<typename Derived>
4006QualType
4007TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004008 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004009 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004010 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4011 if (ElementType.isNull())
4012 return QualType();
4013
Richard Smith764d2fe2011-12-20 02:08:33 +00004014 // Array bounds are constant expressions.
4015 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4016 Sema::ConstantEvaluated);
John McCall550e0c22009-10-21 00:40:46 +00004017
John McCall33ddac02011-01-19 10:06:00 +00004018 // Prefer the expression from the TypeLoc; the other may have been uniqued.
4019 Expr *origSize = TL.getSizeExpr();
4020 if (!origSize) origSize = T->getSizeExpr();
4021
4022 ExprResult sizeResult
4023 = getDerived().TransformExpr(origSize);
Eli Friedmanc6237c62012-02-29 03:16:56 +00004024 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall33ddac02011-01-19 10:06:00 +00004025 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00004026 return QualType();
4027
John McCall33ddac02011-01-19 10:06:00 +00004028 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004029
4030 QualType Result = TL.getType();
4031 if (getDerived().AlwaysRebuild() ||
4032 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00004033 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00004034 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
4035 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00004036 size,
John McCall550e0c22009-10-21 00:40:46 +00004037 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004038 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004039 if (Result.isNull())
4040 return QualType();
4041 }
John McCall550e0c22009-10-21 00:40:46 +00004042
4043 // We might have any sort of array type now, but fortunately they
4044 // all have the same location layout.
4045 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4046 NewTL.setLBracketLoc(TL.getLBracketLoc());
4047 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00004048 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00004049
4050 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004051}
Mike Stump11289f42009-09-09 15:08:12 +00004052
4053template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004054QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00004055 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004056 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004057 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004058
4059 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00004060 QualType ElementType = getDerived().TransformType(T->getElementType());
4061 if (ElementType.isNull())
4062 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004063
Richard Smith764d2fe2011-12-20 02:08:33 +00004064 // Vector sizes are constant expressions.
4065 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4066 Sema::ConstantEvaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00004067
John McCalldadc5752010-08-24 06:29:42 +00004068 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanc6237c62012-02-29 03:16:56 +00004069 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004070 if (Size.isInvalid())
4071 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004072
John McCall550e0c22009-10-21 00:40:46 +00004073 QualType Result = TL.getType();
4074 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00004075 ElementType != T->getElementType() ||
4076 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00004077 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCallb268a282010-08-23 23:25:46 +00004078 Size.take(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00004079 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00004080 if (Result.isNull())
4081 return QualType();
4082 }
John McCall550e0c22009-10-21 00:40:46 +00004083
4084 // Result might be dependent or not.
4085 if (isa<DependentSizedExtVectorType>(Result)) {
4086 DependentSizedExtVectorTypeLoc NewTL
4087 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
4088 NewTL.setNameLoc(TL.getNameLoc());
4089 } else {
4090 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4091 NewTL.setNameLoc(TL.getNameLoc());
4092 }
4093
4094 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004095}
Mike Stump11289f42009-09-09 15:08:12 +00004096
4097template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004098QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004099 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004100 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004101 QualType ElementType = getDerived().TransformType(T->getElementType());
4102 if (ElementType.isNull())
4103 return QualType();
4104
John McCall550e0c22009-10-21 00:40:46 +00004105 QualType Result = TL.getType();
4106 if (getDerived().AlwaysRebuild() ||
4107 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00004108 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00004109 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00004110 if (Result.isNull())
4111 return QualType();
4112 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004113
John McCall550e0c22009-10-21 00:40:46 +00004114 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
4115 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004116
John McCall550e0c22009-10-21 00:40:46 +00004117 return Result;
4118}
4119
4120template<typename Derived>
4121QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004122 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004123 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004124 QualType ElementType = getDerived().TransformType(T->getElementType());
4125 if (ElementType.isNull())
4126 return QualType();
4127
4128 QualType Result = TL.getType();
4129 if (getDerived().AlwaysRebuild() ||
4130 ElementType != T->getElementType()) {
4131 Result = getDerived().RebuildExtVectorType(ElementType,
4132 T->getNumElements(),
4133 /*FIXME*/ SourceLocation());
4134 if (Result.isNull())
4135 return QualType();
4136 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004137
John McCall550e0c22009-10-21 00:40:46 +00004138 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4139 NewTL.setNameLoc(TL.getNameLoc());
4140
4141 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004142}
Mike Stump11289f42009-09-09 15:08:12 +00004143
David Blaikie05785d12013-02-20 22:23:23 +00004144template <typename Derived>
4145ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
4146 ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
4147 bool ExpectParameterPack) {
John McCall58f10c32010-03-11 09:03:00 +00004148 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor715e4612011-01-14 22:40:04 +00004149 TypeSourceInfo *NewDI = 0;
Chad Rosier1dcde962012-08-08 18:46:20 +00004150
Douglas Gregor715e4612011-01-14 22:40:04 +00004151 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004152 // If we're substituting into a pack expansion type and we know the
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004153 // length we want to expand to, just substitute for the pattern.
Douglas Gregor715e4612011-01-14 22:40:04 +00004154 TypeLoc OldTL = OldDI->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004155 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004156
Douglas Gregor715e4612011-01-14 22:40:04 +00004157 TypeLocBuilder TLB;
4158 TypeLoc NewTL = OldDI->getTypeLoc();
4159 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00004160
4161 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor715e4612011-01-14 22:40:04 +00004162 OldExpansionTL.getPatternLoc());
4163 if (Result.isNull())
4164 return 0;
Chad Rosier1dcde962012-08-08 18:46:20 +00004165
4166 Result = RebuildPackExpansionType(Result,
4167 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor715e4612011-01-14 22:40:04 +00004168 OldExpansionTL.getEllipsisLoc(),
4169 NumExpansions);
4170 if (Result.isNull())
4171 return 0;
Chad Rosier1dcde962012-08-08 18:46:20 +00004172
Douglas Gregor715e4612011-01-14 22:40:04 +00004173 PackExpansionTypeLoc NewExpansionTL
4174 = TLB.push<PackExpansionTypeLoc>(Result);
4175 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
4176 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
4177 } else
4178 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00004179 if (!NewDI)
4180 return 0;
4181
John McCall8fb0d9d2011-05-01 22:35:37 +00004182 if (NewDI == OldDI && indexAdjustment == 0)
John McCall58f10c32010-03-11 09:03:00 +00004183 return OldParm;
John McCall8fb0d9d2011-05-01 22:35:37 +00004184
4185 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
4186 OldParm->getDeclContext(),
4187 OldParm->getInnerLocStart(),
4188 OldParm->getLocation(),
4189 OldParm->getIdentifier(),
4190 NewDI->getType(),
4191 NewDI,
4192 OldParm->getStorageClass(),
John McCall8fb0d9d2011-05-01 22:35:37 +00004193 /* DefArg */ NULL);
4194 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
4195 OldParm->getFunctionScopeIndex() + indexAdjustment);
4196 return newParm;
John McCall58f10c32010-03-11 09:03:00 +00004197}
4198
4199template<typename Derived>
4200bool TreeTransform<Derived>::
Douglas Gregordd472162011-01-07 00:20:55 +00004201 TransformFunctionTypeParams(SourceLocation Loc,
4202 ParmVarDecl **Params, unsigned NumParams,
4203 const QualType *ParamTypes,
Chris Lattner01cf8db2011-07-20 06:58:45 +00004204 SmallVectorImpl<QualType> &OutParamTypes,
4205 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004206 int indexAdjustment = 0;
4207
Douglas Gregordd472162011-01-07 00:20:55 +00004208 for (unsigned i = 0; i != NumParams; ++i) {
4209 if (ParmVarDecl *OldParm = Params[i]) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004210 assert(OldParm->getFunctionScopeIndex() == i);
4211
David Blaikie05785d12013-02-20 22:23:23 +00004212 Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004213 ParmVarDecl *NewParm = 0;
Douglas Gregor5499af42011-01-05 23:12:31 +00004214 if (OldParm->isParameterPack()) {
4215 // We have a function parameter pack that may need to be expanded.
Chris Lattner01cf8db2011-07-20 06:58:45 +00004216 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00004217
Douglas Gregor5499af42011-01-05 23:12:31 +00004218 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004219 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004220 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004221 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4222 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004223 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4224
Douglas Gregor5499af42011-01-05 23:12:31 +00004225 // Determine whether we should expand the parameter packs.
4226 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004227 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004228 Optional<unsigned> OrigNumExpansions =
4229 ExpansionTL.getTypePtr()->getNumExpansions();
Douglas Gregor715e4612011-01-14 22:40:04 +00004230 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004231 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4232 Pattern.getSourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004233 Unexpanded,
4234 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004235 RetainExpansion,
4236 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004237 return true;
4238 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004239
Douglas Gregor5499af42011-01-05 23:12:31 +00004240 if (ShouldExpand) {
4241 // Expand the function parameter pack into multiple, separate
4242 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00004243 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004244 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004245 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier1dcde962012-08-08 18:46:20 +00004246 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004247 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004248 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004249 OrigNumExpansions,
4250 /*ExpectParameterPack=*/false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004251 if (!NewParm)
4252 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004253
Douglas Gregordd472162011-01-07 00:20:55 +00004254 OutParamTypes.push_back(NewParm->getType());
4255 if (PVars)
4256 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004257 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004258
4259 // If we're supposed to retain a pack expansion, do so by temporarily
4260 // forgetting the partially-substituted parameter pack.
4261 if (RetainExpansion) {
4262 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00004263 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004264 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004265 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004266 OrigNumExpansions,
4267 /*ExpectParameterPack=*/false);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004268 if (!NewParm)
4269 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004270
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004271 OutParamTypes.push_back(NewParm->getType());
4272 if (PVars)
4273 PVars->push_back(NewParm);
4274 }
4275
John McCall8fb0d9d2011-05-01 22:35:37 +00004276 // The next parameter should have the same adjustment as the
4277 // last thing we pushed, but we post-incremented indexAdjustment
4278 // on every push. Also, if we push nothing, the adjustment should
4279 // go down by one.
4280 indexAdjustment--;
4281
Douglas Gregor5499af42011-01-05 23:12:31 +00004282 // We're done with the pack expansion.
4283 continue;
4284 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004285
4286 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004287 // expansion.
Douglas Gregorc52264e2011-03-02 02:04:06 +00004288 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4289 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004290 indexAdjustment,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004291 NumExpansions,
4292 /*ExpectParameterPack=*/true);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004293 } else {
David Blaikie05785d12013-02-20 22:23:23 +00004294 NewParm = getDerived().TransformFunctionTypeParam(
David Blaikie7a30dc52013-02-21 01:47:18 +00004295 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004296 }
Douglas Gregorc52264e2011-03-02 02:04:06 +00004297
John McCall58f10c32010-03-11 09:03:00 +00004298 if (!NewParm)
4299 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004300
Douglas Gregordd472162011-01-07 00:20:55 +00004301 OutParamTypes.push_back(NewParm->getType());
4302 if (PVars)
4303 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004304 continue;
4305 }
John McCall58f10c32010-03-11 09:03:00 +00004306
4307 // Deal with the possibility that we don't have a parameter
4308 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00004309 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00004310 bool IsPackExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004311 Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004312 QualType NewType;
Chad Rosier1dcde962012-08-08 18:46:20 +00004313 if (const PackExpansionType *Expansion
Douglas Gregor5499af42011-01-05 23:12:31 +00004314 = dyn_cast<PackExpansionType>(OldType)) {
4315 // We have a function parameter pack that may need to be expanded.
4316 QualType Pattern = Expansion->getPattern();
Chris Lattner01cf8db2011-07-20 06:58:45 +00004317 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor5499af42011-01-05 23:12:31 +00004318 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00004319
Douglas Gregor5499af42011-01-05 23:12:31 +00004320 // Determine whether we should expand the parameter packs.
4321 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004322 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00004323 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004324 Unexpanded,
4325 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004326 RetainExpansion,
4327 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00004328 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00004329 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004330
Douglas Gregor5499af42011-01-05 23:12:31 +00004331 if (ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004332 // Expand the function parameter pack into multiple, separate
Douglas Gregor5499af42011-01-05 23:12:31 +00004333 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004334 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004335 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4336 QualType NewType = getDerived().TransformType(Pattern);
4337 if (NewType.isNull())
4338 return true;
John McCall58f10c32010-03-11 09:03:00 +00004339
Douglas Gregordd472162011-01-07 00:20:55 +00004340 OutParamTypes.push_back(NewType);
4341 if (PVars)
4342 PVars->push_back(0);
Douglas Gregor5499af42011-01-05 23:12:31 +00004343 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004344
Douglas Gregor5499af42011-01-05 23:12:31 +00004345 // We're done with the pack expansion.
4346 continue;
4347 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004348
Douglas Gregor48d24112011-01-10 20:53:55 +00004349 // If we're supposed to retain a pack expansion, do so by temporarily
4350 // forgetting the partially-substituted parameter pack.
4351 if (RetainExpansion) {
4352 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4353 QualType NewType = getDerived().TransformType(Pattern);
4354 if (NewType.isNull())
4355 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004356
Douglas Gregor48d24112011-01-10 20:53:55 +00004357 OutParamTypes.push_back(NewType);
4358 if (PVars)
4359 PVars->push_back(0);
4360 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004361
Chad Rosier1dcde962012-08-08 18:46:20 +00004362 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004363 // expansion.
4364 OldType = Expansion->getPattern();
4365 IsPackExpansion = true;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004366 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4367 NewType = getDerived().TransformType(OldType);
4368 } else {
4369 NewType = getDerived().TransformType(OldType);
Douglas Gregor5499af42011-01-05 23:12:31 +00004370 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004371
Douglas Gregor5499af42011-01-05 23:12:31 +00004372 if (NewType.isNull())
4373 return true;
4374
4375 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004376 NewType = getSema().Context.getPackExpansionType(NewType,
4377 NumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00004378
Douglas Gregordd472162011-01-07 00:20:55 +00004379 OutParamTypes.push_back(NewType);
4380 if (PVars)
4381 PVars->push_back(0);
John McCall58f10c32010-03-11 09:03:00 +00004382 }
4383
John McCall8fb0d9d2011-05-01 22:35:37 +00004384#ifndef NDEBUG
4385 if (PVars) {
4386 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4387 if (ParmVarDecl *parm = (*PVars)[i])
4388 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor5499af42011-01-05 23:12:31 +00004389 }
John McCall8fb0d9d2011-05-01 22:35:37 +00004390#endif
4391
4392 return false;
4393}
John McCall58f10c32010-03-11 09:03:00 +00004394
4395template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004396QualType
John McCall550e0c22009-10-21 00:40:46 +00004397TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004398 FunctionProtoTypeLoc TL) {
Douglas Gregor3024f072012-04-16 07:05:22 +00004399 return getDerived().TransformFunctionProtoType(TLB, TL, 0, 0);
4400}
4401
4402template<typename Derived>
4403QualType
4404TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
4405 FunctionProtoTypeLoc TL,
4406 CXXRecordDecl *ThisContext,
4407 unsigned ThisTypeQuals) {
Douglas Gregor4afc2362010-08-31 00:26:14 +00004408 // Transform the parameters and return type.
4409 //
Richard Smithf623c962012-04-17 00:58:00 +00004410 // We are required to instantiate the params and return type in source order.
Douglas Gregor7fb25412010-10-01 18:44:50 +00004411 // When the function has a trailing return type, we instantiate the
4412 // parameters before the return type, since the return type can then refer
4413 // to the parameters themselves (via decltype, sizeof, etc.).
4414 //
Chris Lattner01cf8db2011-07-20 06:58:45 +00004415 SmallVector<QualType, 4> ParamTypes;
4416 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall424cec92011-01-19 06:33:43 +00004417 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00004418
Douglas Gregor7fb25412010-10-01 18:44:50 +00004419 QualType ResultType;
4420
Richard Smith1226c602012-08-14 22:51:13 +00004421 if (T->hasTrailingReturn()) {
Alp Toker9cacbab2014-01-20 20:26:09 +00004422 if (getDerived().TransformFunctionTypeParams(
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004423 TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(),
Alp Toker9cacbab2014-01-20 20:26:09 +00004424 TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004425 return QualType();
4426
Douglas Gregor3024f072012-04-16 07:05:22 +00004427 {
4428 // C++11 [expr.prim.general]p3:
Chad Rosier1dcde962012-08-08 18:46:20 +00004429 // If a declaration declares a member function or member function
4430 // template of a class X, the expression this is a prvalue of type
Douglas Gregor3024f072012-04-16 07:05:22 +00004431 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier1dcde962012-08-08 18:46:20 +00004432 // and the end of the function-definition, member-declarator, or
Douglas Gregor3024f072012-04-16 07:05:22 +00004433 // declarator.
4434 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier1dcde962012-08-08 18:46:20 +00004435
Alp Toker42a16a62014-01-25 23:51:36 +00004436 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor3024f072012-04-16 07:05:22 +00004437 if (ResultType.isNull())
4438 return QualType();
4439 }
Douglas Gregor7fb25412010-10-01 18:44:50 +00004440 }
4441 else {
Alp Toker42a16a62014-01-25 23:51:36 +00004442 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00004443 if (ResultType.isNull())
4444 return QualType();
4445
Alp Toker9cacbab2014-01-20 20:26:09 +00004446 if (getDerived().TransformFunctionTypeParams(
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004447 TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(),
Alp Toker9cacbab2014-01-20 20:26:09 +00004448 TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004449 return QualType();
4450 }
4451
Richard Smithf623c962012-04-17 00:58:00 +00004452 // FIXME: Need to transform the exception-specification too.
4453
John McCall550e0c22009-10-21 00:40:46 +00004454 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00004455 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() ||
Alp Toker9cacbab2014-01-20 20:26:09 +00004456 T->getNumParams() != ParamTypes.size() ||
4457 !std::equal(T->param_type_begin(), T->param_type_end(),
4458 ParamTypes.begin())) {
Jordan Rose5c382722013-03-08 21:51:21 +00004459 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +00004460 T->getExtProtoInfo());
John McCall550e0c22009-10-21 00:40:46 +00004461 if (Result.isNull())
4462 return QualType();
4463 }
Mike Stump11289f42009-09-09 15:08:12 +00004464
John McCall550e0c22009-10-21 00:40:46 +00004465 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004466 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00004467 NewTL.setLParenLoc(TL.getLParenLoc());
4468 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004469 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004470 for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i)
4471 NewTL.setParam(i, ParamDecls[i]);
John McCall550e0c22009-10-21 00:40:46 +00004472
4473 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004474}
Mike Stump11289f42009-09-09 15:08:12 +00004475
Douglas Gregord6ff3322009-08-04 16:50:30 +00004476template<typename Derived>
4477QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00004478 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004479 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004480 const FunctionNoProtoType *T = TL.getTypePtr();
Alp Toker42a16a62014-01-25 23:51:36 +00004481 QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
John McCall550e0c22009-10-21 00:40:46 +00004482 if (ResultType.isNull())
4483 return QualType();
4484
4485 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00004486 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType())
John McCall550e0c22009-10-21 00:40:46 +00004487 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4488
4489 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004490 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00004491 NewTL.setLParenLoc(TL.getLParenLoc());
4492 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004493 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCall550e0c22009-10-21 00:40:46 +00004494
4495 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004496}
Mike Stump11289f42009-09-09 15:08:12 +00004497
John McCallb96ec562009-12-04 22:46:56 +00004498template<typename Derived> QualType
4499TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004500 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004501 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004502 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00004503 if (!D)
4504 return QualType();
4505
4506 QualType Result = TL.getType();
4507 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4508 Result = getDerived().RebuildUnresolvedUsingType(D);
4509 if (Result.isNull())
4510 return QualType();
4511 }
4512
4513 // We might get an arbitrary type spec type back. We should at
4514 // least always get a type spec type, though.
4515 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4516 NewTL.setNameLoc(TL.getNameLoc());
4517
4518 return Result;
4519}
4520
Douglas Gregord6ff3322009-08-04 16:50:30 +00004521template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004522QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004523 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004524 const TypedefType *T = TL.getTypePtr();
Richard Smithdda56e42011-04-15 14:24:37 +00004525 TypedefNameDecl *Typedef
4526 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4527 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004528 if (!Typedef)
4529 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004530
John McCall550e0c22009-10-21 00:40:46 +00004531 QualType Result = TL.getType();
4532 if (getDerived().AlwaysRebuild() ||
4533 Typedef != T->getDecl()) {
4534 Result = getDerived().RebuildTypedefType(Typedef);
4535 if (Result.isNull())
4536 return QualType();
4537 }
Mike Stump11289f42009-09-09 15:08:12 +00004538
John McCall550e0c22009-10-21 00:40:46 +00004539 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4540 NewTL.setNameLoc(TL.getNameLoc());
4541
4542 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004543}
Mike Stump11289f42009-09-09 15:08:12 +00004544
Douglas Gregord6ff3322009-08-04 16:50:30 +00004545template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004546QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004547 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00004548 // typeof expressions are not potentially evaluated contexts
Eli Friedman15681d62012-09-26 04:34:21 +00004549 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4550 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00004551
John McCalldadc5752010-08-24 06:29:42 +00004552 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004553 if (E.isInvalid())
4554 return QualType();
4555
Eli Friedmane4f22df2012-02-29 04:03:55 +00004556 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
4557 if (E.isInvalid())
4558 return QualType();
4559
John McCall550e0c22009-10-21 00:40:46 +00004560 QualType Result = TL.getType();
4561 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00004562 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004563 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00004564 if (Result.isNull())
4565 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004566 }
John McCall550e0c22009-10-21 00:40:46 +00004567 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00004568
John McCall550e0c22009-10-21 00:40:46 +00004569 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004570 NewTL.setTypeofLoc(TL.getTypeofLoc());
4571 NewTL.setLParenLoc(TL.getLParenLoc());
4572 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00004573
4574 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004575}
Mike Stump11289f42009-09-09 15:08:12 +00004576
4577template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004578QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004579 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00004580 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4581 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4582 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00004583 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004584
John McCall550e0c22009-10-21 00:40:46 +00004585 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00004586 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4587 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00004588 if (Result.isNull())
4589 return QualType();
4590 }
Mike Stump11289f42009-09-09 15:08:12 +00004591
John McCall550e0c22009-10-21 00:40:46 +00004592 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004593 NewTL.setTypeofLoc(TL.getTypeofLoc());
4594 NewTL.setLParenLoc(TL.getLParenLoc());
4595 NewTL.setRParenLoc(TL.getRParenLoc());
4596 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00004597
4598 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004599}
Mike Stump11289f42009-09-09 15:08:12 +00004600
4601template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004602QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004603 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004604 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004605
Douglas Gregore922c772009-08-04 22:27:00 +00004606 // decltype expressions are not potentially evaluated contexts
Richard Smithfd555f62012-02-22 02:04:18 +00004607 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, 0,
4608 /*IsDecltype=*/ true);
Mike Stump11289f42009-09-09 15:08:12 +00004609
John McCalldadc5752010-08-24 06:29:42 +00004610 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004611 if (E.isInvalid())
4612 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004613
Richard Smithfd555f62012-02-22 02:04:18 +00004614 E = getSema().ActOnDecltypeExpression(E.take());
4615 if (E.isInvalid())
4616 return QualType();
4617
John McCall550e0c22009-10-21 00:40:46 +00004618 QualType Result = TL.getType();
4619 if (getDerived().AlwaysRebuild() ||
4620 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004621 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004622 if (Result.isNull())
4623 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004624 }
John McCall550e0c22009-10-21 00:40:46 +00004625 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00004626
John McCall550e0c22009-10-21 00:40:46 +00004627 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4628 NewTL.setNameLoc(TL.getNameLoc());
4629
4630 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004631}
4632
4633template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00004634QualType TreeTransform<Derived>::TransformUnaryTransformType(
4635 TypeLocBuilder &TLB,
4636 UnaryTransformTypeLoc TL) {
4637 QualType Result = TL.getType();
4638 if (Result->isDependentType()) {
4639 const UnaryTransformType *T = TL.getTypePtr();
4640 QualType NewBase =
4641 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4642 Result = getDerived().RebuildUnaryTransformType(NewBase,
4643 T->getUTTKind(),
4644 TL.getKWLoc());
4645 if (Result.isNull())
4646 return QualType();
4647 }
4648
4649 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4650 NewTL.setKWLoc(TL.getKWLoc());
4651 NewTL.setParensRange(TL.getParensRange());
4652 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4653 return Result;
4654}
4655
4656template<typename Derived>
Richard Smith30482bc2011-02-20 03:19:35 +00004657QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4658 AutoTypeLoc TL) {
4659 const AutoType *T = TL.getTypePtr();
4660 QualType OldDeduced = T->getDeducedType();
4661 QualType NewDeduced;
4662 if (!OldDeduced.isNull()) {
4663 NewDeduced = getDerived().TransformType(OldDeduced);
4664 if (NewDeduced.isNull())
4665 return QualType();
4666 }
4667
4668 QualType Result = TL.getType();
Richard Smith27d807c2013-04-30 13:56:41 +00004669 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
4670 T->isDependentType()) {
Richard Smith74aeef52013-04-26 16:15:35 +00004671 Result = getDerived().RebuildAutoType(NewDeduced, T->isDecltypeAuto());
Richard Smith30482bc2011-02-20 03:19:35 +00004672 if (Result.isNull())
4673 return QualType();
4674 }
4675
4676 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4677 NewTL.setNameLoc(TL.getNameLoc());
4678
4679 return Result;
4680}
4681
4682template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004683QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004684 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004685 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004686 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004687 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4688 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004689 if (!Record)
4690 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004691
John McCall550e0c22009-10-21 00:40:46 +00004692 QualType Result = TL.getType();
4693 if (getDerived().AlwaysRebuild() ||
4694 Record != T->getDecl()) {
4695 Result = getDerived().RebuildRecordType(Record);
4696 if (Result.isNull())
4697 return QualType();
4698 }
Mike Stump11289f42009-09-09 15:08:12 +00004699
John McCall550e0c22009-10-21 00:40:46 +00004700 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4701 NewTL.setNameLoc(TL.getNameLoc());
4702
4703 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004704}
Mike Stump11289f42009-09-09 15:08:12 +00004705
4706template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004707QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004708 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004709 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004710 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004711 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4712 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004713 if (!Enum)
4714 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004715
John McCall550e0c22009-10-21 00:40:46 +00004716 QualType Result = TL.getType();
4717 if (getDerived().AlwaysRebuild() ||
4718 Enum != T->getDecl()) {
4719 Result = getDerived().RebuildEnumType(Enum);
4720 if (Result.isNull())
4721 return QualType();
4722 }
Mike Stump11289f42009-09-09 15:08:12 +00004723
John McCall550e0c22009-10-21 00:40:46 +00004724 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4725 NewTL.setNameLoc(TL.getNameLoc());
4726
4727 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004728}
John McCallfcc33b02009-09-05 00:15:47 +00004729
John McCalle78aac42010-03-10 03:28:59 +00004730template<typename Derived>
4731QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4732 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004733 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00004734 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4735 TL.getTypePtr()->getDecl());
4736 if (!D) return QualType();
4737
4738 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4739 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4740 return T;
4741}
4742
Douglas Gregord6ff3322009-08-04 16:50:30 +00004743template<typename Derived>
4744QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004745 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004746 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004747 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004748}
4749
Mike Stump11289f42009-09-09 15:08:12 +00004750template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00004751QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004752 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004753 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004754 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00004755
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004756 // Substitute into the replacement type, which itself might involve something
4757 // that needs to be transformed. This only tends to occur with default
4758 // template arguments of template template parameters.
4759 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4760 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4761 if (Replacement.isNull())
4762 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00004763
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004764 // Always canonicalize the replacement type.
4765 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4766 QualType Result
Chad Rosier1dcde962012-08-08 18:46:20 +00004767 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004768 Replacement);
Chad Rosier1dcde962012-08-08 18:46:20 +00004769
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004770 // Propagate type-source information.
4771 SubstTemplateTypeParmTypeLoc NewTL
4772 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4773 NewTL.setNameLoc(TL.getNameLoc());
4774 return Result;
4775
John McCallcebee162009-10-18 09:09:24 +00004776}
4777
4778template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00004779QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4780 TypeLocBuilder &TLB,
4781 SubstTemplateTypeParmPackTypeLoc TL) {
4782 return TransformTypeSpecType(TLB, TL);
4783}
4784
4785template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00004786QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00004787 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004788 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00004789 const TemplateSpecializationType *T = TL.getTypePtr();
4790
Douglas Gregordf846d12011-03-02 18:46:51 +00004791 // The nested-name-specifier never matters in a TemplateSpecializationType,
4792 // because we can't have a dependent nested-name-specifier anyway.
4793 CXXScopeSpec SS;
Mike Stump11289f42009-09-09 15:08:12 +00004794 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00004795 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4796 TL.getTemplateNameLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004797 if (Template.isNull())
4798 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004799
John McCall31f82722010-11-12 08:19:04 +00004800 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4801}
4802
Eli Friedman0dfb8892011-10-06 23:00:33 +00004803template<typename Derived>
4804QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
4805 AtomicTypeLoc TL) {
4806 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
4807 if (ValueType.isNull())
4808 return QualType();
4809
4810 QualType Result = TL.getType();
4811 if (getDerived().AlwaysRebuild() ||
4812 ValueType != TL.getValueLoc().getType()) {
4813 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
4814 if (Result.isNull())
4815 return QualType();
4816 }
4817
4818 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
4819 NewTL.setKWLoc(TL.getKWLoc());
4820 NewTL.setLParenLoc(TL.getLParenLoc());
4821 NewTL.setRParenLoc(TL.getRParenLoc());
4822
4823 return Result;
4824}
4825
Chad Rosier1dcde962012-08-08 18:46:20 +00004826 /// \brief Simple iterator that traverses the template arguments in a
Douglas Gregorfe921a72010-12-20 23:36:19 +00004827 /// container that provides a \c getArgLoc() member function.
4828 ///
4829 /// This iterator is intended to be used with the iterator form of
4830 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4831 template<typename ArgLocContainer>
4832 class TemplateArgumentLocContainerIterator {
4833 ArgLocContainer *Container;
4834 unsigned Index;
Chad Rosier1dcde962012-08-08 18:46:20 +00004835
Douglas Gregorfe921a72010-12-20 23:36:19 +00004836 public:
4837 typedef TemplateArgumentLoc value_type;
4838 typedef TemplateArgumentLoc reference;
4839 typedef int difference_type;
4840 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00004841
Douglas Gregorfe921a72010-12-20 23:36:19 +00004842 class pointer {
4843 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00004844
Douglas Gregorfe921a72010-12-20 23:36:19 +00004845 public:
4846 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00004847
Douglas Gregorfe921a72010-12-20 23:36:19 +00004848 const TemplateArgumentLoc *operator->() const {
4849 return &Arg;
4850 }
4851 };
Chad Rosier1dcde962012-08-08 18:46:20 +00004852
4853
Douglas Gregorfe921a72010-12-20 23:36:19 +00004854 TemplateArgumentLocContainerIterator() {}
Chad Rosier1dcde962012-08-08 18:46:20 +00004855
Douglas Gregorfe921a72010-12-20 23:36:19 +00004856 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4857 unsigned Index)
4858 : Container(&Container), Index(Index) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00004859
Douglas Gregorfe921a72010-12-20 23:36:19 +00004860 TemplateArgumentLocContainerIterator &operator++() {
4861 ++Index;
4862 return *this;
4863 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004864
Douglas Gregorfe921a72010-12-20 23:36:19 +00004865 TemplateArgumentLocContainerIterator operator++(int) {
4866 TemplateArgumentLocContainerIterator Old(*this);
4867 ++(*this);
4868 return Old;
4869 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004870
Douglas Gregorfe921a72010-12-20 23:36:19 +00004871 TemplateArgumentLoc operator*() const {
4872 return Container->getArgLoc(Index);
4873 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004874
Douglas Gregorfe921a72010-12-20 23:36:19 +00004875 pointer operator->() const {
4876 return pointer(Container->getArgLoc(Index));
4877 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004878
Douglas Gregorfe921a72010-12-20 23:36:19 +00004879 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004880 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004881 return X.Container == Y.Container && X.Index == Y.Index;
4882 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004883
Douglas Gregorfe921a72010-12-20 23:36:19 +00004884 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004885 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004886 return !(X == Y);
4887 }
4888 };
Chad Rosier1dcde962012-08-08 18:46:20 +00004889
4890
John McCall31f82722010-11-12 08:19:04 +00004891template <typename Derived>
4892QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4893 TypeLocBuilder &TLB,
4894 TemplateSpecializationTypeLoc TL,
4895 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00004896 TemplateArgumentListInfo NewTemplateArgs;
4897 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4898 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00004899 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4900 ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00004901 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregorfe921a72010-12-20 23:36:19 +00004902 ArgIterator(TL, TL.getNumArgs()),
4903 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00004904 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004905
John McCall0ad16662009-10-29 08:12:44 +00004906 // FIXME: maybe don't rebuild if all the template arguments are the same.
4907
4908 QualType Result =
4909 getDerived().RebuildTemplateSpecializationType(Template,
4910 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00004911 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00004912
4913 if (!Result.isNull()) {
Richard Smith3f1b5d02011-05-05 21:57:07 +00004914 // Specializations of template template parameters are represented as
4915 // TemplateSpecializationTypes, and substitution of type alias templates
4916 // within a dependent context can transform them into
4917 // DependentTemplateSpecializationTypes.
4918 if (isa<DependentTemplateSpecializationType>(Result)) {
4919 DependentTemplateSpecializationTypeLoc NewTL
4920 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004921 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3f1b5d02011-05-05 21:57:07 +00004922 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00004923 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004924 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3f1b5d02011-05-05 21:57:07 +00004925 NewTL.setLAngleLoc(TL.getLAngleLoc());
4926 NewTL.setRAngleLoc(TL.getRAngleLoc());
4927 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4928 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4929 return Result;
4930 }
4931
John McCall0ad16662009-10-29 08:12:44 +00004932 TemplateSpecializationTypeLoc NewTL
4933 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004934 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall0ad16662009-10-29 08:12:44 +00004935 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4936 NewTL.setLAngleLoc(TL.getLAngleLoc());
4937 NewTL.setRAngleLoc(TL.getRAngleLoc());
4938 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4939 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004940 }
Mike Stump11289f42009-09-09 15:08:12 +00004941
John McCall0ad16662009-10-29 08:12:44 +00004942 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004943}
Mike Stump11289f42009-09-09 15:08:12 +00004944
Douglas Gregor5a064722011-02-28 17:23:35 +00004945template <typename Derived>
4946QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4947 TypeLocBuilder &TLB,
4948 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +00004949 TemplateName Template,
4950 CXXScopeSpec &SS) {
Douglas Gregor5a064722011-02-28 17:23:35 +00004951 TemplateArgumentListInfo NewTemplateArgs;
4952 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4953 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4954 typedef TemplateArgumentLocContainerIterator<
4955 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00004956 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor5a064722011-02-28 17:23:35 +00004957 ArgIterator(TL, TL.getNumArgs()),
4958 NewTemplateArgs))
4959 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00004960
Douglas Gregor5a064722011-02-28 17:23:35 +00004961 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier1dcde962012-08-08 18:46:20 +00004962
Douglas Gregor5a064722011-02-28 17:23:35 +00004963 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4964 QualType Result
4965 = getSema().Context.getDependentTemplateSpecializationType(
4966 TL.getTypePtr()->getKeyword(),
4967 DTN->getQualifier(),
4968 DTN->getIdentifier(),
4969 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00004970
Douglas Gregor5a064722011-02-28 17:23:35 +00004971 DependentTemplateSpecializationTypeLoc NewTL
4972 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004973 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004974 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00004975 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004976 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00004977 NewTL.setLAngleLoc(TL.getLAngleLoc());
4978 NewTL.setRAngleLoc(TL.getRAngleLoc());
4979 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4980 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4981 return Result;
4982 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004983
4984 QualType Result
Douglas Gregor5a064722011-02-28 17:23:35 +00004985 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004986 TL.getTemplateNameLoc(),
Douglas Gregor5a064722011-02-28 17:23:35 +00004987 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00004988
Douglas Gregor5a064722011-02-28 17:23:35 +00004989 if (!Result.isNull()) {
4990 /// FIXME: Wrap this in an elaborated-type-specifier?
4991 TemplateSpecializationTypeLoc NewTL
4992 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00004993 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004994 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00004995 NewTL.setLAngleLoc(TL.getLAngleLoc());
4996 NewTL.setRAngleLoc(TL.getRAngleLoc());
4997 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4998 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4999 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005000
Douglas Gregor5a064722011-02-28 17:23:35 +00005001 return Result;
5002}
5003
Mike Stump11289f42009-09-09 15:08:12 +00005004template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005005QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00005006TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005007 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005008 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00005009
Douglas Gregor844cb502011-03-01 18:12:44 +00005010 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara6150c882010-05-11 21:36:43 +00005011 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor844cb502011-03-01 18:12:44 +00005012 if (TL.getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005013 QualifierLoc
Douglas Gregor844cb502011-03-01 18:12:44 +00005014 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5015 if (!QualifierLoc)
Abramo Bagnara6150c882010-05-11 21:36:43 +00005016 return QualType();
5017 }
Mike Stump11289f42009-09-09 15:08:12 +00005018
John McCall31f82722010-11-12 08:19:04 +00005019 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
5020 if (NamedT.isNull())
5021 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00005022
Richard Smith3f1b5d02011-05-05 21:57:07 +00005023 // C++0x [dcl.type.elab]p2:
5024 // If the identifier resolves to a typedef-name or the simple-template-id
5025 // resolves to an alias template specialization, the
5026 // elaborated-type-specifier is ill-formed.
Richard Smith0c4a34b2011-05-14 15:04:18 +00005027 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
5028 if (const TemplateSpecializationType *TST =
5029 NamedT->getAs<TemplateSpecializationType>()) {
5030 TemplateName Template = TST->getTemplateName();
5031 if (TypeAliasTemplateDecl *TAT =
5032 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
5033 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
5034 diag::err_tag_reference_non_tag) << 4;
5035 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
5036 }
Richard Smith3f1b5d02011-05-05 21:57:07 +00005037 }
5038 }
5039
John McCall550e0c22009-10-21 00:40:46 +00005040 QualType Result = TL.getType();
5041 if (getDerived().AlwaysRebuild() ||
Douglas Gregor844cb502011-03-01 18:12:44 +00005042 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00005043 NamedT != T->getNamedType()) {
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005044 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00005045 T->getKeyword(),
Douglas Gregor844cb502011-03-01 18:12:44 +00005046 QualifierLoc, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00005047 if (Result.isNull())
5048 return QualType();
5049 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00005050
Abramo Bagnara6150c882010-05-11 21:36:43 +00005051 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005052 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005053 NewTL.setQualifierLoc(QualifierLoc);
John McCall550e0c22009-10-21 00:40:46 +00005054 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005055}
Mike Stump11289f42009-09-09 15:08:12 +00005056
5057template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00005058QualType TreeTransform<Derived>::TransformAttributedType(
5059 TypeLocBuilder &TLB,
5060 AttributedTypeLoc TL) {
5061 const AttributedType *oldType = TL.getTypePtr();
5062 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
5063 if (modifiedType.isNull())
5064 return QualType();
5065
5066 QualType result = TL.getType();
5067
5068 // FIXME: dependent operand expressions?
5069 if (getDerived().AlwaysRebuild() ||
5070 modifiedType != oldType->getModifiedType()) {
5071 // TODO: this is really lame; we should really be rebuilding the
5072 // equivalent type from first principles.
5073 QualType equivalentType
5074 = getDerived().TransformType(oldType->getEquivalentType());
5075 if (equivalentType.isNull())
5076 return QualType();
5077 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
5078 modifiedType,
5079 equivalentType);
5080 }
5081
5082 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
5083 newTL.setAttrNameLoc(TL.getAttrNameLoc());
5084 if (TL.hasAttrOperand())
5085 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5086 if (TL.hasAttrExprOperand())
5087 newTL.setAttrExprOperand(TL.getAttrExprOperand());
5088 else if (TL.hasAttrEnumOperand())
5089 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
5090
5091 return result;
5092}
5093
5094template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00005095QualType
5096TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
5097 ParenTypeLoc TL) {
5098 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
5099 if (Inner.isNull())
5100 return QualType();
5101
5102 QualType Result = TL.getType();
5103 if (getDerived().AlwaysRebuild() ||
5104 Inner != TL.getInnerLoc().getType()) {
5105 Result = getDerived().RebuildParenType(Inner);
5106 if (Result.isNull())
5107 return QualType();
5108 }
5109
5110 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
5111 NewTL.setLParenLoc(TL.getLParenLoc());
5112 NewTL.setRParenLoc(TL.getRParenLoc());
5113 return Result;
5114}
5115
5116template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00005117QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005118 DependentNameTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005119 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00005120
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005121 NestedNameSpecifierLoc QualifierLoc
5122 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5123 if (!QualifierLoc)
Douglas Gregord6ff3322009-08-04 16:50:30 +00005124 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005125
John McCallc392f372010-06-11 00:33:02 +00005126 QualType Result
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005127 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005128 TL.getElaboratedKeywordLoc(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005129 QualifierLoc,
5130 T->getIdentifier(),
John McCallc392f372010-06-11 00:33:02 +00005131 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00005132 if (Result.isNull())
5133 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005134
Abramo Bagnarad7548482010-05-19 21:37:53 +00005135 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
5136 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00005137 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
5138
Abramo Bagnarad7548482010-05-19 21:37:53 +00005139 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005140 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005141 NewTL.setQualifierLoc(QualifierLoc);
John McCallc392f372010-06-11 00:33:02 +00005142 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00005143 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005144 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005145 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00005146 NewTL.setNameLoc(TL.getNameLoc());
5147 }
John McCall550e0c22009-10-21 00:40:46 +00005148 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005149}
Mike Stump11289f42009-09-09 15:08:12 +00005150
Douglas Gregord6ff3322009-08-04 16:50:30 +00005151template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00005152QualType TreeTransform<Derived>::
5153 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005154 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregora7a795b2011-03-01 20:11:18 +00005155 NestedNameSpecifierLoc QualifierLoc;
5156 if (TL.getQualifierLoc()) {
5157 QualifierLoc
5158 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5159 if (!QualifierLoc)
Douglas Gregor5a064722011-02-28 17:23:35 +00005160 return QualType();
5161 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005162
John McCall31f82722010-11-12 08:19:04 +00005163 return getDerived()
Douglas Gregora7a795b2011-03-01 20:11:18 +00005164 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall31f82722010-11-12 08:19:04 +00005165}
5166
5167template<typename Derived>
5168QualType TreeTransform<Derived>::
Douglas Gregora7a795b2011-03-01 20:11:18 +00005169TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
5170 DependentTemplateSpecializationTypeLoc TL,
5171 NestedNameSpecifierLoc QualifierLoc) {
5172 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00005173
Douglas Gregora7a795b2011-03-01 20:11:18 +00005174 TemplateArgumentListInfo NewTemplateArgs;
5175 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5176 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00005177
Douglas Gregora7a795b2011-03-01 20:11:18 +00005178 typedef TemplateArgumentLocContainerIterator<
5179 DependentTemplateSpecializationTypeLoc> ArgIterator;
5180 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5181 ArgIterator(TL, TL.getNumArgs()),
5182 NewTemplateArgs))
5183 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005184
Douglas Gregora7a795b2011-03-01 20:11:18 +00005185 QualType Result
5186 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
5187 QualifierLoc,
5188 T->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005189 TL.getTemplateNameLoc(),
Douglas Gregora7a795b2011-03-01 20:11:18 +00005190 NewTemplateArgs);
5191 if (Result.isNull())
5192 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005193
Douglas Gregora7a795b2011-03-01 20:11:18 +00005194 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
5195 QualType NamedT = ElabT->getNamedType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005196
Douglas Gregora7a795b2011-03-01 20:11:18 +00005197 // Copy information relevant to the template specialization.
5198 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor43f788f2011-03-07 02:33:33 +00005199 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005200 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005201 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005202 NamedTL.setLAngleLoc(TL.getLAngleLoc());
5203 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005204 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005205 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier1dcde962012-08-08 18:46:20 +00005206
Douglas Gregora7a795b2011-03-01 20:11:18 +00005207 // Copy information relevant to the elaborated type.
5208 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005209 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005210 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor43f788f2011-03-07 02:33:33 +00005211 } else if (isa<DependentTemplateSpecializationType>(Result)) {
5212 DependentTemplateSpecializationTypeLoc SpecTL
5213 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005214 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005215 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005216 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005217 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005218 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5219 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005220 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005221 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005222 } else {
Douglas Gregor43f788f2011-03-07 02:33:33 +00005223 TemplateSpecializationTypeLoc SpecTL
5224 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005225 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005226 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005227 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5228 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005229 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005230 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005231 }
5232 return Result;
5233}
5234
5235template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00005236QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5237 PackExpansionTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005238 QualType Pattern
5239 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor822d0302011-01-12 17:07:58 +00005240 if (Pattern.isNull())
5241 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005242
5243 QualType Result = TL.getType();
Douglas Gregor822d0302011-01-12 17:07:58 +00005244 if (getDerived().AlwaysRebuild() ||
5245 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005246 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00005247 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00005248 TL.getEllipsisLoc(),
5249 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00005250 if (Result.isNull())
5251 return QualType();
5252 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005253
Douglas Gregor822d0302011-01-12 17:07:58 +00005254 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5255 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5256 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00005257}
5258
5259template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005260QualType
5261TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005262 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005263 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00005264 TLB.pushFullCopy(TL);
5265 return TL.getType();
5266}
5267
5268template<typename Derived>
5269QualType
5270TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005271 ObjCObjectTypeLoc TL) {
John McCall8b07ec22010-05-15 11:32:37 +00005272 // ObjCObjectType is never dependent.
5273 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00005274 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005275}
Mike Stump11289f42009-09-09 15:08:12 +00005276
5277template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005278QualType
5279TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005280 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005281 // ObjCObjectPointerType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00005282 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00005283 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00005284}
5285
Douglas Gregord6ff3322009-08-04 16:50:30 +00005286//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00005287// Statement transformation
5288//===----------------------------------------------------------------------===//
5289template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005290StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005291TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00005292 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005293}
5294
5295template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005296StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005297TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
5298 return getDerived().TransformCompoundStmt(S, false);
5299}
5300
5301template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005302StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005303TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00005304 bool IsStmtExpr) {
Dmitri Gribenko800ddf32012-02-14 22:14:32 +00005305 Sema::CompoundScopeRAII CompoundScope(getSema());
5306
John McCall1ababa62010-08-27 19:56:05 +00005307 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00005308 bool SubStmtChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005309 SmallVector<Stmt*, 8> Statements;
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005310 for (auto *B : S->body()) {
5311 StmtResult Result = getDerived().TransformStmt(B);
John McCall1ababa62010-08-27 19:56:05 +00005312 if (Result.isInvalid()) {
5313 // Immediately fail if this was a DeclStmt, since it's very
5314 // likely that this will cause problems for future statements.
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005315 if (isa<DeclStmt>(B))
John McCall1ababa62010-08-27 19:56:05 +00005316 return StmtError();
5317
5318 // Otherwise, just keep processing substatements and fail later.
5319 SubStmtInvalid = true;
5320 continue;
5321 }
Mike Stump11289f42009-09-09 15:08:12 +00005322
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005323 SubStmtChanged = SubStmtChanged || Result.get() != B;
Douglas Gregorebe10102009-08-20 07:17:43 +00005324 Statements.push_back(Result.takeAs<Stmt>());
5325 }
Mike Stump11289f42009-09-09 15:08:12 +00005326
John McCall1ababa62010-08-27 19:56:05 +00005327 if (SubStmtInvalid)
5328 return StmtError();
5329
Douglas Gregorebe10102009-08-20 07:17:43 +00005330 if (!getDerived().AlwaysRebuild() &&
5331 !SubStmtChanged)
John McCallc3007a22010-10-26 07:05:15 +00005332 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005333
5334 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00005335 Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00005336 S->getRBracLoc(),
5337 IsStmtExpr);
5338}
Mike Stump11289f42009-09-09 15:08:12 +00005339
Douglas Gregorebe10102009-08-20 07:17:43 +00005340template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005341StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005342TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005343 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00005344 {
Eli Friedman1f4f9dd2012-01-18 02:54:10 +00005345 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5346 Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005347
Eli Friedman06577382009-11-19 03:14:00 +00005348 // Transform the left-hand case value.
5349 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00005350 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman06577382009-11-19 03:14:00 +00005351 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005352 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005353
Eli Friedman06577382009-11-19 03:14:00 +00005354 // Transform the right-hand case value (for the GNU case-range extension).
5355 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00005356 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman06577382009-11-19 03:14:00 +00005357 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005358 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00005359 }
Mike Stump11289f42009-09-09 15:08:12 +00005360
Douglas Gregorebe10102009-08-20 07:17:43 +00005361 // Build the case statement.
5362 // Case statements are always rebuilt so that they will attached to their
5363 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005364 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00005365 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005366 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00005367 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005368 S->getColonLoc());
5369 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005370 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005371
Douglas Gregorebe10102009-08-20 07:17:43 +00005372 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00005373 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005374 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005375 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005376
Douglas Gregorebe10102009-08-20 07:17:43 +00005377 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00005378 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005379}
5380
5381template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005382StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005383TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005384 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00005385 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005386 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005387 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005388
Douglas Gregorebe10102009-08-20 07:17:43 +00005389 // Default statements are always rebuilt
5390 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00005391 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005392}
Mike Stump11289f42009-09-09 15:08:12 +00005393
Douglas Gregorebe10102009-08-20 07:17:43 +00005394template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005395StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005396TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005397 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005398 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005399 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005400
Chris Lattnercab02a62011-02-17 20:34:02 +00005401 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5402 S->getDecl());
5403 if (!LD)
5404 return StmtError();
Richard Smithc202b282012-04-14 00:33:13 +00005405
5406
Douglas Gregorebe10102009-08-20 07:17:43 +00005407 // FIXME: Pass the real colon location in.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00005408 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005409 cast<LabelDecl>(LD), SourceLocation(),
5410 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005411}
Mike Stump11289f42009-09-09 15:08:12 +00005412
Douglas Gregorebe10102009-08-20 07:17:43 +00005413template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005414StmtResult
Richard Smithc202b282012-04-14 00:33:13 +00005415TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
5416 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5417 if (SubStmt.isInvalid())
5418 return StmtError();
5419
5420 // TODO: transform attributes
5421 if (SubStmt.get() == S->getSubStmt() /* && attrs are the same */)
5422 return S;
5423
5424 return getDerived().RebuildAttributedStmt(S->getAttrLoc(),
5425 S->getAttrs(),
5426 SubStmt.get());
5427}
5428
5429template<typename Derived>
5430StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005431TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005432 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005433 ExprResult Cond;
Douglas Gregor633caca2009-11-23 23:44:04 +00005434 VarDecl *ConditionVar = 0;
5435 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005436 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00005437 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005438 getDerived().TransformDefinition(
5439 S->getConditionVariable()->getLocation(),
5440 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00005441 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005442 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005443 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00005444 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005445
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005446 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005447 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005448
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005449 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00005450 if (S->getCond()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005451 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005452 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005453 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005454 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005455
John McCallb268a282010-08-23 23:25:46 +00005456 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005457 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005458 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005459
John McCallb268a282010-08-23 23:25:46 +00005460 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5461 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005462 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005463
Douglas Gregorebe10102009-08-20 07:17:43 +00005464 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00005465 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00005466 if (Then.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005467 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005468
Douglas Gregorebe10102009-08-20 07:17:43 +00005469 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00005470 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00005471 if (Else.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005472 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005473
Douglas Gregorebe10102009-08-20 07:17:43 +00005474 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00005475 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005476 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005477 Then.get() == S->getThen() &&
5478 Else.get() == S->getElse())
John McCallc3007a22010-10-26 07:05:15 +00005479 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005480
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005481 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00005482 Then.get(),
John McCallb268a282010-08-23 23:25:46 +00005483 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005484}
5485
5486template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005487StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005488TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005489 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00005490 ExprResult Cond;
Douglas Gregordcf19622009-11-24 17:07:59 +00005491 VarDecl *ConditionVar = 0;
5492 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005493 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00005494 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005495 getDerived().TransformDefinition(
5496 S->getConditionVariable()->getLocation(),
5497 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00005498 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005499 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005500 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00005501 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005502
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005503 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005504 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005505 }
Mike Stump11289f42009-09-09 15:08:12 +00005506
Douglas Gregorebe10102009-08-20 07:17:43 +00005507 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005508 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00005509 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00005510 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00005511 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005512 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005513
Douglas Gregorebe10102009-08-20 07:17:43 +00005514 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005515 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005516 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005517 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005518
Douglas Gregorebe10102009-08-20 07:17:43 +00005519 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00005520 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5521 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005522}
Mike Stump11289f42009-09-09 15:08:12 +00005523
Douglas Gregorebe10102009-08-20 07:17:43 +00005524template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005525StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005526TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005527 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005528 ExprResult Cond;
Douglas Gregor680f8612009-11-24 21:15:44 +00005529 VarDecl *ConditionVar = 0;
5530 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005531 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00005532 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005533 getDerived().TransformDefinition(
5534 S->getConditionVariable()->getLocation(),
5535 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00005536 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005537 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005538 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00005539 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005540
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005541 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005542 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005543
5544 if (S->getCond()) {
5545 // Convert the condition to a boolean value.
Chad Rosier1dcde962012-08-08 18:46:20 +00005546 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005547 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005548 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005549 return StmtError();
John McCallb268a282010-08-23 23:25:46 +00005550 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00005551 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005552 }
Mike Stump11289f42009-09-09 15:08:12 +00005553
John McCallb268a282010-08-23 23:25:46 +00005554 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5555 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005556 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005557
Douglas Gregorebe10102009-08-20 07:17:43 +00005558 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005559 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005560 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005561 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005562
Douglas Gregorebe10102009-08-20 07:17:43 +00005563 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00005564 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005565 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005566 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00005567 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005568
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005569 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00005570 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005571}
Mike Stump11289f42009-09-09 15:08:12 +00005572
Douglas Gregorebe10102009-08-20 07:17:43 +00005573template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005574StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005575TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005576 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005577 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005578 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005579 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005580
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005581 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005582 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005583 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005584 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005585
Douglas Gregorebe10102009-08-20 07:17:43 +00005586 if (!getDerived().AlwaysRebuild() &&
5587 Cond.get() == S->getCond() &&
5588 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005589 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005590
John McCallb268a282010-08-23 23:25:46 +00005591 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5592 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005593 S->getRParenLoc());
5594}
Mike Stump11289f42009-09-09 15:08:12 +00005595
Douglas Gregorebe10102009-08-20 07:17:43 +00005596template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005597StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005598TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005599 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00005600 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00005601 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005602 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005603
Douglas Gregorebe10102009-08-20 07:17:43 +00005604 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005605 ExprResult Cond;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005606 VarDecl *ConditionVar = 0;
5607 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005608 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005609 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005610 getDerived().TransformDefinition(
5611 S->getConditionVariable()->getLocation(),
5612 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005613 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005614 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005615 } else {
5616 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005617
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005618 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005619 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005620
5621 if (S->getCond()) {
5622 // Convert the condition to a boolean value.
Chad Rosier1dcde962012-08-08 18:46:20 +00005623 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005624 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005625 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005626 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005627
John McCallb268a282010-08-23 23:25:46 +00005628 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005629 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005630 }
Mike Stump11289f42009-09-09 15:08:12 +00005631
Chad Rosier1dcde962012-08-08 18:46:20 +00005632 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
John McCallb268a282010-08-23 23:25:46 +00005633 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005634 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005635
Douglas Gregorebe10102009-08-20 07:17:43 +00005636 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00005637 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005638 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005639 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005640
Richard Smith945f8d32013-01-14 22:39:08 +00005641 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
John McCallb268a282010-08-23 23:25:46 +00005642 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005643 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005644
Douglas Gregorebe10102009-08-20 07:17:43 +00005645 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005646 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005647 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005648 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005649
Douglas Gregorebe10102009-08-20 07:17:43 +00005650 if (!getDerived().AlwaysRebuild() &&
5651 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00005652 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005653 Inc.get() == S->getInc() &&
5654 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005655 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005656
Douglas Gregorebe10102009-08-20 07:17:43 +00005657 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005658 Init.get(), FullCond, ConditionVar,
5659 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005660}
5661
5662template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005663StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005664TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattnercab02a62011-02-17 20:34:02 +00005665 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5666 S->getLabel());
5667 if (!LD)
5668 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005669
Douglas Gregorebe10102009-08-20 07:17:43 +00005670 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00005671 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005672 cast<LabelDecl>(LD));
Douglas Gregorebe10102009-08-20 07:17:43 +00005673}
5674
5675template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005676StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005677TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005678 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00005679 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005680 return StmtError();
Eli Friedman9ccdb1d2012-01-31 22:47:07 +00005681 Target = SemaRef.MaybeCreateExprWithCleanups(Target.take());
Mike Stump11289f42009-09-09 15:08:12 +00005682
Douglas Gregorebe10102009-08-20 07:17:43 +00005683 if (!getDerived().AlwaysRebuild() &&
5684 Target.get() == S->getTarget())
John McCallc3007a22010-10-26 07:05:15 +00005685 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005686
5687 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00005688 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005689}
5690
5691template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005692StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005693TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00005694 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005695}
Mike Stump11289f42009-09-09 15:08:12 +00005696
Douglas Gregorebe10102009-08-20 07:17:43 +00005697template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005698StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005699TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00005700 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005701}
Mike Stump11289f42009-09-09 15:08:12 +00005702
Douglas Gregorebe10102009-08-20 07:17:43 +00005703template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005704StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005705TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005706 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregorebe10102009-08-20 07:17:43 +00005707 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005708 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00005709
Mike Stump11289f42009-09-09 15:08:12 +00005710 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00005711 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00005712 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005713}
Mike Stump11289f42009-09-09 15:08:12 +00005714
Douglas Gregorebe10102009-08-20 07:17:43 +00005715template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005716StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005717TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005718 bool DeclChanged = false;
Chris Lattner01cf8db2011-07-20 06:58:45 +00005719 SmallVector<Decl *, 4> Decls;
Aaron Ballman535bbcc2014-03-14 17:01:24 +00005720 for (auto *D : S->decls()) {
5721 Decl *Transformed = getDerived().TransformDefinition(D->getLocation(), D);
Douglas Gregorebe10102009-08-20 07:17:43 +00005722 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00005723 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005724
Aaron Ballman535bbcc2014-03-14 17:01:24 +00005725 if (Transformed != D)
Douglas Gregorebe10102009-08-20 07:17:43 +00005726 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00005727
Douglas Gregorebe10102009-08-20 07:17:43 +00005728 Decls.push_back(Transformed);
5729 }
Mike Stump11289f42009-09-09 15:08:12 +00005730
Douglas Gregorebe10102009-08-20 07:17:43 +00005731 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCallc3007a22010-10-26 07:05:15 +00005732 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005733
Rafael Espindolaab417692013-07-09 12:05:01 +00005734 return getDerived().RebuildDeclStmt(Decls, S->getStartLoc(), S->getEndLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005735}
Mike Stump11289f42009-09-09 15:08:12 +00005736
Douglas Gregorebe10102009-08-20 07:17:43 +00005737template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005738StmtResult
Chad Rosierde70e0e2012-08-25 00:11:56 +00005739TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005740
Benjamin Kramerf0623432012-08-23 22:51:59 +00005741 SmallVector<Expr*, 8> Constraints;
5742 SmallVector<Expr*, 8> Exprs;
Chris Lattner01cf8db2011-07-20 06:58:45 +00005743 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00005744
John McCalldadc5752010-08-24 06:29:42 +00005745 ExprResult AsmString;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005746 SmallVector<Expr*, 8> Clobbers;
Anders Carlssonaaeef072010-01-24 05:50:09 +00005747
5748 bool ExprsChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00005749
Anders Carlssonaaeef072010-01-24 05:50:09 +00005750 // Go through the outputs.
5751 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005752 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005753
Anders Carlssonaaeef072010-01-24 05:50:09 +00005754 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005755 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005756
Anders Carlssonaaeef072010-01-24 05:50:09 +00005757 // Transform the output expr.
5758 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005759 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005760 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005761 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005762
Anders Carlssonaaeef072010-01-24 05:50:09 +00005763 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00005764
John McCallb268a282010-08-23 23:25:46 +00005765 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005766 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005767
Anders Carlssonaaeef072010-01-24 05:50:09 +00005768 // Go through the inputs.
5769 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005770 Names.push_back(S->getInputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005771
Anders Carlssonaaeef072010-01-24 05:50:09 +00005772 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005773 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005774
Anders Carlssonaaeef072010-01-24 05:50:09 +00005775 // Transform the input expr.
5776 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005777 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005778 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005779 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005780
Anders Carlssonaaeef072010-01-24 05:50:09 +00005781 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00005782
John McCallb268a282010-08-23 23:25:46 +00005783 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005784 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005785
Anders Carlssonaaeef072010-01-24 05:50:09 +00005786 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCallc3007a22010-10-26 07:05:15 +00005787 return SemaRef.Owned(S);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005788
5789 // Go through the clobbers.
5790 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosierd9fb09a2012-08-27 23:28:41 +00005791 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00005792
5793 // No need to transform the asm string literal.
5794 AsmString = SemaRef.Owned(S->getAsmString());
Chad Rosierde70e0e2012-08-25 00:11:56 +00005795 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
5796 S->isVolatile(), S->getNumOutputs(),
5797 S->getNumInputs(), Names.data(),
5798 Constraints, Exprs, AsmString.get(),
5799 Clobbers, S->getRParenLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005800}
5801
Chad Rosier32503022012-06-11 20:47:18 +00005802template<typename Derived>
5803StmtResult
5804TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier99fc3812012-08-07 00:29:06 +00005805 ArrayRef<Token> AsmToks =
5806 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier3ed0bd92012-08-08 19:48:07 +00005807
John McCallf413f5e2013-05-03 00:10:13 +00005808 bool HadError = false, HadChange = false;
5809
5810 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
5811 SmallVector<Expr*, 8> TransformedExprs;
5812 TransformedExprs.reserve(SrcExprs.size());
5813 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
5814 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
5815 if (!Result.isUsable()) {
5816 HadError = true;
5817 } else {
5818 HadChange |= (Result.get() != SrcExprs[i]);
5819 TransformedExprs.push_back(Result.take());
5820 }
5821 }
5822
5823 if (HadError) return StmtError();
5824 if (!HadChange && !getDerived().AlwaysRebuild())
5825 return Owned(S);
5826
Chad Rosierb6f46c12012-08-15 16:53:30 +00005827 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
John McCallf413f5e2013-05-03 00:10:13 +00005828 AsmToks, S->getAsmString(),
5829 S->getNumOutputs(), S->getNumInputs(),
5830 S->getAllConstraints(), S->getClobbers(),
5831 TransformedExprs, S->getEndLoc());
Chad Rosier32503022012-06-11 20:47:18 +00005832}
Douglas Gregorebe10102009-08-20 07:17:43 +00005833
5834template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005835StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005836TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005837 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00005838 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005839 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005840 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005841
Douglas Gregor96c79492010-04-23 22:50:49 +00005842 // Transform the @catch statements (if present).
5843 bool AnyCatchChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005844 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor96c79492010-04-23 22:50:49 +00005845 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00005846 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00005847 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005848 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00005849 if (Catch.get() != S->getCatchStmt(I))
5850 AnyCatchChanged = true;
5851 CatchStmts.push_back(Catch.release());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005852 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005853
Douglas Gregor306de2f2010-04-22 23:59:56 +00005854 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00005855 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00005856 if (S->getFinallyStmt()) {
5857 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5858 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005859 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00005860 }
5861
5862 // If nothing changed, just retain this statement.
5863 if (!getDerived().AlwaysRebuild() &&
5864 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00005865 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00005866 Finally.get() == S->getFinallyStmt())
John McCallc3007a22010-10-26 07:05:15 +00005867 return SemaRef.Owned(S);
Chad Rosier1dcde962012-08-08 18:46:20 +00005868
Douglas Gregor306de2f2010-04-22 23:59:56 +00005869 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00005870 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00005871 CatchStmts, Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005872}
Mike Stump11289f42009-09-09 15:08:12 +00005873
Douglas Gregorebe10102009-08-20 07:17:43 +00005874template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005875StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005876TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005877 // Transform the @catch parameter, if there is one.
5878 VarDecl *Var = 0;
5879 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5880 TypeSourceInfo *TSInfo = 0;
5881 if (FromVar->getTypeSourceInfo()) {
5882 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5883 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005884 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005885 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005886
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005887 QualType T;
5888 if (TSInfo)
5889 T = TSInfo->getType();
5890 else {
5891 T = getDerived().TransformType(FromVar->getType());
5892 if (T.isNull())
Chad Rosier1dcde962012-08-08 18:46:20 +00005893 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005894 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005895
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005896 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5897 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00005898 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005899 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005900
John McCalldadc5752010-08-24 06:29:42 +00005901 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005902 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005903 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005904
5905 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005906 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005907 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005908}
Mike Stump11289f42009-09-09 15:08:12 +00005909
Douglas Gregorebe10102009-08-20 07:17:43 +00005910template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005911StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005912TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005913 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005914 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005915 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005916 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005917
Douglas Gregor306de2f2010-04-22 23:59:56 +00005918 // If nothing changed, just retain this statement.
5919 if (!getDerived().AlwaysRebuild() &&
5920 Body.get() == S->getFinallyBody())
John McCallc3007a22010-10-26 07:05:15 +00005921 return SemaRef.Owned(S);
Douglas Gregor306de2f2010-04-22 23:59:56 +00005922
5923 // Build a new statement.
5924 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00005925 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005926}
Mike Stump11289f42009-09-09 15:08:12 +00005927
Douglas Gregorebe10102009-08-20 07:17:43 +00005928template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005929StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005930TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005931 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00005932 if (S->getThrowExpr()) {
5933 Operand = getDerived().TransformExpr(S->getThrowExpr());
5934 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005935 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00005936 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005937
Douglas Gregor2900c162010-04-22 21:44:01 +00005938 if (!getDerived().AlwaysRebuild() &&
5939 Operand.get() == S->getThrowExpr())
John McCallc3007a22010-10-26 07:05:15 +00005940 return getSema().Owned(S);
Chad Rosier1dcde962012-08-08 18:46:20 +00005941
John McCallb268a282010-08-23 23:25:46 +00005942 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005943}
Mike Stump11289f42009-09-09 15:08:12 +00005944
Douglas Gregorebe10102009-08-20 07:17:43 +00005945template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005946StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005947TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00005948 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00005949 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00005950 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00005951 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005952 return StmtError();
John McCalld9bb7432011-07-27 21:50:02 +00005953 Object =
5954 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
5955 Object.get());
5956 if (Object.isInvalid())
5957 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005958
Douglas Gregor6148de72010-04-22 22:01:21 +00005959 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005960 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00005961 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005962 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005963
Douglas Gregor6148de72010-04-22 22:01:21 +00005964 // If nothing change, just retain the current statement.
5965 if (!getDerived().AlwaysRebuild() &&
5966 Object.get() == S->getSynchExpr() &&
5967 Body.get() == S->getSynchBody())
John McCallc3007a22010-10-26 07:05:15 +00005968 return SemaRef.Owned(S);
Douglas Gregor6148de72010-04-22 22:01:21 +00005969
5970 // Build a new statement.
5971 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00005972 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005973}
5974
5975template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005976StmtResult
John McCall31168b02011-06-15 23:02:42 +00005977TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
5978 ObjCAutoreleasePoolStmt *S) {
5979 // Transform the body.
5980 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
5981 if (Body.isInvalid())
5982 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005983
John McCall31168b02011-06-15 23:02:42 +00005984 // If nothing changed, just retain this statement.
5985 if (!getDerived().AlwaysRebuild() &&
5986 Body.get() == S->getSubStmt())
5987 return SemaRef.Owned(S);
5988
5989 // Build a new statement.
5990 return getDerived().RebuildObjCAutoreleasePoolStmt(
5991 S->getAtLoc(), Body.get());
5992}
5993
5994template<typename Derived>
5995StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005996TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00005997 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00005998 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00005999 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006000 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006001 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006002
Douglas Gregorf68a5082010-04-22 23:10:45 +00006003 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00006004 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006005 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006006 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006007
Douglas Gregorf68a5082010-04-22 23:10:45 +00006008 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006009 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006010 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006011 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006012
Douglas Gregorf68a5082010-04-22 23:10:45 +00006013 // If nothing changed, just retain this statement.
6014 if (!getDerived().AlwaysRebuild() &&
6015 Element.get() == S->getElement() &&
6016 Collection.get() == S->getCollection() &&
6017 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00006018 return SemaRef.Owned(S);
Chad Rosier1dcde962012-08-08 18:46:20 +00006019
Douglas Gregorf68a5082010-04-22 23:10:45 +00006020 // Build a new statement.
6021 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00006022 Element.get(),
6023 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00006024 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006025 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006026}
6027
David Majnemer5f7efef2013-10-15 09:50:08 +00006028template <typename Derived>
6029StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006030 // Transform the exception declaration, if any.
6031 VarDecl *Var = 0;
David Majnemer5f7efef2013-10-15 09:50:08 +00006032 if (VarDecl *ExceptionDecl = S->getExceptionDecl()) {
6033 TypeSourceInfo *T =
6034 getDerived().TransformType(ExceptionDecl->getTypeSourceInfo());
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00006035 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006036 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006037
David Majnemer5f7efef2013-10-15 09:50:08 +00006038 Var = getDerived().RebuildExceptionDecl(
6039 ExceptionDecl, T, ExceptionDecl->getInnerLocStart(),
6040 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
Douglas Gregorb412e172010-07-25 18:17:45 +00006041 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00006042 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00006043 }
Mike Stump11289f42009-09-09 15:08:12 +00006044
Douglas Gregorebe10102009-08-20 07:17:43 +00006045 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00006046 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00006047 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006048 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006049
David Majnemer5f7efef2013-10-15 09:50:08 +00006050 if (!getDerived().AlwaysRebuild() && !Var &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006051 Handler.get() == S->getHandlerBlock())
John McCallc3007a22010-10-26 07:05:15 +00006052 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00006053
David Majnemer5f7efef2013-10-15 09:50:08 +00006054 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006055}
Mike Stump11289f42009-09-09 15:08:12 +00006056
David Majnemer5f7efef2013-10-15 09:50:08 +00006057template <typename Derived>
6058StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006059 // Transform the try block itself.
David Majnemer5f7efef2013-10-15 09:50:08 +00006060 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
Douglas Gregorebe10102009-08-20 07:17:43 +00006061 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006062 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006063
Douglas Gregorebe10102009-08-20 07:17:43 +00006064 // Transform the handlers.
6065 bool HandlerChanged = false;
David Majnemer5f7efef2013-10-15 09:50:08 +00006066 SmallVector<Stmt *, 8> Handlers;
Douglas Gregorebe10102009-08-20 07:17:43 +00006067 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
David Majnemer5f7efef2013-10-15 09:50:08 +00006068 StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I));
Douglas Gregorebe10102009-08-20 07:17:43 +00006069 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006070 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006071
Douglas Gregorebe10102009-08-20 07:17:43 +00006072 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
6073 Handlers.push_back(Handler.takeAs<Stmt>());
6074 }
Mike Stump11289f42009-09-09 15:08:12 +00006075
David Majnemer5f7efef2013-10-15 09:50:08 +00006076 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006077 !HandlerChanged)
John McCallc3007a22010-10-26 07:05:15 +00006078 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00006079
John McCallb268a282010-08-23 23:25:46 +00006080 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006081 Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00006082}
Mike Stump11289f42009-09-09 15:08:12 +00006083
Richard Smith02e85f32011-04-14 22:09:26 +00006084template<typename Derived>
6085StmtResult
6086TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
6087 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
6088 if (Range.isInvalid())
6089 return StmtError();
6090
6091 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
6092 if (BeginEnd.isInvalid())
6093 return StmtError();
6094
6095 ExprResult Cond = getDerived().TransformExpr(S->getCond());
6096 if (Cond.isInvalid())
6097 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006098 if (Cond.get())
6099 Cond = SemaRef.CheckBooleanCondition(Cond.take(), S->getColonLoc());
6100 if (Cond.isInvalid())
6101 return StmtError();
6102 if (Cond.get())
6103 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.take());
Richard Smith02e85f32011-04-14 22:09:26 +00006104
6105 ExprResult Inc = getDerived().TransformExpr(S->getInc());
6106 if (Inc.isInvalid())
6107 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006108 if (Inc.get())
6109 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.take());
Richard Smith02e85f32011-04-14 22:09:26 +00006110
6111 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
6112 if (LoopVar.isInvalid())
6113 return StmtError();
6114
6115 StmtResult NewStmt = S;
6116 if (getDerived().AlwaysRebuild() ||
6117 Range.get() != S->getRangeStmt() ||
6118 BeginEnd.get() != S->getBeginEndStmt() ||
6119 Cond.get() != S->getCond() ||
6120 Inc.get() != S->getInc() ||
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006121 LoopVar.get() != S->getLoopVarStmt()) {
Richard Smith02e85f32011-04-14 22:09:26 +00006122 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6123 S->getColonLoc(), Range.get(),
6124 BeginEnd.get(), Cond.get(),
6125 Inc.get(), LoopVar.get(),
6126 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006127 if (NewStmt.isInvalid())
6128 return StmtError();
6129 }
Richard Smith02e85f32011-04-14 22:09:26 +00006130
6131 StmtResult Body = getDerived().TransformStmt(S->getBody());
6132 if (Body.isInvalid())
6133 return StmtError();
6134
6135 // Body has changed but we didn't rebuild the for-range statement. Rebuild
6136 // it now so we have a new statement to attach the body to.
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006137 if (Body.get() != S->getBody() && NewStmt.get() == S) {
Richard Smith02e85f32011-04-14 22:09:26 +00006138 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6139 S->getColonLoc(), Range.get(),
6140 BeginEnd.get(), Cond.get(),
6141 Inc.get(), LoopVar.get(),
6142 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006143 if (NewStmt.isInvalid())
6144 return StmtError();
6145 }
Richard Smith02e85f32011-04-14 22:09:26 +00006146
6147 if (NewStmt.get() == S)
6148 return SemaRef.Owned(S);
6149
6150 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
6151}
6152
John Wiegley1c0675e2011-04-28 01:08:34 +00006153template<typename Derived>
6154StmtResult
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006155TreeTransform<Derived>::TransformMSDependentExistsStmt(
6156 MSDependentExistsStmt *S) {
6157 // Transform the nested-name-specifier, if any.
6158 NestedNameSpecifierLoc QualifierLoc;
6159 if (S->getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006160 QualifierLoc
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006161 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
6162 if (!QualifierLoc)
6163 return StmtError();
6164 }
6165
6166 // Transform the declaration name.
6167 DeclarationNameInfo NameInfo = S->getNameInfo();
6168 if (NameInfo.getName()) {
6169 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6170 if (!NameInfo.getName())
6171 return StmtError();
6172 }
6173
6174 // Check whether anything changed.
6175 if (!getDerived().AlwaysRebuild() &&
6176 QualifierLoc == S->getQualifierLoc() &&
6177 NameInfo.getName() == S->getNameInfo().getName())
6178 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006179
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006180 // Determine whether this name exists, if we can.
6181 CXXScopeSpec SS;
6182 SS.Adopt(QualifierLoc);
6183 bool Dependent = false;
6184 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/0, SS, NameInfo)) {
6185 case Sema::IER_Exists:
6186 if (S->isIfExists())
6187 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006188
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006189 return new (getSema().Context) NullStmt(S->getKeywordLoc());
6190
6191 case Sema::IER_DoesNotExist:
6192 if (S->isIfNotExists())
6193 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006194
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006195 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00006196
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006197 case Sema::IER_Dependent:
6198 Dependent = true;
6199 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006200
Douglas Gregor4a2a8f72011-10-25 03:44:56 +00006201 case Sema::IER_Error:
6202 return StmtError();
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006203 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006204
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006205 // We need to continue with the instantiation, so do so now.
6206 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
6207 if (SubStmt.isInvalid())
6208 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006209
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006210 // If we have resolved the name, just transform to the substatement.
6211 if (!Dependent)
6212 return SubStmt;
Chad Rosier1dcde962012-08-08 18:46:20 +00006213
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006214 // The name is still dependent, so build a dependent expression again.
6215 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
6216 S->isIfExists(),
6217 QualifierLoc,
6218 NameInfo,
6219 SubStmt.get());
6220}
6221
6222template<typename Derived>
John McCall5e77d762013-04-16 07:28:30 +00006223ExprResult
6224TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
6225 NestedNameSpecifierLoc QualifierLoc;
6226 if (E->getQualifierLoc()) {
6227 QualifierLoc
6228 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6229 if (!QualifierLoc)
6230 return ExprError();
6231 }
6232
6233 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
6234 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
6235 if (!PD)
6236 return ExprError();
6237
6238 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
6239 if (Base.isInvalid())
6240 return ExprError();
6241
6242 return new (SemaRef.getASTContext())
6243 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
6244 SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
6245 QualifierLoc, E->getMemberLoc());
6246}
6247
David Majnemerfad8f482013-10-15 09:33:02 +00006248template <typename Derived>
6249StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00006250 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006251 if (TryBlock.isInvalid())
6252 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006253
6254 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
David Majnemer7e755502013-10-15 09:30:14 +00006255 if (Handler.isInvalid())
6256 return StmtError();
6257
David Majnemerfad8f482013-10-15 09:33:02 +00006258 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
6259 Handler.get() == S->getHandler())
John Wiegley1c0675e2011-04-28 01:08:34 +00006260 return SemaRef.Owned(S);
6261
David Majnemerfad8f482013-10-15 09:33:02 +00006262 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(),
6263 TryBlock.take(), Handler.take());
John Wiegley1c0675e2011-04-28 01:08:34 +00006264}
6265
David Majnemerfad8f482013-10-15 09:33:02 +00006266template <typename Derived>
6267StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00006268 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006269 if (Block.isInvalid())
6270 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006271
David Majnemerfad8f482013-10-15 09:33:02 +00006272 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.take());
John Wiegley1c0675e2011-04-28 01:08:34 +00006273}
6274
David Majnemerfad8f482013-10-15 09:33:02 +00006275template <typename Derived>
6276StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
John Wiegley1c0675e2011-04-28 01:08:34 +00006277 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
David Majnemerfad8f482013-10-15 09:33:02 +00006278 if (FilterExpr.isInvalid())
6279 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006280
David Majnemer7e755502013-10-15 09:30:14 +00006281 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006282 if (Block.isInvalid())
6283 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006284
David Majnemerfad8f482013-10-15 09:33:02 +00006285 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.take(),
John Wiegley1c0675e2011-04-28 01:08:34 +00006286 Block.take());
6287}
6288
David Majnemerfad8f482013-10-15 09:33:02 +00006289template <typename Derived>
6290StmtResult TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
6291 if (isa<SEHFinallyStmt>(Handler))
John Wiegley1c0675e2011-04-28 01:08:34 +00006292 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
6293 else
6294 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
6295}
6296
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006297template<typename Derived>
6298StmtResult
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006299TreeTransform<Derived>::TransformOMPExecutableDirective(
6300 OMPExecutableDirective *D) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00006301
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006302 // Transform the clauses
Alexey Bataev758e55e2013-09-06 18:03:48 +00006303 llvm::SmallVector<OMPClause *, 16> TClauses;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006304 ArrayRef<OMPClause *> Clauses = D->clauses();
6305 TClauses.reserve(Clauses.size());
6306 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
6307 I != E; ++I) {
6308 if (*I) {
6309 OMPClause *Clause = getDerived().TransformOMPClause(*I);
Alexey Bataev758e55e2013-09-06 18:03:48 +00006310 if (!Clause) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006311 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00006312 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006313 TClauses.push_back(Clause);
6314 }
6315 else {
6316 TClauses.push_back(0);
6317 }
6318 }
Alexey Bataev758e55e2013-09-06 18:03:48 +00006319 if (!D->getAssociatedStmt()) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006320 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00006321 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006322 StmtResult AssociatedStmt =
6323 getDerived().TransformStmt(D->getAssociatedStmt());
Alexey Bataev758e55e2013-09-06 18:03:48 +00006324 if (AssociatedStmt.isInvalid()) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006325 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00006326 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006327
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006328 return getDerived().RebuildOMPExecutableDirective(D->getDirectiveKind(),
6329 TClauses,
6330 AssociatedStmt.take(),
6331 D->getLocStart(),
6332 D->getLocEnd());
6333}
6334
6335template<typename Derived>
6336StmtResult
6337TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
6338 DeclarationNameInfo DirName;
Alexey Bataev3d76e772014-03-07 04:01:56 +00006339 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, 0);
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006340 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6341 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6342 return Res;
6343}
6344
6345template<typename Derived>
6346StmtResult
6347TreeTransform<Derived>::TransformOMPSimdDirective(OMPSimdDirective *D) {
6348 DeclarationNameInfo DirName;
Alexey Bataev96d15102014-03-07 04:16:48 +00006349 getDerived().getSema().StartOpenMPDSABlock(OMPD_simd, DirName, 0);
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006350 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6351 getDerived().getSema().EndOpenMPDSABlock(Res.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00006352 return Res;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006353}
6354
6355template<typename Derived>
6356OMPClause *
Alexey Bataevaadd52e2014-02-13 05:29:23 +00006357TreeTransform<Derived>::TransformOMPIfClause(OMPIfClause *C) {
Alexey Bataevaf7849e2014-03-05 06:45:14 +00006358 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
6359 if (Cond.isInvalid())
6360 return 0;
6361 return getDerived().RebuildOMPIfClause(Cond.take(), C->getLocStart(),
Alexey Bataevaadd52e2014-02-13 05:29:23 +00006362 C->getLParenLoc(), C->getLocEnd());
6363}
6364
6365template<typename Derived>
6366OMPClause *
Alexey Bataev568a8332014-03-06 06:15:19 +00006367TreeTransform<Derived>::TransformOMPNumThreadsClause(OMPNumThreadsClause *C) {
6368 ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads());
6369 if (NumThreads.isInvalid())
6370 return 0;
6371 return getDerived().RebuildOMPNumThreadsClause(NumThreads.take(),
6372 C->getLocStart(),
6373 C->getLParenLoc(),
6374 C->getLocEnd());
6375}
6376
Alexey Bataev62c87d22014-03-21 04:51:18 +00006377template <typename Derived>
6378OMPClause *
6379TreeTransform<Derived>::TransformOMPSafelenClause(OMPSafelenClause *C) {
6380 ExprResult E = getDerived().TransformExpr(C->getSafelen());
6381 if (E.isInvalid())
6382 return 0;
6383 return getDerived().RebuildOMPSafelenClause(
6384 E.take(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
6385}
6386
Alexey Bataev568a8332014-03-06 06:15:19 +00006387template<typename Derived>
6388OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006389TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
6390 return getDerived().RebuildOMPDefaultClause(C->getDefaultKind(),
6391 C->getDefaultKindKwLoc(),
6392 C->getLocStart(),
6393 C->getLParenLoc(),
6394 C->getLocEnd());
6395}
6396
6397template<typename Derived>
6398OMPClause *
6399TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00006400 llvm::SmallVector<Expr *, 16> Vars;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006401 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00006402 for (auto *VE : C->varlists()) {
6403 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006404 if (EVar.isInvalid())
6405 return 0;
6406 Vars.push_back(EVar.take());
6407 }
6408 return getDerived().RebuildOMPPrivateClause(Vars,
6409 C->getLocStart(),
6410 C->getLParenLoc(),
6411 C->getLocEnd());
6412}
6413
Alexey Bataev758e55e2013-09-06 18:03:48 +00006414template<typename Derived>
6415OMPClause *
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006416TreeTransform<Derived>::TransformOMPFirstprivateClause(
6417 OMPFirstprivateClause *C) {
6418 llvm::SmallVector<Expr *, 16> Vars;
6419 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00006420 for (auto *VE : C->varlists()) {
6421 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006422 if (EVar.isInvalid())
6423 return 0;
6424 Vars.push_back(EVar.take());
6425 }
6426 return getDerived().RebuildOMPFirstprivateClause(Vars,
6427 C->getLocStart(),
6428 C->getLParenLoc(),
6429 C->getLocEnd());
6430}
6431
6432template<typename Derived>
6433OMPClause *
Alexey Bataev758e55e2013-09-06 18:03:48 +00006434TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
6435 llvm::SmallVector<Expr *, 16> Vars;
6436 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00006437 for (auto *VE : C->varlists()) {
6438 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev758e55e2013-09-06 18:03:48 +00006439 if (EVar.isInvalid())
6440 return 0;
6441 Vars.push_back(EVar.take());
6442 }
6443 return getDerived().RebuildOMPSharedClause(Vars,
6444 C->getLocStart(),
6445 C->getLParenLoc(),
6446 C->getLocEnd());
6447}
6448
Alexey Bataevd48bcd82014-03-31 03:36:38 +00006449template<typename Derived>
6450OMPClause *
Alexander Musman8dba6642014-04-22 13:09:42 +00006451TreeTransform<Derived>::TransformOMPLinearClause(OMPLinearClause *C) {
6452 llvm::SmallVector<Expr *, 16> Vars;
6453 Vars.reserve(C->varlist_size());
6454 for (auto *VE : C->varlists()) {
6455 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
6456 if (EVar.isInvalid())
6457 return 0;
6458 Vars.push_back(EVar.take());
6459 }
6460 ExprResult Step = getDerived().TransformExpr(C->getStep());
6461 if (Step.isInvalid())
6462 return 0;
6463 return getDerived().RebuildOMPLinearClause(
6464 Vars, Step.take(), C->getLocStart(), C->getLParenLoc(), C->getColonLoc(),
6465 C->getLocEnd());
6466}
6467
6468template<typename Derived>
6469OMPClause *
Alexey Bataevd48bcd82014-03-31 03:36:38 +00006470TreeTransform<Derived>::TransformOMPCopyinClause(OMPCopyinClause *C) {
6471 llvm::SmallVector<Expr *, 16> Vars;
6472 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00006473 for (auto *VE : C->varlists()) {
6474 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd48bcd82014-03-31 03:36:38 +00006475 if (EVar.isInvalid())
6476 return 0;
6477 Vars.push_back(EVar.take());
6478 }
6479 return getDerived().RebuildOMPCopyinClause(Vars,
6480 C->getLocStart(),
6481 C->getLParenLoc(),
6482 C->getLocEnd());
6483}
6484
Douglas Gregorebe10102009-08-20 07:17:43 +00006485//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00006486// Expression transformation
6487//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00006488template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006489ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006490TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006491 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006492}
Mike Stump11289f42009-09-09 15:08:12 +00006493
6494template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006495ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006496TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregorea972d32011-02-28 21:54:11 +00006497 NestedNameSpecifierLoc QualifierLoc;
6498 if (E->getQualifierLoc()) {
6499 QualifierLoc
6500 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6501 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00006502 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00006503 }
John McCallce546572009-12-08 09:08:17 +00006504
6505 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006506 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6507 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006508 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00006509 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006510
John McCall815039a2010-08-17 21:27:17 +00006511 DeclarationNameInfo NameInfo = E->getNameInfo();
6512 if (NameInfo.getName()) {
6513 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6514 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00006515 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00006516 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006517
6518 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00006519 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00006520 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006521 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00006522 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00006523
6524 // Mark it referenced in the new context regardless.
6525 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00006526 SemaRef.MarkDeclRefReferenced(E);
John McCallce546572009-12-08 09:08:17 +00006527
John McCallc3007a22010-10-26 07:05:15 +00006528 return SemaRef.Owned(E);
Douglas Gregor4bd90e52009-10-23 18:54:35 +00006529 }
John McCallce546572009-12-08 09:08:17 +00006530
6531 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCallb3774b52010-08-19 23:49:38 +00006532 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00006533 TemplateArgs = &TransArgs;
6534 TransArgs.setLAngleLoc(E->getLAngleLoc());
6535 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006536 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6537 E->getNumTemplateArgs(),
6538 TransArgs))
6539 return ExprError();
John McCallce546572009-12-08 09:08:17 +00006540 }
6541
Chad Rosier1dcde962012-08-08 18:46:20 +00006542 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregorea972d32011-02-28 21:54:11 +00006543 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00006544}
Mike Stump11289f42009-09-09 15:08:12 +00006545
Douglas Gregora16548e2009-08-11 05:31:07 +00006546template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006547ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006548TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00006549 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006550}
Mike Stump11289f42009-09-09 15:08:12 +00006551
Douglas Gregora16548e2009-08-11 05:31:07 +00006552template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006553ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006554TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00006555 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006556}
Mike Stump11289f42009-09-09 15:08:12 +00006557
Douglas Gregora16548e2009-08-11 05:31:07 +00006558template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006559ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006560TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00006561 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006562}
Mike Stump11289f42009-09-09 15:08:12 +00006563
Douglas Gregora16548e2009-08-11 05:31:07 +00006564template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006565ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006566TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00006567 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006568}
Mike Stump11289f42009-09-09 15:08:12 +00006569
Douglas Gregora16548e2009-08-11 05:31:07 +00006570template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006571ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006572TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00006573 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006574}
6575
6576template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006577ExprResult
Richard Smithc67fdd42012-03-07 08:35:16 +00006578TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
Argyrios Kyrtzidis25049092013-04-09 01:17:02 +00006579 if (FunctionDecl *FD = E->getDirectCallee())
6580 SemaRef.MarkFunctionReferenced(E->getLocStart(), FD);
Richard Smithc67fdd42012-03-07 08:35:16 +00006581 return SemaRef.MaybeBindToTemporary(E);
6582}
6583
6584template<typename Derived>
6585ExprResult
Peter Collingbourne91147592011-04-15 00:35:48 +00006586TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
6587 ExprResult ControllingExpr =
6588 getDerived().TransformExpr(E->getControllingExpr());
6589 if (ControllingExpr.isInvalid())
6590 return ExprError();
6591
Chris Lattner01cf8db2011-07-20 06:58:45 +00006592 SmallVector<Expr *, 4> AssocExprs;
6593 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbourne91147592011-04-15 00:35:48 +00006594 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
6595 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
6596 if (TS) {
6597 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
6598 if (!AssocType)
6599 return ExprError();
6600 AssocTypes.push_back(AssocType);
6601 } else {
6602 AssocTypes.push_back(0);
6603 }
6604
6605 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
6606 if (AssocExpr.isInvalid())
6607 return ExprError();
6608 AssocExprs.push_back(AssocExpr.release());
6609 }
6610
6611 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
6612 E->getDefaultLoc(),
6613 E->getRParenLoc(),
6614 ControllingExpr.release(),
Dmitri Gribenko82360372013-05-10 13:06:58 +00006615 AssocTypes,
6616 AssocExprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00006617}
6618
6619template<typename Derived>
6620ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006621TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006622 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006623 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006624 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006625
Douglas Gregora16548e2009-08-11 05:31:07 +00006626 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006627 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006628
John McCallb268a282010-08-23 23:25:46 +00006629 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006630 E->getRParen());
6631}
6632
Richard Smithdb2630f2012-10-21 03:28:35 +00006633/// \brief The operand of a unary address-of operator has special rules: it's
6634/// allowed to refer to a non-static member of a class even if there's no 'this'
6635/// object available.
6636template<typename Derived>
6637ExprResult
6638TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
6639 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
6640 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true);
6641 else
6642 return getDerived().TransformExpr(E);
6643}
6644
Mike Stump11289f42009-09-09 15:08:12 +00006645template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006646ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006647TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smitheebe125f2013-05-21 23:29:46 +00006648 ExprResult SubExpr;
6649 if (E->getOpcode() == UO_AddrOf)
6650 SubExpr = TransformAddressOfOperand(E->getSubExpr());
6651 else
6652 SubExpr = TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006653 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006654 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006655
Douglas Gregora16548e2009-08-11 05:31:07 +00006656 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006657 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006658
Douglas Gregora16548e2009-08-11 05:31:07 +00006659 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
6660 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00006661 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006662}
Mike Stump11289f42009-09-09 15:08:12 +00006663
Douglas Gregora16548e2009-08-11 05:31:07 +00006664template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006665ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00006666TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
6667 // Transform the type.
6668 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
6669 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00006670 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006671
Douglas Gregor882211c2010-04-28 22:16:22 +00006672 // Transform all of the components into components similar to what the
6673 // parser uses.
Chad Rosier1dcde962012-08-08 18:46:20 +00006674 // FIXME: It would be slightly more efficient in the non-dependent case to
6675 // just map FieldDecls, rather than requiring the rebuilder to look for
6676 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00006677 // template code that we don't care.
6678 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00006679 typedef Sema::OffsetOfComponent Component;
Douglas Gregor882211c2010-04-28 22:16:22 +00006680 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner01cf8db2011-07-20 06:58:45 +00006681 SmallVector<Component, 4> Components;
Douglas Gregor882211c2010-04-28 22:16:22 +00006682 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
6683 const Node &ON = E->getComponent(I);
6684 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00006685 Comp.isBrackets = true;
Abramo Bagnara6b6f0512011-03-12 09:45:03 +00006686 Comp.LocStart = ON.getSourceRange().getBegin();
6687 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor882211c2010-04-28 22:16:22 +00006688 switch (ON.getKind()) {
6689 case Node::Array: {
6690 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00006691 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00006692 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006693 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006694
Douglas Gregor882211c2010-04-28 22:16:22 +00006695 ExprChanged = ExprChanged || Index.get() != FromIndex;
6696 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00006697 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00006698 break;
6699 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006700
Douglas Gregor882211c2010-04-28 22:16:22 +00006701 case Node::Field:
6702 case Node::Identifier:
6703 Comp.isBrackets = false;
6704 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00006705 if (!Comp.U.IdentInfo)
6706 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00006707
Douglas Gregor882211c2010-04-28 22:16:22 +00006708 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006709
Douglas Gregord1702062010-04-29 00:18:15 +00006710 case Node::Base:
6711 // Will be recomputed during the rebuild.
6712 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00006713 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006714
Douglas Gregor882211c2010-04-28 22:16:22 +00006715 Components.push_back(Comp);
6716 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006717
Douglas Gregor882211c2010-04-28 22:16:22 +00006718 // If nothing changed, retain the existing expression.
6719 if (!getDerived().AlwaysRebuild() &&
6720 Type == E->getTypeSourceInfo() &&
6721 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00006722 return SemaRef.Owned(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00006723
Douglas Gregor882211c2010-04-28 22:16:22 +00006724 // Build a new offsetof expression.
6725 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
6726 Components.data(), Components.size(),
6727 E->getRParenLoc());
6728}
6729
6730template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006731ExprResult
John McCall8d69a212010-11-15 23:31:06 +00006732TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
6733 assert(getDerived().AlreadyTransformed(E->getType()) &&
6734 "opaque value expression requires transformation");
6735 return SemaRef.Owned(E);
6736}
6737
6738template<typename Derived>
6739ExprResult
John McCallfe96e0b2011-11-06 09:01:30 +00006740TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCalle9290822011-11-30 04:42:31 +00006741 // Rebuild the syntactic form. The original syntactic form has
6742 // opaque-value expressions in it, so strip those away and rebuild
6743 // the result. This is a really awful way of doing this, but the
6744 // better solution (rebuilding the semantic expressions and
6745 // rebinding OVEs as necessary) doesn't work; we'd need
6746 // TreeTransform to not strip away implicit conversions.
6747 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
6748 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCallfe96e0b2011-11-06 09:01:30 +00006749 if (result.isInvalid()) return ExprError();
6750
6751 // If that gives us a pseudo-object result back, the pseudo-object
6752 // expression must have been an lvalue-to-rvalue conversion which we
6753 // should reapply.
6754 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
6755 result = SemaRef.checkPseudoObjectRValue(result.take());
6756
6757 return result;
6758}
6759
6760template<typename Derived>
6761ExprResult
Peter Collingbournee190dee2011-03-11 19:24:49 +00006762TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
6763 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006764 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00006765 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00006766
John McCallbcd03502009-12-07 02:54:59 +00006767 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00006768 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00006769 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006770
John McCall4c98fd82009-11-04 07:28:41 +00006771 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCallc3007a22010-10-26 07:05:15 +00006772 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006773
Peter Collingbournee190dee2011-03-11 19:24:49 +00006774 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
6775 E->getKind(),
6776 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00006777 }
Mike Stump11289f42009-09-09 15:08:12 +00006778
Eli Friedmane4f22df2012-02-29 04:03:55 +00006779 // C++0x [expr.sizeof]p1:
6780 // The operand is either an expression, which is an unevaluated operand
6781 // [...]
Eli Friedman15681d62012-09-26 04:34:21 +00006782 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
6783 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00006784
Eli Friedmane4f22df2012-02-29 04:03:55 +00006785 ExprResult SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
6786 if (SubExpr.isInvalid())
6787 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006788
Eli Friedmane4f22df2012-02-29 04:03:55 +00006789 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
6790 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006791
Peter Collingbournee190dee2011-03-11 19:24:49 +00006792 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
6793 E->getOperatorLoc(),
6794 E->getKind(),
6795 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00006796}
Mike Stump11289f42009-09-09 15:08:12 +00006797
Douglas Gregora16548e2009-08-11 05:31:07 +00006798template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006799ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006800TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006801 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006802 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006803 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006804
John McCalldadc5752010-08-24 06:29:42 +00006805 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006806 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006807 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006808
6809
Douglas Gregora16548e2009-08-11 05:31:07 +00006810 if (!getDerived().AlwaysRebuild() &&
6811 LHS.get() == E->getLHS() &&
6812 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00006813 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006814
John McCallb268a282010-08-23 23:25:46 +00006815 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006816 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00006817 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006818 E->getRBracketLoc());
6819}
Mike Stump11289f42009-09-09 15:08:12 +00006820
6821template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006822ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006823TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006824 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00006825 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00006826 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006827 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006828
6829 // Transform arguments.
6830 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006831 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00006832 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00006833 &ArgChanged))
6834 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006835
Douglas Gregora16548e2009-08-11 05:31:07 +00006836 if (!getDerived().AlwaysRebuild() &&
6837 Callee.get() == E->getCallee() &&
6838 !ArgChanged)
Dmitri Gribenko76bb5cabfa2012-09-10 21:20:09 +00006839 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00006840
Douglas Gregora16548e2009-08-11 05:31:07 +00006841 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00006842 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00006843 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00006844 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006845 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00006846 E->getRParenLoc());
6847}
Mike Stump11289f42009-09-09 15:08:12 +00006848
6849template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006850ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006851TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006852 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00006853 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006854 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006855
Douglas Gregorea972d32011-02-28 21:54:11 +00006856 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorf405d7e2009-08-31 23:41:50 +00006857 if (E->hasQualifier()) {
Douglas Gregorea972d32011-02-28 21:54:11 +00006858 QualifierLoc
6859 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00006860
Douglas Gregorea972d32011-02-28 21:54:11 +00006861 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00006862 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00006863 }
Abramo Bagnara7945c982012-01-27 09:46:47 +00006864 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00006865
Eli Friedman2cfcef62009-12-04 06:40:45 +00006866 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006867 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
6868 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006869 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00006870 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006871
John McCall16df1e52010-03-30 21:47:33 +00006872 NamedDecl *FoundDecl = E->getFoundDecl();
6873 if (FoundDecl == E->getMemberDecl()) {
6874 FoundDecl = Member;
6875 } else {
6876 FoundDecl = cast_or_null<NamedDecl>(
6877 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
6878 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00006879 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00006880 }
6881
Douglas Gregora16548e2009-08-11 05:31:07 +00006882 if (!getDerived().AlwaysRebuild() &&
6883 Base.get() == E->getBase() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00006884 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00006885 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00006886 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00006887 !E->hasExplicitTemplateArgs()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006888
Anders Carlsson9c45ad72009-12-22 05:24:09 +00006889 // Mark it referenced in the new context regardless.
6890 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00006891 SemaRef.MarkMemberReferenced(E);
6892
John McCallc3007a22010-10-26 07:05:15 +00006893 return SemaRef.Owned(E);
Anders Carlsson9c45ad72009-12-22 05:24:09 +00006894 }
Douglas Gregora16548e2009-08-11 05:31:07 +00006895
John McCall6b51f282009-11-23 01:53:49 +00006896 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00006897 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00006898 TransArgs.setLAngleLoc(E->getLAngleLoc());
6899 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006900 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6901 E->getNumTemplateArgs(),
6902 TransArgs))
6903 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00006904 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006905
Douglas Gregora16548e2009-08-11 05:31:07 +00006906 // FIXME: Bogus source location for the operator
Alp Tokerb6cc5922014-05-03 03:45:55 +00006907 SourceLocation FakeOperatorLoc =
6908 SemaRef.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00006909
John McCall38836f02010-01-15 08:34:02 +00006910 // FIXME: to do this check properly, we will need to preserve the
6911 // first-qualifier-in-scope here, just in case we had a dependent
6912 // base (and therefore couldn't do the check) and a
6913 // nested-name-qualifier (and therefore could do the lookup).
6914 NamedDecl *FirstQualifierInScope = 0;
6915
John McCallb268a282010-08-23 23:25:46 +00006916 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00006917 E->isArrow(),
Douglas Gregorea972d32011-02-28 21:54:11 +00006918 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00006919 TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006920 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00006921 Member,
John McCall16df1e52010-03-30 21:47:33 +00006922 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00006923 (E->hasExplicitTemplateArgs()
John McCall6b51f282009-11-23 01:53:49 +00006924 ? &TransArgs : 0),
John McCall38836f02010-01-15 08:34:02 +00006925 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00006926}
Mike Stump11289f42009-09-09 15:08:12 +00006927
Douglas Gregora16548e2009-08-11 05:31:07 +00006928template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006929ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006930TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00006931 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006932 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006933 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006934
John McCalldadc5752010-08-24 06:29:42 +00006935 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006936 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006937 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006938
Douglas Gregora16548e2009-08-11 05:31:07 +00006939 if (!getDerived().AlwaysRebuild() &&
6940 LHS.get() == E->getLHS() &&
6941 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00006942 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006943
Lang Hames5de91cc2012-10-02 04:45:10 +00006944 Sema::FPContractStateRAII FPContractState(getSema());
6945 getSema().FPFeatures.fp_contract = E->isFPContractable();
6946
Douglas Gregora16548e2009-08-11 05:31:07 +00006947 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00006948 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006949}
6950
Mike Stump11289f42009-09-09 15:08:12 +00006951template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006952ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006953TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00006954 CompoundAssignOperator *E) {
6955 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006956}
Mike Stump11289f42009-09-09 15:08:12 +00006957
Douglas Gregora16548e2009-08-11 05:31:07 +00006958template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00006959ExprResult TreeTransform<Derived>::
6960TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
6961 // Just rebuild the common and RHS expressions and see whether we
6962 // get any changes.
6963
6964 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
6965 if (commonExpr.isInvalid())
6966 return ExprError();
6967
6968 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
6969 if (rhs.isInvalid())
6970 return ExprError();
6971
6972 if (!getDerived().AlwaysRebuild() &&
6973 commonExpr.get() == e->getCommon() &&
6974 rhs.get() == e->getFalseExpr())
6975 return SemaRef.Owned(e);
6976
6977 return getDerived().RebuildConditionalOperator(commonExpr.take(),
6978 e->getQuestionLoc(),
6979 0,
6980 e->getColonLoc(),
6981 rhs.get());
6982}
6983
6984template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006985ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006986TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00006987 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00006988 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006989 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006990
John McCalldadc5752010-08-24 06:29:42 +00006991 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006992 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006993 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006994
John McCalldadc5752010-08-24 06:29:42 +00006995 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006996 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006997 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006998
Douglas Gregora16548e2009-08-11 05:31:07 +00006999 if (!getDerived().AlwaysRebuild() &&
7000 Cond.get() == E->getCond() &&
7001 LHS.get() == E->getLHS() &&
7002 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00007003 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007004
John McCallb268a282010-08-23 23:25:46 +00007005 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00007006 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00007007 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00007008 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00007009 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007010}
Mike Stump11289f42009-09-09 15:08:12 +00007011
7012template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007013ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007014TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00007015 // Implicit casts are eliminated during transformation, since they
7016 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00007017 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007018}
Mike Stump11289f42009-09-09 15:08:12 +00007019
Douglas Gregora16548e2009-08-11 05:31:07 +00007020template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007021ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007022TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007023 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7024 if (!Type)
7025 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007026
John McCalldadc5752010-08-24 06:29:42 +00007027 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00007028 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007029 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007030 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007031
Douglas Gregora16548e2009-08-11 05:31:07 +00007032 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007033 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007034 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00007035 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007036
John McCall97513962010-01-15 18:39:57 +00007037 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007038 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00007039 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007040 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007041}
Mike Stump11289f42009-09-09 15:08:12 +00007042
Douglas Gregora16548e2009-08-11 05:31:07 +00007043template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007044ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007045TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00007046 TypeSourceInfo *OldT = E->getTypeSourceInfo();
7047 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
7048 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00007049 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007050
John McCalldadc5752010-08-24 06:29:42 +00007051 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00007052 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007053 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007054
Douglas Gregora16548e2009-08-11 05:31:07 +00007055 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00007056 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007057 Init.get() == E->getInitializer())
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007058 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007059
John McCall5d7aa7f2010-01-19 22:33:45 +00007060 // Note: the expression type doesn't necessarily match the
7061 // type-as-written, but that's okay, because it should always be
7062 // derivable from the initializer.
7063
John McCalle15bbff2010-01-18 19:35:47 +00007064 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00007065 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00007066 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007067}
Mike Stump11289f42009-09-09 15:08:12 +00007068
Douglas Gregora16548e2009-08-11 05:31:07 +00007069template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007070ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007071TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007072 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00007073 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007074 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007075
Douglas Gregora16548e2009-08-11 05:31:07 +00007076 if (!getDerived().AlwaysRebuild() &&
7077 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007078 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007079
Douglas Gregora16548e2009-08-11 05:31:07 +00007080 // FIXME: Bad source location
Alp Tokerb6cc5922014-05-03 03:45:55 +00007081 SourceLocation FakeOperatorLoc =
7082 SemaRef.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00007083 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00007084 E->getAccessorLoc(),
7085 E->getAccessor());
7086}
Mike Stump11289f42009-09-09 15:08:12 +00007087
Douglas Gregora16548e2009-08-11 05:31:07 +00007088template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007089ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007090TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007091 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00007092
Benjamin Kramerf0623432012-08-23 22:51:59 +00007093 SmallVector<Expr*, 4> Inits;
Chad Rosier1dcde962012-08-08 18:46:20 +00007094 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00007095 Inits, &InitChanged))
7096 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007097
Douglas Gregora16548e2009-08-11 05:31:07 +00007098 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCallc3007a22010-10-26 07:05:15 +00007099 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007100
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007101 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00007102 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00007103}
Mike Stump11289f42009-09-09 15:08:12 +00007104
Douglas Gregora16548e2009-08-11 05:31:07 +00007105template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007106ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007107TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007108 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00007109
Douglas Gregorebe10102009-08-20 07:17:43 +00007110 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00007111 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00007112 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007113 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007114
Douglas Gregorebe10102009-08-20 07:17:43 +00007115 // transform the designators.
Benjamin Kramerf0623432012-08-23 22:51:59 +00007116 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregora16548e2009-08-11 05:31:07 +00007117 bool ExprChanged = false;
7118 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
7119 DEnd = E->designators_end();
7120 D != DEnd; ++D) {
7121 if (D->isFieldDesignator()) {
7122 Desig.AddDesignator(Designator::getField(D->getFieldName(),
7123 D->getDotLoc(),
7124 D->getFieldLoc()));
7125 continue;
7126 }
Mike Stump11289f42009-09-09 15:08:12 +00007127
Douglas Gregora16548e2009-08-11 05:31:07 +00007128 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00007129 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00007130 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007131 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007132
7133 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007134 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00007135
Douglas Gregora16548e2009-08-11 05:31:07 +00007136 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
7137 ArrayExprs.push_back(Index.release());
7138 continue;
7139 }
Mike Stump11289f42009-09-09 15:08:12 +00007140
Douglas Gregora16548e2009-08-11 05:31:07 +00007141 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00007142 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00007143 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
7144 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007145 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007146
John McCalldadc5752010-08-24 06:29:42 +00007147 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00007148 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007149 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007150
7151 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007152 End.get(),
7153 D->getLBracketLoc(),
7154 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00007155
Douglas Gregora16548e2009-08-11 05:31:07 +00007156 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
7157 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00007158
Douglas Gregora16548e2009-08-11 05:31:07 +00007159 ArrayExprs.push_back(Start.release());
7160 ArrayExprs.push_back(End.release());
7161 }
Mike Stump11289f42009-09-09 15:08:12 +00007162
Douglas Gregora16548e2009-08-11 05:31:07 +00007163 if (!getDerived().AlwaysRebuild() &&
7164 Init.get() == E->getInit() &&
7165 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00007166 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007167
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007168 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00007169 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00007170 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007171}
Mike Stump11289f42009-09-09 15:08:12 +00007172
Douglas Gregora16548e2009-08-11 05:31:07 +00007173template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007174ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007175TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007176 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00007177 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier1dcde962012-08-08 18:46:20 +00007178
Douglas Gregor3da3c062009-10-28 00:29:27 +00007179 // FIXME: Will we ever have proper type location here? Will we actually
7180 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00007181 QualType T = getDerived().TransformType(E->getType());
7182 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00007183 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007184
Douglas Gregora16548e2009-08-11 05:31:07 +00007185 if (!getDerived().AlwaysRebuild() &&
7186 T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00007187 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007188
Douglas Gregora16548e2009-08-11 05:31:07 +00007189 return getDerived().RebuildImplicitValueInitExpr(T);
7190}
Mike Stump11289f42009-09-09 15:08:12 +00007191
Douglas Gregora16548e2009-08-11 05:31:07 +00007192template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007193ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007194TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00007195 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
7196 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007197 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007198
John McCalldadc5752010-08-24 06:29:42 +00007199 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007200 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007201 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007202
Douglas Gregora16548e2009-08-11 05:31:07 +00007203 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00007204 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007205 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00007206 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007207
John McCallb268a282010-08-23 23:25:46 +00007208 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00007209 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007210}
7211
7212template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007213ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007214TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007215 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007216 SmallVector<Expr*, 4> Inits;
Douglas Gregora3efea12011-01-03 19:04:46 +00007217 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
7218 &ArgumentChanged))
7219 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007220
Douglas Gregora16548e2009-08-11 05:31:07 +00007221 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007222 Inits,
Douglas Gregora16548e2009-08-11 05:31:07 +00007223 E->getRParenLoc());
7224}
Mike Stump11289f42009-09-09 15:08:12 +00007225
Douglas Gregora16548e2009-08-11 05:31:07 +00007226/// \brief Transform an address-of-label expression.
7227///
7228/// By default, the transformation of an address-of-label expression always
7229/// rebuilds the expression, so that the label identifier can be resolved to
7230/// the corresponding label statement by semantic analysis.
7231template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007232ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007233TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +00007234 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
7235 E->getLabel());
7236 if (!LD)
7237 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007238
Douglas Gregora16548e2009-08-11 05:31:07 +00007239 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00007240 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +00007241}
Mike Stump11289f42009-09-09 15:08:12 +00007242
7243template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00007244ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007245TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalled7b2782012-04-06 18:20:53 +00007246 SemaRef.ActOnStartStmtExpr();
John McCalldadc5752010-08-24 06:29:42 +00007247 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00007248 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCalled7b2782012-04-06 18:20:53 +00007249 if (SubStmt.isInvalid()) {
7250 SemaRef.ActOnStmtExprError();
John McCallfaf5fb42010-08-26 23:41:50 +00007251 return ExprError();
John McCalled7b2782012-04-06 18:20:53 +00007252 }
Mike Stump11289f42009-09-09 15:08:12 +00007253
Douglas Gregora16548e2009-08-11 05:31:07 +00007254 if (!getDerived().AlwaysRebuild() &&
John McCalled7b2782012-04-06 18:20:53 +00007255 SubStmt.get() == E->getSubStmt()) {
7256 // Calling this an 'error' is unintuitive, but it does the right thing.
7257 SemaRef.ActOnStmtExprError();
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007258 return SemaRef.MaybeBindToTemporary(E);
John McCalled7b2782012-04-06 18:20:53 +00007259 }
Mike Stump11289f42009-09-09 15:08:12 +00007260
7261 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007262 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007263 E->getRParenLoc());
7264}
Mike Stump11289f42009-09-09 15:08:12 +00007265
Douglas Gregora16548e2009-08-11 05:31:07 +00007266template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007267ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007268TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007269 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00007270 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007271 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007272
John McCalldadc5752010-08-24 06:29:42 +00007273 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007274 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007275 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007276
John McCalldadc5752010-08-24 06:29:42 +00007277 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007278 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007279 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007280
Douglas Gregora16548e2009-08-11 05:31:07 +00007281 if (!getDerived().AlwaysRebuild() &&
7282 Cond.get() == E->getCond() &&
7283 LHS.get() == E->getLHS() &&
7284 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00007285 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007286
Douglas Gregora16548e2009-08-11 05:31:07 +00007287 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00007288 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007289 E->getRParenLoc());
7290}
Mike Stump11289f42009-09-09 15:08:12 +00007291
Douglas Gregora16548e2009-08-11 05:31:07 +00007292template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007293ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007294TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007295 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007296}
7297
7298template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007299ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007300TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007301 switch (E->getOperator()) {
7302 case OO_New:
7303 case OO_Delete:
7304 case OO_Array_New:
7305 case OO_Array_Delete:
7306 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier1dcde962012-08-08 18:46:20 +00007307
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007308 case OO_Call: {
7309 // This is a call to an object's operator().
7310 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
7311
7312 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00007313 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007314 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007315 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007316
7317 // FIXME: Poor location information
Alp Tokerb6cc5922014-05-03 03:45:55 +00007318 SourceLocation FakeLParenLoc = SemaRef.getLocForEndOfToken(
7319 static_cast<Expr *>(Object.get())->getLocEnd());
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007320
7321 // Transform the call arguments.
Benjamin Kramerf0623432012-08-23 22:51:59 +00007322 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00007323 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregora3efea12011-01-03 19:04:46 +00007324 Args))
7325 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007326
John McCallb268a282010-08-23 23:25:46 +00007327 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007328 Args,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007329 E->getLocEnd());
7330 }
7331
7332#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
7333 case OO_##Name:
7334#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
7335#include "clang/Basic/OperatorKinds.def"
7336 case OO_Subscript:
7337 // Handled below.
7338 break;
7339
7340 case OO_Conditional:
7341 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007342
7343 case OO_None:
7344 case NUM_OVERLOADED_OPERATORS:
7345 llvm_unreachable("not an overloaded operator?");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007346 }
7347
John McCalldadc5752010-08-24 06:29:42 +00007348 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00007349 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007350 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007351
Richard Smithdb2630f2012-10-21 03:28:35 +00007352 ExprResult First;
7353 if (E->getOperator() == OO_Amp)
7354 First = getDerived().TransformAddressOfOperand(E->getArg(0));
7355 else
7356 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00007357 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007358 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007359
John McCalldadc5752010-08-24 06:29:42 +00007360 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00007361 if (E->getNumArgs() == 2) {
7362 Second = getDerived().TransformExpr(E->getArg(1));
7363 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007364 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007365 }
Mike Stump11289f42009-09-09 15:08:12 +00007366
Douglas Gregora16548e2009-08-11 05:31:07 +00007367 if (!getDerived().AlwaysRebuild() &&
7368 Callee.get() == E->getCallee() &&
7369 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00007370 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007371 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00007372
Lang Hames5de91cc2012-10-02 04:45:10 +00007373 Sema::FPContractStateRAII FPContractState(getSema());
7374 getSema().FPFeatures.fp_contract = E->isFPContractable();
7375
Douglas Gregora16548e2009-08-11 05:31:07 +00007376 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
7377 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00007378 Callee.get(),
7379 First.get(),
7380 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007381}
Mike Stump11289f42009-09-09 15:08:12 +00007382
Douglas Gregora16548e2009-08-11 05:31:07 +00007383template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007384ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007385TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
7386 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007387}
Mike Stump11289f42009-09-09 15:08:12 +00007388
Douglas Gregora16548e2009-08-11 05:31:07 +00007389template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007390ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +00007391TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
7392 // Transform the callee.
7393 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
7394 if (Callee.isInvalid())
7395 return ExprError();
7396
7397 // Transform exec config.
7398 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
7399 if (EC.isInvalid())
7400 return ExprError();
7401
7402 // Transform arguments.
7403 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007404 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00007405 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00007406 &ArgChanged))
7407 return ExprError();
7408
7409 if (!getDerived().AlwaysRebuild() &&
7410 Callee.get() == E->getCallee() &&
7411 !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007412 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbourne41f85462011-02-09 21:07:24 +00007413
7414 // FIXME: Wrong source location information for the '('.
7415 SourceLocation FakeLParenLoc
7416 = ((Expr *)Callee.get())->getSourceRange().getBegin();
7417 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007418 Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00007419 E->getRParenLoc(), EC.get());
7420}
7421
7422template<typename Derived>
7423ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007424TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007425 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7426 if (!Type)
7427 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007428
John McCalldadc5752010-08-24 06:29:42 +00007429 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00007430 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007431 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007432 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007433
Douglas Gregora16548e2009-08-11 05:31:07 +00007434 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007435 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007436 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00007437 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007438 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00007439 E->getStmtClass(),
Fariborz Jahanianf0738712013-02-22 22:02:53 +00007440 E->getAngleBrackets().getBegin(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007441 Type,
Fariborz Jahanianf0738712013-02-22 22:02:53 +00007442 E->getAngleBrackets().getEnd(),
7443 // FIXME. this should be '(' location
7444 E->getAngleBrackets().getEnd(),
John McCallb268a282010-08-23 23:25:46 +00007445 SubExpr.get(),
Abramo Bagnara9fb43862012-10-15 21:08:58 +00007446 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007447}
Mike Stump11289f42009-09-09 15:08:12 +00007448
Douglas Gregora16548e2009-08-11 05:31:07 +00007449template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007450ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007451TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
7452 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007453}
Mike Stump11289f42009-09-09 15:08:12 +00007454
7455template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007456ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007457TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
7458 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00007459}
7460
Douglas Gregora16548e2009-08-11 05:31:07 +00007461template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007462ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007463TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007464 CXXReinterpretCastExpr *E) {
7465 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007466}
Mike Stump11289f42009-09-09 15:08:12 +00007467
Douglas Gregora16548e2009-08-11 05:31:07 +00007468template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007469ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007470TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
7471 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007472}
Mike Stump11289f42009-09-09 15:08:12 +00007473
Douglas Gregora16548e2009-08-11 05:31:07 +00007474template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007475ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007476TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007477 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007478 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7479 if (!Type)
7480 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007481
John McCalldadc5752010-08-24 06:29:42 +00007482 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00007483 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007484 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007485 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007486
Douglas Gregora16548e2009-08-11 05:31:07 +00007487 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007488 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007489 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00007490 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007491
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007492 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Eli Friedman89fe0d52013-08-15 22:02:56 +00007493 E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007494 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007495 E->getRParenLoc());
7496}
Mike Stump11289f42009-09-09 15:08:12 +00007497
Douglas Gregora16548e2009-08-11 05:31:07 +00007498template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007499ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007500TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007501 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00007502 TypeSourceInfo *TInfo
7503 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7504 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007505 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007506
Douglas Gregora16548e2009-08-11 05:31:07 +00007507 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00007508 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00007509 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007510
Douglas Gregor9da64192010-04-26 22:37:10 +00007511 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7512 E->getLocStart(),
7513 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00007514 E->getLocEnd());
7515 }
Mike Stump11289f42009-09-09 15:08:12 +00007516
Eli Friedman456f0182012-01-20 01:26:23 +00007517 // We don't know whether the subexpression is potentially evaluated until
7518 // after we perform semantic analysis. We speculatively assume it is
7519 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregora16548e2009-08-11 05:31:07 +00007520 // potentially evaluated.
Eli Friedman15681d62012-09-26 04:34:21 +00007521 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
7522 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00007523
John McCalldadc5752010-08-24 06:29:42 +00007524 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00007525 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007526 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007527
Douglas Gregora16548e2009-08-11 05:31:07 +00007528 if (!getDerived().AlwaysRebuild() &&
7529 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00007530 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007531
Douglas Gregor9da64192010-04-26 22:37:10 +00007532 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7533 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00007534 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007535 E->getLocEnd());
7536}
7537
7538template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007539ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00007540TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
7541 if (E->isTypeOperand()) {
7542 TypeSourceInfo *TInfo
7543 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7544 if (!TInfo)
7545 return ExprError();
7546
7547 if (!getDerived().AlwaysRebuild() &&
7548 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00007549 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00007550
Douglas Gregor69735112011-03-06 17:40:41 +00007551 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet9f4f2072010-09-08 12:20:18 +00007552 E->getLocStart(),
7553 TInfo,
7554 E->getLocEnd());
7555 }
7556
Francois Pichet9f4f2072010-09-08 12:20:18 +00007557 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7558
7559 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
7560 if (SubExpr.isInvalid())
7561 return ExprError();
7562
7563 if (!getDerived().AlwaysRebuild() &&
7564 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00007565 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00007566
7567 return getDerived().RebuildCXXUuidofExpr(E->getType(),
7568 E->getLocStart(),
7569 SubExpr.get(),
7570 E->getLocEnd());
7571}
7572
7573template<typename Derived>
7574ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007575TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007576 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007577}
Mike Stump11289f42009-09-09 15:08:12 +00007578
Douglas Gregora16548e2009-08-11 05:31:07 +00007579template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007580ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007581TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007582 CXXNullPtrLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007583 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007584}
Mike Stump11289f42009-09-09 15:08:12 +00007585
Douglas Gregora16548e2009-08-11 05:31:07 +00007586template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007587ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007588TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Richard Smithc3d2ebb2013-06-07 02:33:37 +00007589 QualType T = getSema().getCurrentThisType();
Mike Stump11289f42009-09-09 15:08:12 +00007590
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00007591 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
7592 // Make sure that we capture 'this'.
7593 getSema().CheckCXXThisCapture(E->getLocStart());
John McCallc3007a22010-10-26 07:05:15 +00007594 return SemaRef.Owned(E);
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00007595 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007596
Douglas Gregorb15af892010-01-07 23:12:05 +00007597 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00007598}
Mike Stump11289f42009-09-09 15:08:12 +00007599
Douglas Gregora16548e2009-08-11 05:31:07 +00007600template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007601ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007602TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007603 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007604 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007605 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007606
Douglas Gregora16548e2009-08-11 05:31:07 +00007607 if (!getDerived().AlwaysRebuild() &&
7608 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00007609 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007610
Douglas Gregor53e191ed2011-07-06 22:04:06 +00007611 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
7612 E->isThrownVariableInScope());
Douglas Gregora16548e2009-08-11 05:31:07 +00007613}
Mike Stump11289f42009-09-09 15:08:12 +00007614
Douglas Gregora16548e2009-08-11 05:31:07 +00007615template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007616ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007617TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00007618 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007619 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
7620 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007621 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00007622 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007623
Chandler Carruth794da4c2010-02-08 06:42:49 +00007624 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007625 Param == E->getParam())
John McCallc3007a22010-10-26 07:05:15 +00007626 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007627
Douglas Gregor033f6752009-12-23 23:03:06 +00007628 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00007629}
Mike Stump11289f42009-09-09 15:08:12 +00007630
Douglas Gregora16548e2009-08-11 05:31:07 +00007631template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007632ExprResult
Richard Smith852c9db2013-04-20 22:23:05 +00007633TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
7634 FieldDecl *Field
7635 = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(),
7636 E->getField()));
7637 if (!Field)
7638 return ExprError();
7639
7640 if (!getDerived().AlwaysRebuild() && Field == E->getField())
7641 return SemaRef.Owned(E);
7642
7643 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
7644}
7645
7646template<typename Derived>
7647ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00007648TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
7649 CXXScalarValueInitExpr *E) {
7650 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7651 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007652 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007653
Douglas Gregora16548e2009-08-11 05:31:07 +00007654 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00007655 T == E->getTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00007656 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007657
Chad Rosier1dcde962012-08-08 18:46:20 +00007658 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregor2b88c112010-09-08 00:15:04 +00007659 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00007660 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007661}
Mike Stump11289f42009-09-09 15:08:12 +00007662
Douglas Gregora16548e2009-08-11 05:31:07 +00007663template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007664ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007665TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007666 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00007667 TypeSourceInfo *AllocTypeInfo
7668 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
7669 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007670 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007671
Douglas Gregora16548e2009-08-11 05:31:07 +00007672 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00007673 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00007674 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007675 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007676
Douglas Gregora16548e2009-08-11 05:31:07 +00007677 // Transform the placement arguments (if any).
7678 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007679 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier1dcde962012-08-08 18:46:20 +00007680 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregora3efea12011-01-03 19:04:46 +00007681 E->getNumPlacementArgs(), true,
7682 PlacementArgs, &ArgumentChanged))
Sebastian Redl6047f072012-02-16 12:22:20 +00007683 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007684
Sebastian Redl6047f072012-02-16 12:22:20 +00007685 // Transform the initializer (if any).
7686 Expr *OldInit = E->getInitializer();
7687 ExprResult NewInit;
7688 if (OldInit)
7689 NewInit = getDerived().TransformExpr(OldInit);
7690 if (NewInit.isInvalid())
7691 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007692
Sebastian Redl6047f072012-02-16 12:22:20 +00007693 // Transform new operator and delete operator.
Douglas Gregord2d9da02010-02-26 00:38:10 +00007694 FunctionDecl *OperatorNew = 0;
7695 if (E->getOperatorNew()) {
7696 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007697 getDerived().TransformDecl(E->getLocStart(),
7698 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00007699 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00007700 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00007701 }
7702
7703 FunctionDecl *OperatorDelete = 0;
7704 if (E->getOperatorDelete()) {
7705 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007706 getDerived().TransformDecl(E->getLocStart(),
7707 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00007708 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00007709 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00007710 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007711
Douglas Gregora16548e2009-08-11 05:31:07 +00007712 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00007713 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007714 ArraySize.get() == E->getArraySize() &&
Sebastian Redl6047f072012-02-16 12:22:20 +00007715 NewInit.get() == OldInit &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00007716 OperatorNew == E->getOperatorNew() &&
7717 OperatorDelete == E->getOperatorDelete() &&
7718 !ArgumentChanged) {
7719 // Mark any declarations we need as referenced.
7720 // FIXME: instantiation-specific.
Douglas Gregord2d9da02010-02-26 00:38:10 +00007721 if (OperatorNew)
Eli Friedmanfa0df832012-02-02 03:46:19 +00007722 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregord2d9da02010-02-26 00:38:10 +00007723 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00007724 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00007725
Sebastian Redl6047f072012-02-16 12:22:20 +00007726 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor72912fb2011-07-26 15:11:03 +00007727 QualType ElementType
7728 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
7729 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
7730 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
7731 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedmanfa0df832012-02-02 03:46:19 +00007732 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor72912fb2011-07-26 15:11:03 +00007733 }
7734 }
7735 }
Sebastian Redl6047f072012-02-16 12:22:20 +00007736
John McCallc3007a22010-10-26 07:05:15 +00007737 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00007738 }
Mike Stump11289f42009-09-09 15:08:12 +00007739
Douglas Gregor0744ef62010-09-07 21:49:58 +00007740 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00007741 if (!ArraySize.get()) {
7742 // If no array size was specified, but the new expression was
7743 // instantiated with an array type (e.g., "new T" where T is
7744 // instantiated with "int[4]"), extract the outer bound from the
7745 // array type as our array size. We do this with constant and
7746 // dependently-sized array types.
7747 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
7748 if (!ArrayT) {
7749 // Do nothing
7750 } else if (const ConstantArrayType *ConsArrayT
7751 = dyn_cast<ConstantArrayType>(ArrayT)) {
Chad Rosier1dcde962012-08-08 18:46:20 +00007752 ArraySize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00007753 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
Chad Rosier1dcde962012-08-08 18:46:20 +00007754 ConsArrayT->getSize(),
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00007755 SemaRef.Context.getSizeType(),
7756 /*FIXME:*/E->getLocStart()));
Douglas Gregor2e9c7952009-12-22 17:13:37 +00007757 AllocType = ConsArrayT->getElementType();
7758 } else if (const DependentSizedArrayType *DepArrayT
7759 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
7760 if (DepArrayT->getSizeExpr()) {
John McCallc3007a22010-10-26 07:05:15 +00007761 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00007762 AllocType = DepArrayT->getElementType();
7763 }
7764 }
7765 }
Sebastian Redl6047f072012-02-16 12:22:20 +00007766
Douglas Gregora16548e2009-08-11 05:31:07 +00007767 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
7768 E->isGlobalNew(),
7769 /*FIXME:*/E->getLocStart(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007770 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00007771 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00007772 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007773 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00007774 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00007775 ArraySize.get(),
Sebastian Redl6047f072012-02-16 12:22:20 +00007776 E->getDirectInitRange(),
7777 NewInit.take());
Douglas Gregora16548e2009-08-11 05:31:07 +00007778}
Mike Stump11289f42009-09-09 15:08:12 +00007779
Douglas Gregora16548e2009-08-11 05:31:07 +00007780template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007781ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007782TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007783 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00007784 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007785 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007786
Douglas Gregord2d9da02010-02-26 00:38:10 +00007787 // Transform the delete operator, if known.
7788 FunctionDecl *OperatorDelete = 0;
7789 if (E->getOperatorDelete()) {
7790 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007791 getDerived().TransformDecl(E->getLocStart(),
7792 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00007793 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00007794 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00007795 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007796
Douglas Gregora16548e2009-08-11 05:31:07 +00007797 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00007798 Operand.get() == E->getArgument() &&
7799 OperatorDelete == E->getOperatorDelete()) {
7800 // Mark any declarations we need as referenced.
7801 // FIXME: instantiation-specific.
7802 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00007803 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00007804
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00007805 if (!E->getArgument()->isTypeDependent()) {
7806 QualType Destroyed = SemaRef.Context.getBaseElementType(
7807 E->getDestroyedType());
7808 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
7809 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +00007810 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedmanfa0df832012-02-02 03:46:19 +00007811 SemaRef.LookupDestructor(Record));
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00007812 }
7813 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007814
John McCallc3007a22010-10-26 07:05:15 +00007815 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00007816 }
Mike Stump11289f42009-09-09 15:08:12 +00007817
Douglas Gregora16548e2009-08-11 05:31:07 +00007818 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
7819 E->isGlobalDelete(),
7820 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00007821 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007822}
Mike Stump11289f42009-09-09 15:08:12 +00007823
Douglas Gregora16548e2009-08-11 05:31:07 +00007824template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007825ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00007826TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007827 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007828 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00007829 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007830 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007831
John McCallba7bf592010-08-24 05:47:05 +00007832 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00007833 bool MayBePseudoDestructor = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00007834 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00007835 E->getOperatorLoc(),
7836 E->isArrow()? tok::arrow : tok::period,
7837 ObjectTypePtr,
7838 MayBePseudoDestructor);
7839 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007840 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007841
John McCallba7bf592010-08-24 05:47:05 +00007842 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +00007843 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
7844 if (QualifierLoc) {
7845 QualifierLoc
7846 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
7847 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +00007848 return ExprError();
7849 }
Douglas Gregora6ce6082011-02-25 18:19:59 +00007850 CXXScopeSpec SS;
7851 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00007852
Douglas Gregor678f90d2010-02-25 01:56:36 +00007853 PseudoDestructorTypeStorage Destroyed;
7854 if (E->getDestroyedTypeInfo()) {
7855 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00007856 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregor579c15f2011-03-02 18:32:08 +00007857 ObjectType, 0, SS);
Douglas Gregor678f90d2010-02-25 01:56:36 +00007858 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007859 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00007860 Destroyed = DestroyedTypeInfo;
Douglas Gregorf39a8dd2011-11-09 02:19:47 +00007861 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregor678f90d2010-02-25 01:56:36 +00007862 // We aren't likely to be able to resolve the identifier down to a type
7863 // now anyway, so just retain the identifier.
7864 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
7865 E->getDestroyedTypeLoc());
7866 } else {
7867 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +00007868 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00007869 *E->getDestroyedTypeIdentifier(),
7870 E->getDestroyedTypeLoc(),
7871 /*Scope=*/0,
7872 SS, ObjectTypePtr,
7873 false);
7874 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007875 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007876
Douglas Gregor678f90d2010-02-25 01:56:36 +00007877 Destroyed
7878 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
7879 E->getDestroyedTypeLoc());
7880 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007881
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007882 TypeSourceInfo *ScopeTypeInfo = 0;
7883 if (E->getScopeTypeInfo()) {
Douglas Gregora88c55b2013-03-08 21:25:01 +00007884 CXXScopeSpec EmptySS;
7885 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
7886 E->getScopeTypeInfo(), ObjectType, 0, EmptySS);
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007887 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007888 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00007889 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007890
John McCallb268a282010-08-23 23:25:46 +00007891 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00007892 E->getOperatorLoc(),
7893 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +00007894 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007895 ScopeTypeInfo,
7896 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00007897 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00007898 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00007899}
Mike Stump11289f42009-09-09 15:08:12 +00007900
Douglas Gregorad8a3362009-09-04 17:36:40 +00007901template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007902ExprResult
John McCalld14a8642009-11-21 08:51:07 +00007903TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007904 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00007905 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
7906 Sema::LookupOrdinaryName);
7907
7908 // Transform all the decls.
7909 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
7910 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007911 NamedDecl *InstD = static_cast<NamedDecl*>(
7912 getDerived().TransformDecl(Old->getNameLoc(),
7913 *I));
John McCall84d87672009-12-10 09:41:52 +00007914 if (!InstD) {
7915 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7916 // This can happen because of dependent hiding.
7917 if (isa<UsingShadowDecl>(*I))
7918 continue;
Serge Pavlov82605302013-09-04 04:50:29 +00007919 else {
7920 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00007921 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00007922 }
John McCall84d87672009-12-10 09:41:52 +00007923 }
John McCalle66edc12009-11-24 19:00:30 +00007924
7925 // Expand using declarations.
7926 if (isa<UsingDecl>(InstD)) {
7927 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +00007928 for (auto *I : UD->shadows())
7929 R.addDecl(I);
John McCalle66edc12009-11-24 19:00:30 +00007930 continue;
7931 }
7932
7933 R.addDecl(InstD);
7934 }
7935
7936 // Resolve a kind, but don't do any further analysis. If it's
7937 // ambiguous, the callee needs to deal with it.
7938 R.resolveKind();
7939
7940 // Rebuild the nested-name qualifier, if present.
7941 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00007942 if (Old->getQualifierLoc()) {
7943 NestedNameSpecifierLoc QualifierLoc
7944 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7945 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007946 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007947
Douglas Gregor0da1d432011-02-28 20:01:57 +00007948 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00007949 }
7950
Douglas Gregor9262f472010-04-27 18:19:34 +00007951 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00007952 CXXRecordDecl *NamingClass
7953 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
7954 Old->getNameLoc(),
7955 Old->getNamingClass()));
Serge Pavlov82605302013-09-04 04:50:29 +00007956 if (!NamingClass) {
7957 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00007958 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00007959 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007960
Douglas Gregorda7be082010-04-27 16:10:10 +00007961 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00007962 }
7963
Abramo Bagnara7945c982012-01-27 09:46:47 +00007964 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
7965
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00007966 // If we have neither explicit template arguments, nor the template keyword,
7967 // it's a normal declaration name.
7968 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
John McCalle66edc12009-11-24 19:00:30 +00007969 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
7970
7971 // If we have template arguments, rebuild them, then rebuild the
7972 // templateid expression.
7973 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola3dd531d2012-08-28 04:13:54 +00007974 if (Old->hasExplicitTemplateArgs() &&
7975 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregor62e06f22010-12-20 17:31:10 +00007976 Old->getNumTemplateArgs(),
Serge Pavlov82605302013-09-04 04:50:29 +00007977 TransArgs)) {
7978 R.clear();
Douglas Gregor62e06f22010-12-20 17:31:10 +00007979 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00007980 }
John McCalle66edc12009-11-24 19:00:30 +00007981
Abramo Bagnara7945c982012-01-27 09:46:47 +00007982 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00007983 Old->requiresADL(), &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00007984}
Mike Stump11289f42009-09-09 15:08:12 +00007985
Douglas Gregora16548e2009-08-11 05:31:07 +00007986template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007987ExprResult
Douglas Gregor29c42f22012-02-24 07:38:34 +00007988TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
7989 bool ArgChanged = false;
Dmitri Gribenkof8579502013-01-12 19:30:44 +00007990 SmallVector<TypeSourceInfo *, 4> Args;
Douglas Gregor29c42f22012-02-24 07:38:34 +00007991 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
7992 TypeSourceInfo *From = E->getArg(I);
7993 TypeLoc FromTL = From->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00007994 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
Douglas Gregor29c42f22012-02-24 07:38:34 +00007995 TypeLocBuilder TLB;
7996 TLB.reserve(FromTL.getFullDataSize());
7997 QualType To = getDerived().TransformType(TLB, FromTL);
7998 if (To.isNull())
7999 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008000
Douglas Gregor29c42f22012-02-24 07:38:34 +00008001 if (To == From->getType())
8002 Args.push_back(From);
8003 else {
8004 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8005 ArgChanged = true;
8006 }
8007 continue;
8008 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008009
Douglas Gregor29c42f22012-02-24 07:38:34 +00008010 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00008011
Douglas Gregor29c42f22012-02-24 07:38:34 +00008012 // We have a pack expansion. Instantiate it.
David Blaikie6adc78e2013-02-18 22:06:02 +00008013 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
Douglas Gregor29c42f22012-02-24 07:38:34 +00008014 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
8015 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
8016 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00008017
Douglas Gregor29c42f22012-02-24 07:38:34 +00008018 // Determine whether the set of unexpanded parameter packs can and should
8019 // be expanded.
8020 bool Expand = true;
8021 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00008022 Optional<unsigned> OrigNumExpansions =
8023 ExpansionTL.getTypePtr()->getNumExpansions();
8024 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor29c42f22012-02-24 07:38:34 +00008025 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
8026 PatternTL.getSourceRange(),
8027 Unexpanded,
8028 Expand, RetainExpansion,
8029 NumExpansions))
8030 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008031
Douglas Gregor29c42f22012-02-24 07:38:34 +00008032 if (!Expand) {
8033 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00008034 // transformation on the pack expansion, producing another pack
Douglas Gregor29c42f22012-02-24 07:38:34 +00008035 // expansion.
8036 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier1dcde962012-08-08 18:46:20 +00008037
Douglas Gregor29c42f22012-02-24 07:38:34 +00008038 TypeLocBuilder TLB;
8039 TLB.reserve(From->getTypeLoc().getFullDataSize());
8040
8041 QualType To = getDerived().TransformType(TLB, PatternTL);
8042 if (To.isNull())
8043 return ExprError();
8044
Chad Rosier1dcde962012-08-08 18:46:20 +00008045 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00008046 PatternTL.getSourceRange(),
8047 ExpansionTL.getEllipsisLoc(),
8048 NumExpansions);
8049 if (To.isNull())
8050 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008051
Douglas Gregor29c42f22012-02-24 07:38:34 +00008052 PackExpansionTypeLoc ToExpansionTL
8053 = TLB.push<PackExpansionTypeLoc>(To);
8054 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8055 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8056 continue;
8057 }
8058
8059 // Expand the pack expansion by substituting for each argument in the
8060 // pack(s).
8061 for (unsigned I = 0; I != *NumExpansions; ++I) {
8062 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
8063 TypeLocBuilder TLB;
8064 TLB.reserve(PatternTL.getFullDataSize());
8065 QualType To = getDerived().TransformType(TLB, PatternTL);
8066 if (To.isNull())
8067 return ExprError();
8068
Eli Friedman5e05c4a2013-07-19 21:49:32 +00008069 if (To->containsUnexpandedParameterPack()) {
8070 To = getDerived().RebuildPackExpansionType(To,
8071 PatternTL.getSourceRange(),
8072 ExpansionTL.getEllipsisLoc(),
8073 NumExpansions);
8074 if (To.isNull())
8075 return ExprError();
8076
8077 PackExpansionTypeLoc ToExpansionTL
8078 = TLB.push<PackExpansionTypeLoc>(To);
8079 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8080 }
8081
Douglas Gregor29c42f22012-02-24 07:38:34 +00008082 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8083 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008084
Douglas Gregor29c42f22012-02-24 07:38:34 +00008085 if (!RetainExpansion)
8086 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00008087
Douglas Gregor29c42f22012-02-24 07:38:34 +00008088 // If we're supposed to retain a pack expansion, do so by temporarily
8089 // forgetting the partially-substituted parameter pack.
8090 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
8091
8092 TypeLocBuilder TLB;
8093 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00008094
Douglas Gregor29c42f22012-02-24 07:38:34 +00008095 QualType To = getDerived().TransformType(TLB, PatternTL);
8096 if (To.isNull())
8097 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008098
8099 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00008100 PatternTL.getSourceRange(),
8101 ExpansionTL.getEllipsisLoc(),
8102 NumExpansions);
8103 if (To.isNull())
8104 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008105
Douglas Gregor29c42f22012-02-24 07:38:34 +00008106 PackExpansionTypeLoc ToExpansionTL
8107 = TLB.push<PackExpansionTypeLoc>(To);
8108 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8109 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8110 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008111
Douglas Gregor29c42f22012-02-24 07:38:34 +00008112 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8113 return SemaRef.Owned(E);
8114
8115 return getDerived().RebuildTypeTrait(E->getTrait(),
8116 E->getLocStart(),
8117 Args,
8118 E->getLocEnd());
8119}
8120
8121template<typename Derived>
8122ExprResult
John Wiegley6242b6a2011-04-28 00:16:57 +00008123TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
8124 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
8125 if (!T)
8126 return ExprError();
8127
8128 if (!getDerived().AlwaysRebuild() &&
8129 T == E->getQueriedTypeSourceInfo())
8130 return SemaRef.Owned(E);
8131
8132 ExprResult SubExpr;
8133 {
8134 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8135 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
8136 if (SubExpr.isInvalid())
8137 return ExprError();
8138
8139 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
8140 return SemaRef.Owned(E);
8141 }
8142
8143 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
8144 E->getLocStart(),
8145 T,
8146 SubExpr.get(),
8147 E->getLocEnd());
8148}
8149
8150template<typename Derived>
8151ExprResult
John Wiegleyf9f65842011-04-25 06:54:41 +00008152TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
8153 ExprResult SubExpr;
8154 {
8155 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8156 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
8157 if (SubExpr.isInvalid())
8158 return ExprError();
8159
8160 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
8161 return SemaRef.Owned(E);
8162 }
8163
8164 return getDerived().RebuildExpressionTrait(
8165 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
8166}
8167
8168template<typename Derived>
8169ExprResult
John McCall8cd78132009-11-19 22:55:06 +00008170TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008171 DependentScopeDeclRefExpr *E) {
Richard Smithdb2630f2012-10-21 03:28:35 +00008172 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand*/false);
8173}
8174
8175template<typename Derived>
8176ExprResult
8177TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
8178 DependentScopeDeclRefExpr *E,
8179 bool IsAddressOfOperand) {
Reid Kleckner916ac4d2013-10-15 18:38:02 +00008180 assert(E->getQualifierLoc());
Douglas Gregor3a43fd62011-02-25 20:49:16 +00008181 NestedNameSpecifierLoc QualifierLoc
8182 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
8183 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008184 return ExprError();
Abramo Bagnara7945c982012-01-27 09:46:47 +00008185 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00008186
John McCall31f82722010-11-12 08:19:04 +00008187 // TODO: If this is a conversion-function-id, verify that the
8188 // destination type name (if present) resolves the same way after
8189 // instantiation as it did in the local scope.
8190
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008191 DeclarationNameInfo NameInfo
8192 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
8193 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00008194 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008195
John McCalle66edc12009-11-24 19:00:30 +00008196 if (!E->hasExplicitTemplateArgs()) {
8197 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3a43fd62011-02-25 20:49:16 +00008198 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008199 // Note: it is sufficient to compare the Name component of NameInfo:
8200 // if name has not changed, DNLoc has not changed either.
8201 NameInfo.getName() == E->getDeclName())
John McCallc3007a22010-10-26 07:05:15 +00008202 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00008203
Douglas Gregor3a43fd62011-02-25 20:49:16 +00008204 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008205 TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008206 NameInfo,
Richard Smithdb2630f2012-10-21 03:28:35 +00008207 /*TemplateArgs*/ 0,
8208 IsAddressOfOperand);
Douglas Gregord019ff62009-10-22 17:20:55 +00008209 }
John McCall6b51f282009-11-23 01:53:49 +00008210
8211 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008212 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8213 E->getNumTemplateArgs(),
8214 TransArgs))
8215 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008216
Douglas Gregor3a43fd62011-02-25 20:49:16 +00008217 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008218 TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008219 NameInfo,
Richard Smithdb2630f2012-10-21 03:28:35 +00008220 &TransArgs,
8221 IsAddressOfOperand);
Douglas Gregora16548e2009-08-11 05:31:07 +00008222}
8223
8224template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008225ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008226TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithd59b8322012-12-19 01:39:02 +00008227 // CXXConstructExprs other than for list-initialization and
8228 // CXXTemporaryObjectExpr are always implicit, so when we have
8229 // a 1-argument construction we just transform that argument.
Richard Smithdd2ca572012-11-26 08:32:48 +00008230 if ((E->getNumArgs() == 1 ||
8231 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithd59b8322012-12-19 01:39:02 +00008232 (!getDerived().DropCallArgument(E->getArg(0))) &&
8233 !E->isListInitialization())
Douglas Gregordb56b912010-02-03 03:01:57 +00008234 return getDerived().TransformExpr(E->getArg(0));
8235
Douglas Gregora16548e2009-08-11 05:31:07 +00008236 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
8237
8238 QualType T = getDerived().TransformType(E->getType());
8239 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00008240 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008241
8242 CXXConstructorDecl *Constructor
8243 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008244 getDerived().TransformDecl(E->getLocStart(),
8245 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008246 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00008247 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008248
Douglas Gregora16548e2009-08-11 05:31:07 +00008249 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008250 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00008251 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00008252 &ArgumentChanged))
8253 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008254
Douglas Gregora16548e2009-08-11 05:31:07 +00008255 if (!getDerived().AlwaysRebuild() &&
8256 T == E->getType() &&
8257 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00008258 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00008259 // Mark the constructor as referenced.
8260 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00008261 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00008262 return SemaRef.Owned(E);
Douglas Gregorde550352010-02-26 00:01:57 +00008263 }
Mike Stump11289f42009-09-09 15:08:12 +00008264
Douglas Gregordb121ba2009-12-14 16:27:04 +00008265 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
8266 Constructor, E->isElidable(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008267 Args,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00008268 E->hadMultipleCandidates(),
Richard Smithd59b8322012-12-19 01:39:02 +00008269 E->isListInitialization(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00008270 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00008271 E->getConstructionKind(),
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00008272 E->getParenOrBraceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00008273}
Mike Stump11289f42009-09-09 15:08:12 +00008274
Douglas Gregora16548e2009-08-11 05:31:07 +00008275/// \brief Transform a C++ temporary-binding expression.
8276///
Douglas Gregor363b1512009-12-24 18:51:59 +00008277/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
8278/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00008279template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008280ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008281TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00008282 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008283}
Mike Stump11289f42009-09-09 15:08:12 +00008284
John McCall5d413782010-12-06 08:20:24 +00008285/// \brief Transform a C++ expression that contains cleanups that should
8286/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +00008287///
John McCall5d413782010-12-06 08:20:24 +00008288/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +00008289/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00008290template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008291ExprResult
John McCall5d413782010-12-06 08:20:24 +00008292TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00008293 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008294}
Mike Stump11289f42009-09-09 15:08:12 +00008295
Douglas Gregora16548e2009-08-11 05:31:07 +00008296template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008297ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008298TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00008299 CXXTemporaryObjectExpr *E) {
8300 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8301 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00008302 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008303
Douglas Gregora16548e2009-08-11 05:31:07 +00008304 CXXConstructorDecl *Constructor
8305 = cast_or_null<CXXConstructorDecl>(
Chad Rosier1dcde962012-08-08 18:46:20 +00008306 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008307 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008308 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00008309 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008310
Douglas Gregora16548e2009-08-11 05:31:07 +00008311 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008312 SmallVector<Expr*, 8> Args;
Douglas Gregora16548e2009-08-11 05:31:07 +00008313 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +00008314 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00008315 &ArgumentChanged))
8316 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008317
Douglas Gregora16548e2009-08-11 05:31:07 +00008318 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00008319 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008320 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00008321 !ArgumentChanged) {
8322 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00008323 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00008324 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00008325 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008326
Richard Smithd59b8322012-12-19 01:39:02 +00008327 // FIXME: Pass in E->isListInitialization().
Douglas Gregor2b88c112010-09-08 00:15:04 +00008328 return getDerived().RebuildCXXTemporaryObjectExpr(T,
8329 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008330 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00008331 E->getLocEnd());
8332}
Mike Stump11289f42009-09-09 15:08:12 +00008333
Douglas Gregora16548e2009-08-11 05:31:07 +00008334template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008335ExprResult
Douglas Gregore31e6062012-02-07 10:09:13 +00008336TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008337
8338 // Transform any init-capture expressions before entering the scope of the
8339 // lambda body, because they are not semantically within that scope.
8340 SmallVector<InitCaptureInfoTy, 8> InitCaptureExprsAndTypes;
8341 InitCaptureExprsAndTypes.resize(E->explicit_capture_end() -
8342 E->explicit_capture_begin());
8343
8344 for (LambdaExpr::capture_iterator C = E->capture_begin(),
8345 CEnd = E->capture_end();
8346 C != CEnd; ++C) {
8347 if (!C->isInitCapture())
8348 continue;
8349 EnterExpressionEvaluationContext EEEC(getSema(),
8350 Sema::PotentiallyEvaluated);
8351 ExprResult NewExprInitResult = getDerived().TransformInitializer(
8352 C->getCapturedVar()->getInit(),
8353 C->getCapturedVar()->getInitStyle() == VarDecl::CallInit);
8354
8355 if (NewExprInitResult.isInvalid())
8356 return ExprError();
8357 Expr *NewExprInit = NewExprInitResult.get();
8358
8359 VarDecl *OldVD = C->getCapturedVar();
8360 QualType NewInitCaptureType =
8361 getSema().performLambdaInitCaptureInitialization(C->getLocation(),
8362 OldVD->getType()->isReferenceType(), OldVD->getIdentifier(),
8363 NewExprInit);
8364 NewExprInitResult = NewExprInit;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008365 InitCaptureExprsAndTypes[C - E->capture_begin()] =
8366 std::make_pair(NewExprInitResult, NewInitCaptureType);
8367
8368 }
8369
Faisal Vali524ca282013-11-12 01:40:44 +00008370 LambdaScopeInfo *LSI = getSema().PushLambdaScope();
Faisal Vali2cba1332013-10-23 06:44:28 +00008371 // Transform the template parameters, and add them to the current
8372 // instantiation scope. The null case is handled correctly.
8373 LSI->GLTemplateParameterList = getDerived().TransformTemplateParameterList(
8374 E->getTemplateParameterList());
8375
8376 // Check to see if the TypeSourceInfo of the call operator needs to
8377 // be transformed, and if so do the transformation in the
8378 // CurrentInstantiationScope.
8379
8380 TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo();
8381 FunctionProtoTypeLoc OldCallOpFPTL =
8382 OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>();
8383 TypeSourceInfo *NewCallOpTSI = 0;
8384
8385 const bool CallOpWasAlreadyTransformed =
8386 getDerived().AlreadyTransformed(OldCallOpTSI->getType());
8387
8388 // Use the Old Call Operator's TypeSourceInfo if it is already transformed.
8389 if (CallOpWasAlreadyTransformed)
8390 NewCallOpTSI = OldCallOpTSI;
8391 else {
8392 // Transform the TypeSourceInfo of the Original Lambda's Call Operator.
8393 // The transformation MUST be done in the CurrentInstantiationScope since
8394 // it introduces a mapping of the original to the newly created
8395 // transformed parameters.
8396
8397 TypeLocBuilder NewCallOpTLBuilder;
8398 QualType NewCallOpType = TransformFunctionProtoType(NewCallOpTLBuilder,
8399 OldCallOpFPTL,
8400 0, 0);
8401 NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context,
8402 NewCallOpType);
Faisal Vali2b391ab2013-09-26 19:54:12 +00008403 }
Faisal Vali2cba1332013-10-23 06:44:28 +00008404 // Extract the ParmVarDecls from the NewCallOpTSI and add them to
8405 // the vector below - this will be used to synthesize the
8406 // NewCallOperator. Additionally, add the parameters of the untransformed
8407 // lambda call operator to the CurrentInstantiationScope.
8408 SmallVector<ParmVarDecl *, 4> Params;
8409 {
8410 FunctionProtoTypeLoc NewCallOpFPTL =
8411 NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>();
8412 ParmVarDecl **NewParamDeclArray = NewCallOpFPTL.getParmArray();
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00008413 const unsigned NewNumArgs = NewCallOpFPTL.getNumParams();
Faisal Vali2cba1332013-10-23 06:44:28 +00008414
8415 for (unsigned I = 0; I < NewNumArgs; ++I) {
8416 // If this call operator's type does not require transformation,
8417 // the parameters do not get added to the current instantiation scope,
8418 // - so ADD them! This allows the following to compile when the enclosing
8419 // template is specialized and the entire lambda expression has to be
8420 // transformed.
8421 // template<class T> void foo(T t) {
8422 // auto L = [](auto a) {
8423 // auto M = [](char b) { <-- note: non-generic lambda
8424 // auto N = [](auto c) {
8425 // int x = sizeof(a);
8426 // x = sizeof(b); <-- specifically this line
8427 // x = sizeof(c);
8428 // };
8429 // };
8430 // };
8431 // }
8432 // foo('a')
8433 if (CallOpWasAlreadyTransformed)
8434 getDerived().transformedLocalDecl(NewParamDeclArray[I],
8435 NewParamDeclArray[I]);
8436 // Add to Params array, so these parameters can be used to create
8437 // the newly transformed call operator.
8438 Params.push_back(NewParamDeclArray[I]);
8439 }
8440 }
8441
8442 if (!NewCallOpTSI)
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008443 return ExprError();
8444
Eli Friedmand564afb2012-09-19 01:18:11 +00008445 // Create the local class that will describe the lambda.
8446 CXXRecordDecl *Class
8447 = getSema().createLambdaClosureType(E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +00008448 NewCallOpTSI,
Faisal Valic1a6dc42013-10-23 16:10:50 +00008449 /*KnownDependent=*/false,
8450 E->getCaptureDefault());
8451
Eli Friedmand564afb2012-09-19 01:18:11 +00008452 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
8453
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008454 // Build the call operator.
Faisal Vali2cba1332013-10-23 06:44:28 +00008455 CXXMethodDecl *NewCallOperator
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008456 = getSema().startLambdaDefinition(Class, E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +00008457 NewCallOpTSI,
Douglas Gregoradb376e2012-02-14 22:28:59 +00008458 E->getCallOperator()->getLocEnd(),
Richard Smith505df232012-07-22 23:45:10 +00008459 Params);
Faisal Vali2cba1332013-10-23 06:44:28 +00008460 LSI->CallOperator = NewCallOperator;
Rafael Espindola4b35f272013-10-04 14:28:51 +00008461
Faisal Vali2cba1332013-10-23 06:44:28 +00008462 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
8463
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008464 return getDerived().TransformLambdaScope(E, NewCallOperator,
8465 InitCaptureExprsAndTypes);
Richard Smith2589b9802012-07-25 03:56:55 +00008466}
8467
8468template<typename Derived>
8469ExprResult
8470TreeTransform<Derived>::TransformLambdaScope(LambdaExpr *E,
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008471 CXXMethodDecl *CallOperator,
8472 ArrayRef<InitCaptureInfoTy> InitCaptureExprsAndTypes) {
Richard Smithba71c082013-05-16 06:20:58 +00008473 bool Invalid = false;
8474
Douglas Gregorb4328232012-02-14 00:00:48 +00008475 // Introduce the context of the call operator.
Richard Smith7ff2bcb2014-01-24 01:54:52 +00008476 Sema::ContextRAII SavedContext(getSema(), CallOperator,
8477 /*NewThisContext*/false);
Douglas Gregorb4328232012-02-14 00:00:48 +00008478
Faisal Vali2b391ab2013-09-26 19:54:12 +00008479 LambdaScopeInfo *const LSI = getSema().getCurLambda();
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008480 // Enter the scope of the lambda.
Faisal Vali2b391ab2013-09-26 19:54:12 +00008481 getSema().buildLambdaScope(LSI, CallOperator, E->getIntroducerRange(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008482 E->getCaptureDefault(),
James Dennettddd36ff2013-08-09 23:08:25 +00008483 E->getCaptureDefaultLoc(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008484 E->hasExplicitParameters(),
8485 E->hasExplicitResultType(),
8486 E->isMutable());
Chad Rosier1dcde962012-08-08 18:46:20 +00008487
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008488 // Transform captures.
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008489 bool FinishedExplicitCaptures = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00008490 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008491 CEnd = E->capture_end();
8492 C != CEnd; ++C) {
8493 // When we hit the first implicit capture, tell Sema that we've finished
8494 // the list of explicit captures.
8495 if (!FinishedExplicitCaptures && C->isImplicit()) {
8496 getSema().finishLambdaExplicitCaptures(LSI);
8497 FinishedExplicitCaptures = true;
8498 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008499
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008500 // Capturing 'this' is trivial.
8501 if (C->capturesThis()) {
8502 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
8503 continue;
8504 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008505
Richard Smithba71c082013-05-16 06:20:58 +00008506 // Rebuild init-captures, including the implied field declaration.
8507 if (C->isInitCapture()) {
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008508
8509 InitCaptureInfoTy InitExprTypePair =
8510 InitCaptureExprsAndTypes[C - E->capture_begin()];
8511 ExprResult Init = InitExprTypePair.first;
8512 QualType InitQualType = InitExprTypePair.second;
8513 if (Init.isInvalid() || InitQualType.isNull()) {
Richard Smithba71c082013-05-16 06:20:58 +00008514 Invalid = true;
8515 continue;
8516 }
Richard Smithbb13c9a2013-09-28 04:02:39 +00008517 VarDecl *OldVD = C->getCapturedVar();
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008518 VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl(
8519 OldVD->getLocation(), InitExprTypePair.second,
8520 OldVD->getIdentifier(), Init.get());
Richard Smithbb13c9a2013-09-28 04:02:39 +00008521 if (!NewVD)
Richard Smithba71c082013-05-16 06:20:58 +00008522 Invalid = true;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008523 else {
Richard Smithbb13c9a2013-09-28 04:02:39 +00008524 getDerived().transformedLocalDecl(OldVD, NewVD);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008525 }
Richard Smithbb13c9a2013-09-28 04:02:39 +00008526 getSema().buildInitCaptureField(LSI, NewVD);
Richard Smithba71c082013-05-16 06:20:58 +00008527 continue;
8528 }
8529
8530 assert(C->capturesVariable() && "unexpected kind of lambda capture");
8531
Douglas Gregor3e308b12012-02-14 19:27:52 +00008532 // Determine the capture kind for Sema.
8533 Sema::TryCaptureKind Kind
8534 = C->isImplicit()? Sema::TryCapture_Implicit
8535 : C->getCaptureKind() == LCK_ByCopy
8536 ? Sema::TryCapture_ExplicitByVal
8537 : Sema::TryCapture_ExplicitByRef;
8538 SourceLocation EllipsisLoc;
8539 if (C->isPackExpansion()) {
8540 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
8541 bool ShouldExpand = false;
8542 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00008543 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +00008544 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
8545 C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +00008546 Unexpanded,
8547 ShouldExpand, RetainExpansion,
Richard Smithba71c082013-05-16 06:20:58 +00008548 NumExpansions)) {
8549 Invalid = true;
8550 continue;
8551 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008552
Douglas Gregor3e308b12012-02-14 19:27:52 +00008553 if (ShouldExpand) {
8554 // The transform has determined that we should perform an expansion;
8555 // transform and capture each of the arguments.
8556 // expansion of the pattern. Do so.
8557 VarDecl *Pack = C->getCapturedVar();
8558 for (unsigned I = 0; I != *NumExpansions; ++I) {
8559 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8560 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +00008561 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +00008562 Pack));
8563 if (!CapturedVar) {
8564 Invalid = true;
8565 continue;
8566 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008567
Douglas Gregor3e308b12012-02-14 19:27:52 +00008568 // Capture the transformed variable.
Chad Rosier1dcde962012-08-08 18:46:20 +00008569 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
8570 }
Douglas Gregor3e308b12012-02-14 19:27:52 +00008571 continue;
8572 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008573
Douglas Gregor3e308b12012-02-14 19:27:52 +00008574 EllipsisLoc = C->getEllipsisLoc();
8575 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008576
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008577 // Transform the captured variable.
8578 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +00008579 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008580 C->getCapturedVar()));
8581 if (!CapturedVar) {
8582 Invalid = true;
8583 continue;
8584 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008585
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008586 // Capture the transformed variable.
Douglas Gregorfdf598e2012-02-18 09:37:24 +00008587 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008588 }
8589 if (!FinishedExplicitCaptures)
8590 getSema().finishLambdaExplicitCaptures(LSI);
8591
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008592
8593 // Enter a new evaluation context to insulate the lambda from any
8594 // cleanups from the enclosing full-expression.
Chad Rosier1dcde962012-08-08 18:46:20 +00008595 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008596
8597 if (Invalid) {
Chad Rosier1dcde962012-08-08 18:46:20 +00008598 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008599 /*IsInstantiation=*/true);
8600 return ExprError();
8601 }
8602
8603 // Instantiate the body of the lambda expression.
Douglas Gregorb4328232012-02-14 00:00:48 +00008604 StmtResult Body = getDerived().TransformStmt(E->getBody());
8605 if (Body.isInvalid()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00008606 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
Douglas Gregorb4328232012-02-14 00:00:48 +00008607 /*IsInstantiation=*/true);
Chad Rosier1dcde962012-08-08 18:46:20 +00008608 return ExprError();
Douglas Gregorb4328232012-02-14 00:00:48 +00008609 }
Douglas Gregor7fcbd902012-02-21 00:37:24 +00008610
Chad Rosier1dcde962012-08-08 18:46:20 +00008611 return getSema().ActOnLambdaExpr(E->getLocStart(), Body.take(),
Douglas Gregorb61e8092012-04-04 17:40:10 +00008612 /*CurScope=*/0, /*IsInstantiation=*/true);
Douglas Gregore31e6062012-02-07 10:09:13 +00008613}
8614
8615template<typename Derived>
8616ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008617TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008618 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00008619 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8620 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00008621 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008622
Douglas Gregora16548e2009-08-11 05:31:07 +00008623 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008624 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +00008625 Args.reserve(E->arg_size());
Chad Rosier1dcde962012-08-08 18:46:20 +00008626 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00008627 &ArgumentChanged))
8628 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008629
Douglas Gregora16548e2009-08-11 05:31:07 +00008630 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00008631 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008632 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00008633 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00008634
Douglas Gregora16548e2009-08-11 05:31:07 +00008635 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +00008636 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +00008637 E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008638 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00008639 E->getRParenLoc());
8640}
Mike Stump11289f42009-09-09 15:08:12 +00008641
Douglas Gregora16548e2009-08-11 05:31:07 +00008642template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008643ExprResult
John McCall8cd78132009-11-19 22:55:06 +00008644TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008645 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008646 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00008647 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00008648 Expr *OldBase;
8649 QualType BaseType;
8650 QualType ObjectType;
8651 if (!E->isImplicitAccess()) {
8652 OldBase = E->getBase();
8653 Base = getDerived().TransformExpr(OldBase);
8654 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008655 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008656
John McCall2d74de92009-12-01 22:10:20 +00008657 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +00008658 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +00008659 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00008660 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00008661 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00008662 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00008663 ObjectTy,
8664 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00008665 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008666 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00008667
John McCallba7bf592010-08-24 05:47:05 +00008668 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +00008669 BaseType = ((Expr*) Base.get())->getType();
8670 } else {
8671 OldBase = 0;
8672 BaseType = getDerived().TransformType(E->getBaseType());
8673 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
8674 }
Mike Stump11289f42009-09-09 15:08:12 +00008675
Douglas Gregora5cb6da2009-10-20 05:58:46 +00008676 // Transform the first part of the nested-name-specifier that qualifies
8677 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00008678 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00008679 = getDerived().TransformFirstQualifierInScope(
Douglas Gregore16af532011-02-28 18:50:33 +00008680 E->getFirstQualifierFoundInScope(),
8681 E->getQualifierLoc().getBeginLoc());
Mike Stump11289f42009-09-09 15:08:12 +00008682
Douglas Gregore16af532011-02-28 18:50:33 +00008683 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00008684 if (E->getQualifier()) {
Douglas Gregore16af532011-02-28 18:50:33 +00008685 QualifierLoc
8686 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
8687 ObjectType,
8688 FirstQualifierInScope);
8689 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008690 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +00008691 }
Mike Stump11289f42009-09-09 15:08:12 +00008692
Abramo Bagnara7945c982012-01-27 09:46:47 +00008693 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
8694
John McCall31f82722010-11-12 08:19:04 +00008695 // TODO: If this is a conversion-function-id, verify that the
8696 // destination type name (if present) resolves the same way after
8697 // instantiation as it did in the local scope.
8698
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008699 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +00008700 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008701 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00008702 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008703
John McCall2d74de92009-12-01 22:10:20 +00008704 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00008705 // This is a reference to a member without an explicitly-specified
8706 // template argument list. Optimize for this common case.
8707 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00008708 Base.get() == OldBase &&
8709 BaseType == E->getBaseType() &&
Douglas Gregore16af532011-02-28 18:50:33 +00008710 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008711 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00008712 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCallc3007a22010-10-26 07:05:15 +00008713 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00008714
John McCallb268a282010-08-23 23:25:46 +00008715 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00008716 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00008717 E->isArrow(),
8718 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00008719 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008720 TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00008721 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008722 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00008723 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00008724 }
8725
John McCall6b51f282009-11-23 01:53:49 +00008726 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008727 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8728 E->getNumTemplateArgs(),
8729 TransArgs))
8730 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008731
John McCallb268a282010-08-23 23:25:46 +00008732 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00008733 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00008734 E->isArrow(),
8735 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00008736 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008737 TemplateKWLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +00008738 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008739 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00008740 &TransArgs);
8741}
8742
8743template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008744ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008745TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00008746 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00008747 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00008748 QualType BaseType;
8749 if (!Old->isImplicitAccess()) {
8750 Base = getDerived().TransformExpr(Old->getBase());
8751 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008752 return ExprError();
Richard Smithcab9a7d2011-10-26 19:06:56 +00008753 Base = getSema().PerformMemberExprBaseConversion(Base.take(),
8754 Old->isArrow());
8755 if (Base.isInvalid())
8756 return ExprError();
8757 BaseType = Base.get()->getType();
John McCall2d74de92009-12-01 22:10:20 +00008758 } else {
8759 BaseType = getDerived().TransformType(Old->getBaseType());
8760 }
John McCall10eae182009-11-30 22:42:35 +00008761
Douglas Gregor0da1d432011-02-28 20:01:57 +00008762 NestedNameSpecifierLoc QualifierLoc;
8763 if (Old->getQualifierLoc()) {
8764 QualifierLoc
8765 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
8766 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008767 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00008768 }
8769
Abramo Bagnara7945c982012-01-27 09:46:47 +00008770 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
8771
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008772 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +00008773 Sema::LookupOrdinaryName);
8774
8775 // Transform all the decls.
8776 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
8777 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008778 NamedDecl *InstD = static_cast<NamedDecl*>(
8779 getDerived().TransformDecl(Old->getMemberLoc(),
8780 *I));
John McCall84d87672009-12-10 09:41:52 +00008781 if (!InstD) {
8782 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
8783 // This can happen because of dependent hiding.
8784 if (isa<UsingShadowDecl>(*I))
8785 continue;
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00008786 else {
8787 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00008788 return ExprError();
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00008789 }
John McCall84d87672009-12-10 09:41:52 +00008790 }
John McCall10eae182009-11-30 22:42:35 +00008791
8792 // Expand using declarations.
8793 if (isa<UsingDecl>(InstD)) {
8794 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +00008795 for (auto *I : UD->shadows())
8796 R.addDecl(I);
John McCall10eae182009-11-30 22:42:35 +00008797 continue;
8798 }
8799
8800 R.addDecl(InstD);
8801 }
8802
8803 R.resolveKind();
8804
Douglas Gregor9262f472010-04-27 18:19:34 +00008805 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00008806 if (Old->getNamingClass()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00008807 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00008808 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00008809 Old->getMemberLoc(),
8810 Old->getNamingClass()));
8811 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00008812 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008813
Douglas Gregorda7be082010-04-27 16:10:10 +00008814 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00008815 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008816
John McCall10eae182009-11-30 22:42:35 +00008817 TemplateArgumentListInfo TransArgs;
8818 if (Old->hasExplicitTemplateArgs()) {
8819 TransArgs.setLAngleLoc(Old->getLAngleLoc());
8820 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008821 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
8822 Old->getNumTemplateArgs(),
8823 TransArgs))
8824 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00008825 }
John McCall38836f02010-01-15 08:34:02 +00008826
8827 // FIXME: to do this check properly, we will need to preserve the
8828 // first-qualifier-in-scope here, just in case we had a dependent
8829 // base (and therefore couldn't do the check) and a
8830 // nested-name-qualifier (and therefore could do the lookup).
8831 NamedDecl *FirstQualifierInScope = 0;
Chad Rosier1dcde962012-08-08 18:46:20 +00008832
John McCallb268a282010-08-23 23:25:46 +00008833 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00008834 BaseType,
John McCall10eae182009-11-30 22:42:35 +00008835 Old->getOperatorLoc(),
8836 Old->isArrow(),
Douglas Gregor0da1d432011-02-28 20:01:57 +00008837 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008838 TemplateKWLoc,
John McCall38836f02010-01-15 08:34:02 +00008839 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00008840 R,
8841 (Old->hasExplicitTemplateArgs()
8842 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00008843}
8844
8845template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008846ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +00008847TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Alexis Hunt414e3e32011-05-31 19:54:49 +00008848 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00008849 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
8850 if (SubExpr.isInvalid())
8851 return ExprError();
8852
8853 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCallc3007a22010-10-26 07:05:15 +00008854 return SemaRef.Owned(E);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00008855
8856 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
8857}
8858
8859template<typename Derived>
8860ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +00008861TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +00008862 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
8863 if (Pattern.isInvalid())
8864 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008865
Douglas Gregor0f836ea2011-01-13 00:19:55 +00008866 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
8867 return SemaRef.Owned(E);
8868
Douglas Gregorb8840002011-01-14 21:20:45 +00008869 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
8870 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +00008871}
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008872
8873template<typename Derived>
8874ExprResult
8875TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
8876 // If E is not value-dependent, then nothing will change when we transform it.
8877 // Note: This is an instantiation-centric view.
8878 if (!E->isValueDependent())
8879 return SemaRef.Owned(E);
8880
8881 // Note: None of the implementations of TryExpandParameterPacks can ever
8882 // produce a diagnostic when given only a single unexpanded parameter pack,
Chad Rosier1dcde962012-08-08 18:46:20 +00008883 // so
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008884 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
8885 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00008886 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00008887 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +00008888 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikieb9c168a2011-09-22 02:34:54 +00008889 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00008890 ShouldExpand, RetainExpansion,
8891 NumExpansions))
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008892 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008893
Douglas Gregorab96bcf2011-10-10 18:59:29 +00008894 if (RetainExpansion)
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008895 return SemaRef.Owned(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00008896
Douglas Gregorab96bcf2011-10-10 18:59:29 +00008897 NamedDecl *Pack = E->getPack();
8898 if (!ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00008899 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
Douglas Gregorab96bcf2011-10-10 18:59:29 +00008900 Pack));
8901 if (!Pack)
8902 return ExprError();
8903 }
8904
Chad Rosier1dcde962012-08-08 18:46:20 +00008905
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008906 // We now know the length of the parameter pack, so build a new expression
8907 // that stores that length.
Chad Rosier1dcde962012-08-08 18:46:20 +00008908 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
8909 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregorab96bcf2011-10-10 18:59:29 +00008910 NumExpansions);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008911}
8912
Douglas Gregore8e9dd62011-01-03 17:17:50 +00008913template<typename Derived>
8914ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +00008915TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
8916 SubstNonTypeTemplateParmPackExpr *E) {
8917 // Default behavior is to do nothing with this transformation.
8918 return SemaRef.Owned(E);
8919}
8920
8921template<typename Derived>
8922ExprResult
John McCall7c454bb2011-07-15 05:09:51 +00008923TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
8924 SubstNonTypeTemplateParmExpr *E) {
8925 // Default behavior is to do nothing with this transformation.
8926 return SemaRef.Owned(E);
8927}
8928
8929template<typename Derived>
8930ExprResult
Richard Smithb15fe3a2012-09-12 00:56:43 +00008931TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
8932 // Default behavior is to do nothing with this transformation.
8933 return SemaRef.Owned(E);
8934}
8935
8936template<typename Derived>
8937ExprResult
Douglas Gregorfe314812011-06-21 17:03:29 +00008938TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
8939 MaterializeTemporaryExpr *E) {
8940 return getDerived().TransformExpr(E->GetTemporaryExpr());
8941}
Chad Rosier1dcde962012-08-08 18:46:20 +00008942
Douglas Gregorfe314812011-06-21 17:03:29 +00008943template<typename Derived>
8944ExprResult
Richard Smithcc1b96d2013-06-12 22:31:48 +00008945TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
8946 CXXStdInitializerListExpr *E) {
8947 return getDerived().TransformExpr(E->getSubExpr());
8948}
8949
8950template<typename Derived>
8951ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008952TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00008953 return SemaRef.MaybeBindToTemporary(E);
8954}
8955
8956template<typename Derived>
8957ExprResult
8958TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Jordy Rose8986c5992012-03-12 17:53:02 +00008959 return SemaRef.Owned(E);
Ted Kremeneke65b0862012-03-06 20:05:56 +00008960}
8961
8962template<typename Derived>
8963ExprResult
Patrick Beard0caa3942012-04-19 00:25:12 +00008964TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
8965 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
8966 if (SubExpr.isInvalid())
8967 return ExprError();
8968
8969 if (!getDerived().AlwaysRebuild() &&
8970 SubExpr.get() == E->getSubExpr())
8971 return SemaRef.Owned(E);
8972
8973 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremeneke65b0862012-03-06 20:05:56 +00008974}
8975
8976template<typename Derived>
8977ExprResult
8978TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
8979 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +00008980 SmallVector<Expr *, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +00008981 bool ArgChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00008982 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremeneke65b0862012-03-06 20:05:56 +00008983 /*IsCall=*/false, Elements, &ArgChanged))
8984 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008985
Ted Kremeneke65b0862012-03-06 20:05:56 +00008986 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8987 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00008988
Ted Kremeneke65b0862012-03-06 20:05:56 +00008989 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
8990 Elements.data(),
8991 Elements.size());
8992}
8993
8994template<typename Derived>
8995ExprResult
8996TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier1dcde962012-08-08 18:46:20 +00008997 ObjCDictionaryLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00008998 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +00008999 SmallVector<ObjCDictionaryElement, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009000 bool ArgChanged = false;
9001 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
9002 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier1dcde962012-08-08 18:46:20 +00009003
Ted Kremeneke65b0862012-03-06 20:05:56 +00009004 if (OrigElement.isPackExpansion()) {
9005 // This key/value element is a pack expansion.
9006 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
9007 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
9008 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
9009 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
9010
9011 // Determine whether the set of unexpanded parameter packs can
9012 // and should be expanded.
9013 bool Expand = true;
9014 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00009015 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
9016 Optional<unsigned> NumExpansions = OrigNumExpansions;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009017 SourceRange PatternRange(OrigElement.Key->getLocStart(),
9018 OrigElement.Value->getLocEnd());
9019 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
9020 PatternRange,
9021 Unexpanded,
9022 Expand, RetainExpansion,
9023 NumExpansions))
9024 return ExprError();
9025
9026 if (!Expand) {
9027 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00009028 // transformation on the pack expansion, producing another pack
Ted Kremeneke65b0862012-03-06 20:05:56 +00009029 // expansion.
9030 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
9031 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
9032 if (Key.isInvalid())
9033 return ExprError();
9034
9035 if (Key.get() != OrigElement.Key)
9036 ArgChanged = true;
9037
9038 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
9039 if (Value.isInvalid())
9040 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009041
Ted Kremeneke65b0862012-03-06 20:05:56 +00009042 if (Value.get() != OrigElement.Value)
9043 ArgChanged = true;
9044
Chad Rosier1dcde962012-08-08 18:46:20 +00009045 ObjCDictionaryElement Expansion = {
Ted Kremeneke65b0862012-03-06 20:05:56 +00009046 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
9047 };
9048 Elements.push_back(Expansion);
9049 continue;
9050 }
9051
9052 // Record right away that the argument was changed. This needs
9053 // to happen even if the array expands to nothing.
9054 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009055
Ted Kremeneke65b0862012-03-06 20:05:56 +00009056 // The transform has determined that we should perform an elementwise
9057 // expansion of the pattern. Do so.
9058 for (unsigned I = 0; I != *NumExpansions; ++I) {
9059 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
9060 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
9061 if (Key.isInvalid())
9062 return ExprError();
9063
9064 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
9065 if (Value.isInvalid())
9066 return ExprError();
9067
Chad Rosier1dcde962012-08-08 18:46:20 +00009068 ObjCDictionaryElement Element = {
Ted Kremeneke65b0862012-03-06 20:05:56 +00009069 Key.get(), Value.get(), SourceLocation(), NumExpansions
9070 };
9071
9072 // If any unexpanded parameter packs remain, we still have a
9073 // pack expansion.
9074 if (Key.get()->containsUnexpandedParameterPack() ||
9075 Value.get()->containsUnexpandedParameterPack())
9076 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier1dcde962012-08-08 18:46:20 +00009077
Ted Kremeneke65b0862012-03-06 20:05:56 +00009078 Elements.push_back(Element);
9079 }
9080
9081 // We've finished with this pack expansion.
9082 continue;
9083 }
9084
9085 // Transform and check key.
9086 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
9087 if (Key.isInvalid())
9088 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009089
Ted Kremeneke65b0862012-03-06 20:05:56 +00009090 if (Key.get() != OrigElement.Key)
9091 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009092
Ted Kremeneke65b0862012-03-06 20:05:56 +00009093 // Transform and check value.
9094 ExprResult Value
9095 = getDerived().TransformExpr(OrigElement.Value);
9096 if (Value.isInvalid())
9097 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009098
Ted Kremeneke65b0862012-03-06 20:05:56 +00009099 if (Value.get() != OrigElement.Value)
9100 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009101
9102 ObjCDictionaryElement Element = {
David Blaikie7a30dc52013-02-21 01:47:18 +00009103 Key.get(), Value.get(), SourceLocation(), None
Ted Kremeneke65b0862012-03-06 20:05:56 +00009104 };
9105 Elements.push_back(Element);
9106 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009107
Ted Kremeneke65b0862012-03-06 20:05:56 +00009108 if (!getDerived().AlwaysRebuild() && !ArgChanged)
9109 return SemaRef.MaybeBindToTemporary(E);
9110
9111 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
9112 Elements.data(),
9113 Elements.size());
Douglas Gregora16548e2009-08-11 05:31:07 +00009114}
9115
Mike Stump11289f42009-09-09 15:08:12 +00009116template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009117ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009118TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00009119 TypeSourceInfo *EncodedTypeInfo
9120 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
9121 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009122 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009123
Douglas Gregora16548e2009-08-11 05:31:07 +00009124 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00009125 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00009126 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009127
9128 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00009129 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00009130 E->getRParenLoc());
9131}
Mike Stump11289f42009-09-09 15:08:12 +00009132
Douglas Gregora16548e2009-08-11 05:31:07 +00009133template<typename Derived>
John McCall31168b02011-06-15 23:02:42 +00009134ExprResult TreeTransform<Derived>::
9135TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
John McCallbc489892013-04-11 02:14:26 +00009136 // This is a kind of implicit conversion, and it needs to get dropped
9137 // and recomputed for the same general reasons that ImplicitCastExprs
9138 // do, as well a more specific one: this expression is only valid when
9139 // it appears *immediately* as an argument expression.
9140 return getDerived().TransformExpr(E->getSubExpr());
John McCall31168b02011-06-15 23:02:42 +00009141}
9142
9143template<typename Derived>
9144ExprResult TreeTransform<Derived>::
9145TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier1dcde962012-08-08 18:46:20 +00009146 TypeSourceInfo *TSInfo
John McCall31168b02011-06-15 23:02:42 +00009147 = getDerived().TransformType(E->getTypeInfoAsWritten());
9148 if (!TSInfo)
9149 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009150
John McCall31168b02011-06-15 23:02:42 +00009151 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier1dcde962012-08-08 18:46:20 +00009152 if (Result.isInvalid())
John McCall31168b02011-06-15 23:02:42 +00009153 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009154
John McCall31168b02011-06-15 23:02:42 +00009155 if (!getDerived().AlwaysRebuild() &&
9156 TSInfo == E->getTypeInfoAsWritten() &&
9157 Result.get() == E->getSubExpr())
9158 return SemaRef.Owned(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009159
John McCall31168b02011-06-15 23:02:42 +00009160 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier1dcde962012-08-08 18:46:20 +00009161 E->getBridgeKeywordLoc(), TSInfo,
John McCall31168b02011-06-15 23:02:42 +00009162 Result.get());
9163}
9164
9165template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009166ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009167TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009168 // Transform arguments.
9169 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009170 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +00009171 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +00009172 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009173 &ArgChanged))
9174 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009175
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009176 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
9177 // Class message: transform the receiver type.
9178 TypeSourceInfo *ReceiverTypeInfo
9179 = getDerived().TransformType(E->getClassReceiverTypeInfo());
9180 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009181 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009182
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009183 // If nothing changed, just retain the existing message send.
9184 if (!getDerived().AlwaysRebuild() &&
9185 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009186 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009187
9188 // Build a new class message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009189 SmallVector<SourceLocation, 16> SelLocs;
9190 E->getSelectorLocs(SelLocs);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009191 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
9192 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009193 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009194 E->getMethodDecl(),
9195 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009196 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009197 E->getRightLoc());
9198 }
9199
9200 // Instance message: transform the receiver
9201 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
9202 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +00009203 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009204 = getDerived().TransformExpr(E->getInstanceReceiver());
9205 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009206 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009207
9208 // If nothing changed, just retain the existing message send.
9209 if (!getDerived().AlwaysRebuild() &&
9210 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009211 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009212
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009213 // Build a new instance message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009214 SmallVector<SourceLocation, 16> SelLocs;
9215 E->getSelectorLocs(SelLocs);
John McCallb268a282010-08-23 23:25:46 +00009216 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009217 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009218 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009219 E->getMethodDecl(),
9220 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009221 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009222 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00009223}
9224
Mike Stump11289f42009-09-09 15:08:12 +00009225template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009226ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009227TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00009228 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009229}
9230
Mike Stump11289f42009-09-09 15:08:12 +00009231template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009232ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009233TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00009234 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009235}
9236
Mike Stump11289f42009-09-09 15:08:12 +00009237template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009238ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009239TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00009240 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00009241 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00009242 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009243 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +00009244
9245 // We don't need to transform the ivar; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +00009246
Douglas Gregord51d90d2010-04-26 20:11:03 +00009247 // If nothing changed, just retain the existing expression.
9248 if (!getDerived().AlwaysRebuild() &&
9249 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00009250 return SemaRef.Owned(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009251
John McCallb268a282010-08-23 23:25:46 +00009252 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00009253 E->getLocation(),
9254 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +00009255}
9256
Mike Stump11289f42009-09-09 15:08:12 +00009257template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009258ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009259TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +00009260 // 'super' and types never change. Property never changes. Just
9261 // retain the existing expression.
9262 if (!E->isObjectReceiver())
John McCallc3007a22010-10-26 07:05:15 +00009263 return SemaRef.Owned(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009264
Douglas Gregor9faee212010-04-26 20:47:02 +00009265 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00009266 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +00009267 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009268 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009269
Douglas Gregor9faee212010-04-26 20:47:02 +00009270 // We don't need to transform the property; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +00009271
Douglas Gregor9faee212010-04-26 20:47:02 +00009272 // If nothing changed, just retain the existing expression.
9273 if (!getDerived().AlwaysRebuild() &&
9274 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00009275 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009276
John McCallb7bd14f2010-12-02 01:19:52 +00009277 if (E->isExplicitProperty())
9278 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
9279 E->getExplicitProperty(),
9280 E->getLocation());
9281
9282 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall526ab472011-10-25 17:37:35 +00009283 SemaRef.Context.PseudoObjectTy,
John McCallb7bd14f2010-12-02 01:19:52 +00009284 E->getImplicitPropertyGetter(),
9285 E->getImplicitPropertySetter(),
9286 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00009287}
9288
Mike Stump11289f42009-09-09 15:08:12 +00009289template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009290ExprResult
Ted Kremeneke65b0862012-03-06 20:05:56 +00009291TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
9292 // Transform the base expression.
9293 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
9294 if (Base.isInvalid())
9295 return ExprError();
9296
9297 // Transform the key expression.
9298 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
9299 if (Key.isInvalid())
9300 return ExprError();
9301
9302 // If nothing changed, just retain the existing expression.
9303 if (!getDerived().AlwaysRebuild() &&
9304 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
9305 return SemaRef.Owned(E);
9306
Chad Rosier1dcde962012-08-08 18:46:20 +00009307 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremeneke65b0862012-03-06 20:05:56 +00009308 Base.get(), Key.get(),
9309 E->getAtIndexMethodDecl(),
9310 E->setAtIndexMethodDecl());
9311}
9312
9313template<typename Derived>
9314ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009315TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00009316 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00009317 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00009318 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009319 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009320
Douglas Gregord51d90d2010-04-26 20:11:03 +00009321 // If nothing changed, just retain the existing expression.
9322 if (!getDerived().AlwaysRebuild() &&
9323 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00009324 return SemaRef.Owned(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009325
John McCallb268a282010-08-23 23:25:46 +00009326 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00009327 E->getOpLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00009328 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +00009329}
9330
Mike Stump11289f42009-09-09 15:08:12 +00009331template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009332ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009333TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009334 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009335 SmallVector<Expr*, 8> SubExprs;
Douglas Gregora3efea12011-01-03 19:04:46 +00009336 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier1dcde962012-08-08 18:46:20 +00009337 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00009338 SubExprs, &ArgumentChanged))
9339 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009340
Douglas Gregora16548e2009-08-11 05:31:07 +00009341 if (!getDerived().AlwaysRebuild() &&
9342 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00009343 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00009344
Douglas Gregora16548e2009-08-11 05:31:07 +00009345 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009346 SubExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00009347 E->getRParenLoc());
9348}
9349
Mike Stump11289f42009-09-09 15:08:12 +00009350template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009351ExprResult
Hal Finkelc4d7c822013-09-18 03:29:45 +00009352TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) {
9353 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
9354 if (SrcExpr.isInvalid())
9355 return ExprError();
9356
9357 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
9358 if (!Type)
9359 return ExprError();
9360
9361 if (!getDerived().AlwaysRebuild() &&
9362 Type == E->getTypeSourceInfo() &&
9363 SrcExpr.get() == E->getSrcExpr())
9364 return SemaRef.Owned(E);
9365
9366 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
9367 SrcExpr.get(), Type,
9368 E->getRParenLoc());
9369}
9370
9371template<typename Derived>
9372ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009373TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +00009374 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier1dcde962012-08-08 18:46:20 +00009375
John McCall490112f2011-02-04 18:33:18 +00009376 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
9377 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
9378
9379 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahaniandd5eb9d2011-12-03 17:47:53 +00009380 blockScope->TheDecl->setBlockMissingReturnType(
9381 oldBlock->blockMissingReturnType());
Chad Rosier1dcde962012-08-08 18:46:20 +00009382
Chris Lattner01cf8db2011-07-20 06:58:45 +00009383 SmallVector<ParmVarDecl*, 4> params;
9384 SmallVector<QualType, 4> paramTypes;
Chad Rosier1dcde962012-08-08 18:46:20 +00009385
Fariborz Jahanian1babe772010-07-09 18:44:02 +00009386 // Parameter substitution.
John McCall490112f2011-02-04 18:33:18 +00009387 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
9388 oldBlock->param_begin(),
9389 oldBlock->param_size(),
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +00009390 0, paramTypes, &params)) {
9391 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009392 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +00009393 }
John McCall490112f2011-02-04 18:33:18 +00009394
Jordan Rosea0a86be2013-03-08 22:25:36 +00009395 const FunctionProtoType *exprFunctionType = E->getFunctionType();
Eli Friedman34b49062012-01-26 03:00:14 +00009396 QualType exprResultType =
Alp Toker314cc812014-01-25 16:55:45 +00009397 getDerived().TransformType(exprFunctionType->getReturnType());
Douglas Gregor476e3022011-01-19 21:32:01 +00009398
Jordan Rose5c382722013-03-08 21:51:21 +00009399 QualType functionType =
9400 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +00009401 exprFunctionType->getExtProtoInfo());
John McCall490112f2011-02-04 18:33:18 +00009402 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +00009403
9404 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +00009405 if (!params.empty())
David Blaikie9c70e042011-09-21 18:16:56 +00009406 blockScope->TheDecl->setParams(params);
Eli Friedman34b49062012-01-26 03:00:14 +00009407
9408 if (!oldBlock->blockMissingReturnType()) {
9409 blockScope->HasImplicitReturnType = false;
9410 blockScope->ReturnType = exprResultType;
9411 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009412
John McCall3882ace2011-01-05 12:14:39 +00009413 // Transform the body
John McCall490112f2011-02-04 18:33:18 +00009414 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +00009415 if (body.isInvalid()) {
9416 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
John McCall3882ace2011-01-05 12:14:39 +00009417 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +00009418 }
John McCall3882ace2011-01-05 12:14:39 +00009419
John McCall490112f2011-02-04 18:33:18 +00009420#ifndef NDEBUG
9421 // In builds with assertions, make sure that we captured everything we
9422 // captured before.
Douglas Gregor4385d8b2011-05-20 15:32:55 +00009423 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
Aaron Ballman9371dd22014-03-14 18:34:04 +00009424 for (const auto &I : oldBlock->captures()) {
9425 VarDecl *oldCapture = I.getVariable();
John McCall490112f2011-02-04 18:33:18 +00009426
Douglas Gregor4385d8b2011-05-20 15:32:55 +00009427 // Ignore parameter packs.
9428 if (isa<ParmVarDecl>(oldCapture) &&
9429 cast<ParmVarDecl>(oldCapture)->isParameterPack())
9430 continue;
John McCall490112f2011-02-04 18:33:18 +00009431
Douglas Gregor4385d8b2011-05-20 15:32:55 +00009432 VarDecl *newCapture =
9433 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
9434 oldCapture));
9435 assert(blockScope->CaptureMap.count(newCapture));
9436 }
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00009437 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCall490112f2011-02-04 18:33:18 +00009438 }
9439#endif
9440
9441 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
9442 /*Scope=*/0);
Douglas Gregora16548e2009-08-11 05:31:07 +00009443}
9444
Mike Stump11289f42009-09-09 15:08:12 +00009445template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009446ExprResult
Tanya Lattner55808c12011-06-04 00:47:47 +00009447TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikie83d382b2011-09-23 05:06:16 +00009448 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner55808c12011-06-04 00:47:47 +00009449}
Eli Friedmandf14b3a2011-10-11 02:20:01 +00009450
9451template<typename Derived>
9452ExprResult
9453TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedman8d3e43f2011-10-14 22:48:56 +00009454 QualType RetTy = getDerived().TransformType(E->getType());
9455 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009456 SmallVector<Expr*, 8> SubExprs;
Eli Friedman8d3e43f2011-10-14 22:48:56 +00009457 SubExprs.reserve(E->getNumSubExprs());
9458 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
9459 SubExprs, &ArgumentChanged))
9460 return ExprError();
9461
9462 if (!getDerived().AlwaysRebuild() &&
9463 !ArgumentChanged)
9464 return SemaRef.Owned(E);
9465
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009466 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedman8d3e43f2011-10-14 22:48:56 +00009467 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedmandf14b3a2011-10-11 02:20:01 +00009468}
Chad Rosier1dcde962012-08-08 18:46:20 +00009469
Douglas Gregora16548e2009-08-11 05:31:07 +00009470//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00009471// Type reconstruction
9472//===----------------------------------------------------------------------===//
9473
Mike Stump11289f42009-09-09 15:08:12 +00009474template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00009475QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
9476 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00009477 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009478 getDerived().getBaseEntity());
9479}
9480
Mike Stump11289f42009-09-09 15:08:12 +00009481template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00009482QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
9483 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00009484 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009485 getDerived().getBaseEntity());
9486}
9487
Mike Stump11289f42009-09-09 15:08:12 +00009488template<typename Derived>
9489QualType
John McCall70dd5f62009-10-30 00:06:24 +00009490TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
9491 bool WrittenAsLValue,
9492 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00009493 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +00009494 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00009495}
9496
9497template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009498QualType
John McCall70dd5f62009-10-30 00:06:24 +00009499TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
9500 QualType ClassType,
9501 SourceLocation Sigil) {
Reid Kleckner0503a872013-12-05 01:23:43 +00009502 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil,
9503 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00009504}
9505
9506template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009507QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00009508TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
9509 ArrayType::ArraySizeModifier SizeMod,
9510 const llvm::APInt *Size,
9511 Expr *SizeExpr,
9512 unsigned IndexTypeQuals,
9513 SourceRange BracketsRange) {
9514 if (SizeExpr || !Size)
9515 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
9516 IndexTypeQuals, BracketsRange,
9517 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00009518
9519 QualType Types[] = {
9520 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
9521 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
9522 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00009523 };
Craig Toppere5ce8312013-07-15 03:38:40 +00009524 const unsigned NumTypes = llvm::array_lengthof(Types);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009525 QualType SizeType;
9526 for (unsigned I = 0; I != NumTypes; ++I)
9527 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
9528 SizeType = Types[I];
9529 break;
9530 }
Mike Stump11289f42009-09-09 15:08:12 +00009531
Eli Friedman9562f392012-01-25 23:20:27 +00009532 // Note that we can return a VariableArrayType here in the case where
9533 // the element type was a dependent VariableArrayType.
9534 IntegerLiteral *ArraySize
9535 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
9536 /*FIXME*/BracketsRange.getBegin());
9537 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009538 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00009539 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00009540}
Mike Stump11289f42009-09-09 15:08:12 +00009541
Douglas Gregord6ff3322009-08-04 16:50:30 +00009542template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009543QualType
9544TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009545 ArrayType::ArraySizeModifier SizeMod,
9546 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00009547 unsigned IndexTypeQuals,
9548 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00009549 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00009550 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009551}
9552
9553template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009554QualType
Mike Stump11289f42009-09-09 15:08:12 +00009555TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009556 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00009557 unsigned IndexTypeQuals,
9558 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00009559 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00009560 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009561}
Mike Stump11289f42009-09-09 15:08:12 +00009562
Douglas Gregord6ff3322009-08-04 16:50:30 +00009563template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009564QualType
9565TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009566 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00009567 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009568 unsigned IndexTypeQuals,
9569 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00009570 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00009571 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009572 IndexTypeQuals, BracketsRange);
9573}
9574
9575template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009576QualType
9577TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009578 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00009579 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009580 unsigned IndexTypeQuals,
9581 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00009582 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00009583 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009584 IndexTypeQuals, BracketsRange);
9585}
9586
9587template<typename Derived>
9588QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +00009589 unsigned NumElements,
9590 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00009591 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +00009592 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009593}
Mike Stump11289f42009-09-09 15:08:12 +00009594
Douglas Gregord6ff3322009-08-04 16:50:30 +00009595template<typename Derived>
9596QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
9597 unsigned NumElements,
9598 SourceLocation AttributeLoc) {
9599 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
9600 NumElements, true);
9601 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00009602 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
9603 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +00009604 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009605}
Mike Stump11289f42009-09-09 15:08:12 +00009606
Douglas Gregord6ff3322009-08-04 16:50:30 +00009607template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009608QualType
9609TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +00009610 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009611 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +00009612 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009613}
Mike Stump11289f42009-09-09 15:08:12 +00009614
Douglas Gregord6ff3322009-08-04 16:50:30 +00009615template<typename Derived>
Jordan Rose5c382722013-03-08 21:51:21 +00009616QualType TreeTransform<Derived>::RebuildFunctionProtoType(
9617 QualType T,
9618 llvm::MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +00009619 const FunctionProtoType::ExtProtoInfo &EPI) {
9620 return SemaRef.BuildFunctionType(T, ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009621 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +00009622 getDerived().getBaseEntity(),
Jordan Rosea0a86be2013-03-08 22:25:36 +00009623 EPI);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009624}
Mike Stump11289f42009-09-09 15:08:12 +00009625
Douglas Gregord6ff3322009-08-04 16:50:30 +00009626template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00009627QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
9628 return SemaRef.Context.getFunctionNoProtoType(T);
9629}
9630
9631template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00009632QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
9633 assert(D && "no decl found");
9634 if (D->isInvalidDecl()) return QualType();
9635
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009636 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +00009637 TypeDecl *Ty;
9638 if (isa<UsingDecl>(D)) {
9639 UsingDecl *Using = cast<UsingDecl>(D);
Enea Zaffanellae05a3cf2013-07-22 10:54:09 +00009640 assert(Using->hasTypename() &&
John McCallb96ec562009-12-04 22:46:56 +00009641 "UnresolvedUsingTypenameDecl transformed to non-typename using");
9642
9643 // A valid resolved using typename decl points to exactly one type decl.
9644 assert(++Using->shadow_begin() == Using->shadow_end());
9645 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +00009646
John McCallb96ec562009-12-04 22:46:56 +00009647 } else {
9648 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
9649 "UnresolvedUsingTypenameDecl transformed to non-using decl");
9650 Ty = cast<UnresolvedUsingTypenameDecl>(D);
9651 }
9652
9653 return SemaRef.Context.getTypeDeclType(Ty);
9654}
9655
9656template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00009657QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
9658 SourceLocation Loc) {
9659 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009660}
9661
9662template<typename Derived>
9663QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
9664 return SemaRef.Context.getTypeOfType(Underlying);
9665}
9666
9667template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00009668QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
9669 SourceLocation Loc) {
9670 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009671}
9672
9673template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00009674QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
9675 UnaryTransformType::UTTKind UKind,
9676 SourceLocation Loc) {
9677 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
9678}
9679
9680template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00009681QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00009682 TemplateName Template,
9683 SourceLocation TemplateNameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +00009684 TemplateArgumentListInfo &TemplateArgs) {
John McCall6b51f282009-11-23 01:53:49 +00009685 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009686}
Mike Stump11289f42009-09-09 15:08:12 +00009687
Douglas Gregor1135c352009-08-06 05:28:30 +00009688template<typename Derived>
Eli Friedman0dfb8892011-10-06 23:00:33 +00009689QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
9690 SourceLocation KWLoc) {
9691 return SemaRef.BuildAtomicType(ValueType, KWLoc);
9692}
9693
9694template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009695TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00009696TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +00009697 bool TemplateKW,
9698 TemplateDecl *Template) {
Douglas Gregor9db53502011-03-02 18:07:45 +00009699 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00009700 Template);
9701}
9702
9703template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009704TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00009705TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
9706 const IdentifierInfo &Name,
9707 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +00009708 QualType ObjectType,
9709 NamedDecl *FirstQualifierInScope) {
Douglas Gregor9db53502011-03-02 18:07:45 +00009710 UnqualifiedId TemplateName;
9711 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregorbb119652010-06-16 23:00:59 +00009712 Sema::TemplateTy Template;
Abramo Bagnara7945c982012-01-27 09:46:47 +00009713 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregorbb119652010-06-16 23:00:59 +00009714 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009715 SS, TemplateKWLoc, TemplateName,
John McCallba7bf592010-08-24 05:47:05 +00009716 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00009717 /*EnteringContext=*/false,
9718 Template);
John McCall31f82722010-11-12 08:19:04 +00009719 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +00009720}
Mike Stump11289f42009-09-09 15:08:12 +00009721
Douglas Gregora16548e2009-08-11 05:31:07 +00009722template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00009723TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00009724TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +00009725 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +00009726 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +00009727 QualType ObjectType) {
Douglas Gregor71395fa2009-11-04 00:56:37 +00009728 UnqualifiedId Name;
Douglas Gregor9db53502011-03-02 18:07:45 +00009729 // FIXME: Bogus location information.
Abramo Bagnara7945c982012-01-27 09:46:47 +00009730 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregor9db53502011-03-02 18:07:45 +00009731 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnara7945c982012-01-27 09:46:47 +00009732 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregorbb119652010-06-16 23:00:59 +00009733 Sema::TemplateTy Template;
9734 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009735 SS, TemplateKWLoc, Name,
John McCallba7bf592010-08-24 05:47:05 +00009736 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00009737 /*EnteringContext=*/false,
9738 Template);
Serge Pavlov9ddb76e2013-08-27 13:15:56 +00009739 return Template.get();
Douglas Gregor71395fa2009-11-04 00:56:37 +00009740}
Chad Rosier1dcde962012-08-08 18:46:20 +00009741
Douglas Gregor71395fa2009-11-04 00:56:37 +00009742template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009743ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009744TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
9745 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00009746 Expr *OrigCallee,
9747 Expr *First,
9748 Expr *Second) {
9749 Expr *Callee = OrigCallee->IgnoreParenCasts();
9750 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00009751
Douglas Gregora16548e2009-08-11 05:31:07 +00009752 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00009753 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +00009754 if (!First->getType()->isOverloadableType() &&
9755 !Second->getType()->isOverloadableType())
9756 return getSema().CreateBuiltinArraySubscriptExpr(First,
9757 Callee->getLocStart(),
9758 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00009759 } else if (Op == OO_Arrow) {
9760 // -> is never a builtin operation.
John McCallb268a282010-08-23 23:25:46 +00009761 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
9762 } else if (Second == 0 || isPostIncDec) {
9763 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009764 // The argument is not of overloadable type, so try to create a
9765 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +00009766 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00009767 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00009768
John McCallb268a282010-08-23 23:25:46 +00009769 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00009770 }
9771 } else {
John McCallb268a282010-08-23 23:25:46 +00009772 if (!First->getType()->isOverloadableType() &&
9773 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009774 // Neither of the arguments is an overloadable type, so try to
9775 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +00009776 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00009777 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00009778 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +00009779 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009780 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009781
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009782 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00009783 }
9784 }
Mike Stump11289f42009-09-09 15:08:12 +00009785
9786 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00009787 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00009788 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00009789
John McCallb268a282010-08-23 23:25:46 +00009790 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +00009791 assert(ULE->requiresADL());
Richard Smith100b24a2014-04-17 01:52:14 +00009792 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00009793 } else {
Richard Smith58db83d2012-11-28 21:47:39 +00009794 // If we've resolved this to a particular non-member function, just call
9795 // that function. If we resolved it to a member function,
9796 // CreateOverloaded* will find that function for us.
9797 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
9798 if (!isa<CXXMethodDecl>(ND))
9799 Functions.addDecl(ND);
John McCalld14a8642009-11-21 08:51:07 +00009800 }
Mike Stump11289f42009-09-09 15:08:12 +00009801
Douglas Gregora16548e2009-08-11 05:31:07 +00009802 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +00009803 Expr *Args[2] = { First, Second };
9804 unsigned NumArgs = 1 + (Second != 0);
Mike Stump11289f42009-09-09 15:08:12 +00009805
Douglas Gregora16548e2009-08-11 05:31:07 +00009806 // Create the overloaded operator invocation for unary operators.
9807 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +00009808 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00009809 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +00009810 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00009811 }
Mike Stump11289f42009-09-09 15:08:12 +00009812
Douglas Gregore9d62932011-07-15 16:25:15 +00009813 if (Op == OO_Subscript) {
9814 SourceLocation LBrace;
9815 SourceLocation RBrace;
9816
9817 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
9818 DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
9819 LBrace = SourceLocation::getFromRawEncoding(
9820 NameLoc.CXXOperatorName.BeginOpNameLoc);
9821 RBrace = SourceLocation::getFromRawEncoding(
9822 NameLoc.CXXOperatorName.EndOpNameLoc);
9823 } else {
9824 LBrace = Callee->getLocStart();
9825 RBrace = OpLoc;
9826 }
9827
9828 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
9829 First, Second);
9830 }
Sebastian Redladba46e2009-10-29 20:17:01 +00009831
Douglas Gregora16548e2009-08-11 05:31:07 +00009832 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +00009833 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00009834 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00009835 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
9836 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009837 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009838
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009839 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00009840}
Mike Stump11289f42009-09-09 15:08:12 +00009841
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009842template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00009843ExprResult
John McCallb268a282010-08-23 23:25:46 +00009844TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009845 SourceLocation OperatorLoc,
9846 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +00009847 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009848 TypeSourceInfo *ScopeType,
9849 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00009850 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00009851 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +00009852 QualType BaseType = Base->getType();
9853 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009854 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier1dcde962012-08-08 18:46:20 +00009855 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +00009856 !BaseType->getAs<PointerType>()->getPointeeType()
9857 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009858 // This pseudo-destructor expression is still a pseudo-destructor.
John McCallb268a282010-08-23 23:25:46 +00009859 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009860 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00009861 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00009862 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009863 /*FIXME?*/true);
9864 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009865
Douglas Gregor678f90d2010-02-25 01:56:36 +00009866 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009867 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
9868 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
9869 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
9870 NameInfo.setNamedTypeInfo(DestroyedType);
9871
Richard Smith8e4a3862012-05-15 06:15:11 +00009872 // The scope type is now known to be a valid nested name specifier
9873 // component. Tack it on to the end of the nested name specifier.
9874 if (ScopeType)
9875 SS.Extend(SemaRef.Context, SourceLocation(),
9876 ScopeType->getTypeLoc(), CCLoc);
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009877
Abramo Bagnara7945c982012-01-27 09:46:47 +00009878 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCallb268a282010-08-23 23:25:46 +00009879 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009880 OperatorLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009881 SS, TemplateKWLoc,
9882 /*FIXME: FirstQualifier*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009883 NameInfo,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009884 /*TemplateArgs*/ 0);
9885}
9886
Tareq A. Siraj24110cc2013-04-16 18:53:08 +00009887template<typename Derived>
9888StmtResult
9889TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
Wei Pan17fbf6e2013-05-04 03:59:06 +00009890 SourceLocation Loc = S->getLocStart();
9891 unsigned NumParams = S->getCapturedDecl()->getNumParams();
9892 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/0,
9893 S->getCapturedRegionKind(), NumParams);
9894 StmtResult Body = getDerived().TransformStmt(S->getCapturedStmt());
9895
9896 if (Body.isInvalid()) {
9897 getSema().ActOnCapturedRegionError();
9898 return StmtError();
9899 }
9900
9901 return getSema().ActOnCapturedRegionEnd(Body.take());
Tareq A. Siraj24110cc2013-04-16 18:53:08 +00009902}
9903
Douglas Gregord6ff3322009-08-04 16:50:30 +00009904} // end namespace clang
9905
9906#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H