blob: 29bfcd453706c5c1794f8d2e91fffeec06703afd [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
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001348 /// \brief Build a new OpenMP 'proc_bind' 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 *RebuildOMPProcBindClause(OpenMPProcBindClauseKind Kind,
1353 SourceLocation KindKwLoc,
1354 SourceLocation StartLoc,
1355 SourceLocation LParenLoc,
1356 SourceLocation EndLoc) {
1357 return getSema().ActOnOpenMPProcBindClause(Kind, KindKwLoc,
1358 StartLoc, LParenLoc, EndLoc);
1359 }
1360
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001361 /// \brief Build a new OpenMP 'private' clause.
1362 ///
1363 /// By default, performs semantic analysis to build the new statement.
1364 /// Subclasses may override this routine to provide different behavior.
1365 OMPClause *RebuildOMPPrivateClause(ArrayRef<Expr *> VarList,
1366 SourceLocation StartLoc,
1367 SourceLocation LParenLoc,
1368 SourceLocation EndLoc) {
1369 return getSema().ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc,
1370 EndLoc);
1371 }
1372
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001373 /// \brief Build a new OpenMP 'firstprivate' clause.
1374 ///
1375 /// By default, performs semantic analysis to build the new statement.
1376 /// Subclasses may override this routine to provide different behavior.
1377 OMPClause *RebuildOMPFirstprivateClause(ArrayRef<Expr *> VarList,
1378 SourceLocation StartLoc,
1379 SourceLocation LParenLoc,
1380 SourceLocation EndLoc) {
1381 return getSema().ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc,
1382 EndLoc);
1383 }
1384
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001385 /// \brief Build a new OpenMP 'shared' clause.
1386 ///
1387 /// By default, performs semantic analysis to build the new statement.
1388 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev758e55e2013-09-06 18:03:48 +00001389 OMPClause *RebuildOMPSharedClause(ArrayRef<Expr *> VarList,
1390 SourceLocation StartLoc,
1391 SourceLocation LParenLoc,
1392 SourceLocation EndLoc) {
1393 return getSema().ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc,
1394 EndLoc);
1395 }
1396
Alexander Musman8dba6642014-04-22 13:09:42 +00001397 /// \brief Build a new OpenMP 'linear' 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 *RebuildOMPLinearClause(ArrayRef<Expr *> VarList, Expr *Step,
1402 SourceLocation StartLoc,
1403 SourceLocation LParenLoc,
1404 SourceLocation ColonLoc,
1405 SourceLocation EndLoc) {
1406 return getSema().ActOnOpenMPLinearClause(VarList, Step, StartLoc, LParenLoc,
1407 ColonLoc, EndLoc);
1408 }
1409
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001410 /// \brief Build a new OpenMP 'copyin' clause.
1411 ///
1412 /// By default, performs semantic analysis to build the new statement.
1413 /// Subclasses may override this routine to provide different behavior.
1414 OMPClause *RebuildOMPCopyinClause(ArrayRef<Expr *> VarList,
1415 SourceLocation StartLoc,
1416 SourceLocation LParenLoc,
1417 SourceLocation EndLoc) {
1418 return getSema().ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc,
1419 EndLoc);
1420 }
1421
James Dennett2a4d13c2012-06-15 07:13:21 +00001422 /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
John McCalld9bb7432011-07-27 21:50:02 +00001423 ///
1424 /// By default, performs semantic analysis to build the new statement.
1425 /// Subclasses may override this routine to provide different behavior.
1426 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1427 Expr *object) {
1428 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1429 }
1430
James Dennett2a4d13c2012-06-15 07:13:21 +00001431 /// \brief Build a new Objective-C \@synchronized statement.
Douglas Gregor6148de72010-04-22 22:01:21 +00001432 ///
Douglas Gregor6148de72010-04-22 22:01:21 +00001433 /// By default, performs semantic analysis to build the new statement.
1434 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001435 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCalld9bb7432011-07-27 21:50:02 +00001436 Expr *Object, Stmt *Body) {
1437 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor6148de72010-04-22 22:01:21 +00001438 }
Douglas Gregorf68a5082010-04-22 23:10:45 +00001439
James Dennett2a4d13c2012-06-15 07:13:21 +00001440 /// \brief Build a new Objective-C \@autoreleasepool statement.
John McCall31168b02011-06-15 23:02:42 +00001441 ///
1442 /// By default, performs semantic analysis to build the new statement.
1443 /// Subclasses may override this routine to provide different behavior.
1444 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1445 Stmt *Body) {
1446 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1447 }
John McCall53848232011-07-27 01:07:15 +00001448
Douglas Gregorf68a5082010-04-22 23:10:45 +00001449 /// \brief Build a new Objective-C fast enumeration statement.
1450 ///
1451 /// By default, performs semantic analysis to build the new statement.
1452 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001453 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001454 Stmt *Element,
1455 Expr *Collection,
1456 SourceLocation RParenLoc,
1457 Stmt *Body) {
Sam Panzer2c4ca0f2012-08-16 21:47:25 +00001458 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001459 Element,
John McCallb268a282010-08-23 23:25:46 +00001460 Collection,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001461 RParenLoc);
1462 if (ForEachStmt.isInvalid())
1463 return StmtError();
1464
1465 return getSema().FinishObjCForCollectionStmt(ForEachStmt.take(), Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +00001466 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001467
Douglas Gregorebe10102009-08-20 07:17:43 +00001468 /// \brief Build a new C++ exception declaration.
1469 ///
1470 /// By default, performs semantic analysis to build the new decaration.
1471 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaradff19302011-03-08 08:55:46 +00001472 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +00001473 TypeSourceInfo *Declarator,
Abramo Bagnaradff19302011-03-08 08:55:46 +00001474 SourceLocation StartLoc,
1475 SourceLocation IdLoc,
1476 IdentifierInfo *Id) {
Douglas Gregor40965fa2011-04-14 22:32:28 +00001477 VarDecl *Var = getSema().BuildExceptionDeclaration(0, Declarator,
1478 StartLoc, IdLoc, Id);
1479 if (Var)
1480 getSema().CurContext->addDecl(Var);
1481 return Var;
Douglas Gregorebe10102009-08-20 07:17:43 +00001482 }
1483
1484 /// \brief Build a new C++ catch statement.
1485 ///
1486 /// By default, performs semantic analysis to build the new statement.
1487 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001488 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001489 VarDecl *ExceptionDecl,
1490 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00001491 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1492 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00001493 }
Mike Stump11289f42009-09-09 15:08:12 +00001494
Douglas Gregorebe10102009-08-20 07:17:43 +00001495 /// \brief Build a new C++ try statement.
1496 ///
1497 /// By default, performs semantic analysis to build the new statement.
1498 /// Subclasses may override this routine to provide different behavior.
Robert Wilhelmcafda822013-08-22 09:20:03 +00001499 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock,
1500 ArrayRef<Stmt *> Handlers) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001501 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00001502 }
Mike Stump11289f42009-09-09 15:08:12 +00001503
Richard Smith02e85f32011-04-14 22:09:26 +00001504 /// \brief Build a new C++0x range-based for statement.
1505 ///
1506 /// By default, performs semantic analysis to build the new statement.
1507 /// Subclasses may override this routine to provide different behavior.
1508 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1509 SourceLocation ColonLoc,
1510 Stmt *Range, Stmt *BeginEnd,
1511 Expr *Cond, Expr *Inc,
1512 Stmt *LoopVar,
1513 SourceLocation RParenLoc) {
Douglas Gregorf7106af2013-04-08 18:40:13 +00001514 // If we've just learned that the range is actually an Objective-C
1515 // collection, treat this as an Objective-C fast enumeration loop.
1516 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
1517 if (RangeStmt->isSingleDecl()) {
1518 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
Douglas Gregor39aaeef2013-05-02 18:35:56 +00001519 if (RangeVar->isInvalidDecl())
1520 return StmtError();
1521
Douglas Gregorf7106af2013-04-08 18:40:13 +00001522 Expr *RangeExpr = RangeVar->getInit();
1523 if (!RangeExpr->isTypeDependent() &&
1524 RangeExpr->getType()->isObjCObjectPointerType())
1525 return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, RangeExpr,
1526 RParenLoc);
1527 }
1528 }
1529 }
1530
Richard Smith02e85f32011-04-14 22:09:26 +00001531 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
Richard Smitha05b3b52012-09-20 21:52:32 +00001532 Cond, Inc, LoopVar, RParenLoc,
1533 Sema::BFRK_Rebuild);
Richard Smith02e85f32011-04-14 22:09:26 +00001534 }
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001535
1536 /// \brief Build a new C++0x range-based for statement.
1537 ///
1538 /// By default, performs semantic analysis to build the new statement.
1539 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00001540 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001541 bool IsIfExists,
1542 NestedNameSpecifierLoc QualifierLoc,
1543 DeclarationNameInfo NameInfo,
1544 Stmt *Nested) {
1545 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1546 QualifierLoc, NameInfo, Nested);
1547 }
1548
Richard Smith02e85f32011-04-14 22:09:26 +00001549 /// \brief Attach body to a C++0x range-based for statement.
1550 ///
1551 /// By default, performs semantic analysis to finish the new statement.
1552 /// Subclasses may override this routine to provide different behavior.
1553 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1554 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1555 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001556
David Majnemerfad8f482013-10-15 09:33:02 +00001557 StmtResult RebuildSEHTryStmt(bool IsCXXTry, SourceLocation TryLoc,
1558 Stmt *TryBlock, Stmt *Handler) {
1559 return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +00001560 }
1561
David Majnemerfad8f482013-10-15 09:33:02 +00001562 StmtResult RebuildSEHExceptStmt(SourceLocation Loc, Expr *FilterExpr,
John Wiegley1c0675e2011-04-28 01:08:34 +00001563 Stmt *Block) {
David Majnemerfad8f482013-10-15 09:33:02 +00001564 return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001565 }
1566
David Majnemerfad8f482013-10-15 09:33:02 +00001567 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, Stmt *Block) {
1568 return getSema().ActOnSEHFinallyBlock(Loc, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001569 }
1570
Douglas Gregora16548e2009-08-11 05:31:07 +00001571 /// \brief Build a new expression that references a declaration.
1572 ///
1573 /// By default, performs semantic analysis to build the new expression.
1574 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001575 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00001576 LookupResult &R,
1577 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00001578 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1579 }
1580
1581
1582 /// \brief Build a new expression that references a declaration.
1583 ///
1584 /// By default, performs semantic analysis to build the new expression.
1585 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorea972d32011-02-28 21:54:11 +00001586 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001587 ValueDecl *VD,
1588 const DeclarationNameInfo &NameInfo,
1589 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001590 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001591 SS.Adopt(QualifierLoc);
John McCallce546572009-12-08 09:08:17 +00001592
1593 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001594
1595 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001596 }
Mike Stump11289f42009-09-09 15:08:12 +00001597
Douglas Gregora16548e2009-08-11 05:31:07 +00001598 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001599 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001600 /// By default, performs semantic analysis to build the new expression.
1601 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001602 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00001603 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00001604 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001605 }
1606
Douglas Gregorad8a3362009-09-04 17:36:40 +00001607 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001608 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +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 RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora6ce6082011-02-25 18:19:59 +00001612 SourceLocation OperatorLoc,
1613 bool isArrow,
1614 CXXScopeSpec &SS,
1615 TypeSourceInfo *ScopeType,
1616 SourceLocation CCLoc,
1617 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001618 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001619
Douglas Gregora16548e2009-08-11 05:31:07 +00001620 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001621 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001622 /// By default, performs semantic analysis to build the new expression.
1623 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001624 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001625 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001626 Expr *SubExpr) {
1627 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001628 }
Mike Stump11289f42009-09-09 15:08:12 +00001629
Douglas Gregor882211c2010-04-28 22:16:22 +00001630 /// \brief Build a new builtin offsetof expression.
1631 ///
1632 /// By default, performs semantic analysis to build the new expression.
1633 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001634 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor882211c2010-04-28 22:16:22 +00001635 TypeSourceInfo *Type,
John McCallfaf5fb42010-08-26 23:41:50 +00001636 Sema::OffsetOfComponent *Components,
Douglas Gregor882211c2010-04-28 22:16:22 +00001637 unsigned NumComponents,
1638 SourceLocation RParenLoc) {
1639 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1640 NumComponents, RParenLoc);
1641 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001642
1643 /// \brief Build a new sizeof, alignof or vec_step expression with a
Peter Collingbournee190dee2011-03-11 19:24:49 +00001644 /// type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001645 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001646 /// By default, performs semantic analysis to build the new expression.
1647 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001648 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1649 SourceLocation OpLoc,
1650 UnaryExprOrTypeTrait ExprKind,
1651 SourceRange R) {
1652 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001653 }
1654
Peter Collingbournee190dee2011-03-11 19:24:49 +00001655 /// \brief Build a new sizeof, alignof or vec step expression with an
1656 /// expression argument.
Mike Stump11289f42009-09-09 15:08:12 +00001657 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001658 /// By default, performs semantic analysis to build the new expression.
1659 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001660 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1661 UnaryExprOrTypeTrait ExprKind,
1662 SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00001663 ExprResult Result
Chandler Carrutha923fb22011-05-29 07:32:14 +00001664 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregora16548e2009-08-11 05:31:07 +00001665 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001666 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001667
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001668 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001669 }
Mike Stump11289f42009-09-09 15:08:12 +00001670
Douglas Gregora16548e2009-08-11 05:31:07 +00001671 /// \brief Build a new array subscript 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 RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001676 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00001677 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001678 SourceLocation RBracketLoc) {
John McCallb268a282010-08-23 23:25:46 +00001679 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1680 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001681 RBracketLoc);
1682 }
1683
1684 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00001685 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001686 /// By default, performs semantic analysis to build the new expression.
1687 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001688 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001689 MultiExprArg Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00001690 SourceLocation RParenLoc,
1691 Expr *ExecConfig = 0) {
John McCallb268a282010-08-23 23:25:46 +00001692 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001693 Args, RParenLoc, ExecConfig);
Douglas Gregora16548e2009-08-11 05:31:07 +00001694 }
1695
1696 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001697 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001698 /// By default, performs semantic analysis to build the new expression.
1699 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001700 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001701 bool isArrow,
Douglas Gregorea972d32011-02-28 21:54:11 +00001702 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001703 SourceLocation TemplateKWLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001704 const DeclarationNameInfo &MemberNameInfo,
1705 ValueDecl *Member,
1706 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001707 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00001708 NamedDecl *FirstQualifierInScope) {
Richard Smithcab9a7d2011-10-26 19:06:56 +00001709 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
1710 isArrow);
Anders Carlsson5da84842009-09-01 04:26:58 +00001711 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00001712 // We have a reference to an unnamed field. This is always the
1713 // base of an anonymous struct/union member access, i.e. the
1714 // field is always of record type.
Douglas Gregorea972d32011-02-28 21:54:11 +00001715 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCall7decc9e2010-11-18 06:31:45 +00001716 assert(Member->getType()->isRecordType() &&
1717 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00001718
Richard Smithcab9a7d2011-10-26 19:06:56 +00001719 BaseResult =
1720 getSema().PerformObjectMemberConversion(BaseResult.take(),
John Wiegley01296292011-04-08 18:41:53 +00001721 QualifierLoc.getNestedNameSpecifier(),
1722 FoundDecl, Member);
1723 if (BaseResult.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001724 return ExprError();
John Wiegley01296292011-04-08 18:41:53 +00001725 Base = BaseResult.take();
John McCall7decc9e2010-11-18 06:31:45 +00001726 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump11289f42009-09-09 15:08:12 +00001727 MemberExpr *ME =
John McCallb268a282010-08-23 23:25:46 +00001728 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001729 Member, MemberNameInfo,
John McCall7decc9e2010-11-18 06:31:45 +00001730 cast<FieldDecl>(Member)->getType(),
1731 VK, OK_Ordinary);
Anders Carlsson5da84842009-09-01 04:26:58 +00001732 return getSema().Owned(ME);
1733 }
Mike Stump11289f42009-09-09 15:08:12 +00001734
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001735 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001736 SS.Adopt(QualifierLoc);
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001737
John Wiegley01296292011-04-08 18:41:53 +00001738 Base = BaseResult.take();
John McCallb268a282010-08-23 23:25:46 +00001739 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00001740
John McCall16df1e52010-03-30 21:47:33 +00001741 // FIXME: this involves duplicating earlier analysis in a lot of
1742 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001743 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001744 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001745 R.resolveKind();
1746
John McCallb268a282010-08-23 23:25:46 +00001747 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001748 SS, TemplateKWLoc,
1749 FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001750 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001751 }
Mike Stump11289f42009-09-09 15:08:12 +00001752
Douglas Gregora16548e2009-08-11 05:31:07 +00001753 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001754 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001755 /// By default, performs semantic analysis to build the new expression.
1756 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001757 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001758 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001759 Expr *LHS, Expr *RHS) {
1760 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001761 }
1762
1763 /// \brief Build a new conditional operator 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 RebuildConditionalOperator(Expr *Cond,
John McCallc07a0c72011-02-17 10:25:35 +00001768 SourceLocation QuestionLoc,
1769 Expr *LHS,
1770 SourceLocation ColonLoc,
1771 Expr *RHS) {
John McCallb268a282010-08-23 23:25:46 +00001772 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1773 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001774 }
1775
Douglas Gregora16548e2009-08-11 05:31:07 +00001776 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001777 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001778 /// By default, performs semantic analysis to build the new expression.
1779 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001780 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00001781 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001782 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001783 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001784 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001785 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001786 }
Mike Stump11289f42009-09-09 15:08:12 +00001787
Douglas Gregora16548e2009-08-11 05:31:07 +00001788 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001789 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001790 /// By default, performs semantic analysis to build the new expression.
1791 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001792 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001793 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001794 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001795 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001796 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001797 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001798 }
Mike Stump11289f42009-09-09 15:08:12 +00001799
Douglas Gregora16548e2009-08-11 05:31:07 +00001800 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001801 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001802 /// By default, performs semantic analysis to build the new expression.
1803 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001804 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001805 SourceLocation OpLoc,
1806 SourceLocation AccessorLoc,
1807 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001808
John McCall10eae182009-11-30 22:42:35 +00001809 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001810 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00001811 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00001812 OpLoc, /*IsArrow*/ false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001813 SS, SourceLocation(),
1814 /*FirstQualifierInScope*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001815 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00001816 /* TemplateArgs */ 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00001817 }
Mike Stump11289f42009-09-09 15:08:12 +00001818
Douglas Gregora16548e2009-08-11 05:31:07 +00001819 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001820 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001821 /// By default, performs semantic analysis to build the new expression.
1822 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001823 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCall542e7c62011-07-06 07:30:07 +00001824 MultiExprArg Inits,
1825 SourceLocation RBraceLoc,
1826 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00001827 ExprResult Result
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001828 = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
Douglas Gregord3d93062009-11-09 17:16:50 +00001829 if (Result.isInvalid() || ResultTy->isDependentType())
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001830 return Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00001831
Douglas Gregord3d93062009-11-09 17:16:50 +00001832 // Patch in the result type we were given, which may have been computed
1833 // when the initial InitListExpr was built.
1834 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1835 ILE->setType(ResultTy);
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001836 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001837 }
Mike Stump11289f42009-09-09 15:08:12 +00001838
Douglas Gregora16548e2009-08-11 05:31:07 +00001839 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001840 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001841 /// By default, performs semantic analysis to build the new expression.
1842 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001843 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00001844 MultiExprArg ArrayExprs,
1845 SourceLocation EqualOrColonLoc,
1846 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001847 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00001848 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001849 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001850 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001851 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001852 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001853
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001854 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001855 }
Mike Stump11289f42009-09-09 15:08:12 +00001856
Douglas Gregora16548e2009-08-11 05:31:07 +00001857 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001858 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001859 /// By default, builds the implicit value initialization without performing
1860 /// any semantic analysis. Subclasses may override this routine to provide
1861 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001862 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001863 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1864 }
Mike Stump11289f42009-09-09 15:08:12 +00001865
Douglas Gregora16548e2009-08-11 05:31:07 +00001866 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001867 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001868 /// By default, performs semantic analysis to build the new expression.
1869 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001870 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001871 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001872 SourceLocation RParenLoc) {
1873 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001874 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001875 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001876 }
1877
1878 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001879 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001880 /// By default, performs semantic analysis to build the new expression.
1881 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001882 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redla9351792012-02-11 23:51:47 +00001883 MultiExprArg SubExprs,
1884 SourceLocation RParenLoc) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001885 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001886 }
Mike Stump11289f42009-09-09 15:08:12 +00001887
Douglas Gregora16548e2009-08-11 05:31:07 +00001888 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001889 ///
1890 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00001891 /// rather than attempting to map the label statement itself.
1892 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001893 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001894 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001895 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregora16548e2009-08-11 05:31:07 +00001896 }
Mike Stump11289f42009-09-09 15:08:12 +00001897
Douglas Gregora16548e2009-08-11 05:31:07 +00001898 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00001899 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001900 /// By default, performs semantic analysis to build the new expression.
1901 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001902 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001903 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00001904 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001905 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001906 }
Mike Stump11289f42009-09-09 15:08:12 +00001907
Douglas Gregora16548e2009-08-11 05:31:07 +00001908 /// \brief Build a new __builtin_choose_expr expression.
1909 ///
1910 /// By default, performs semantic analysis to build the new expression.
1911 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001912 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001913 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001914 SourceLocation RParenLoc) {
1915 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001916 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001917 RParenLoc);
1918 }
Mike Stump11289f42009-09-09 15:08:12 +00001919
Peter Collingbourne91147592011-04-15 00:35:48 +00001920 /// \brief Build a new generic selection expression.
1921 ///
1922 /// By default, performs semantic analysis to build the new expression.
1923 /// Subclasses may override this routine to provide different behavior.
1924 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
1925 SourceLocation DefaultLoc,
1926 SourceLocation RParenLoc,
1927 Expr *ControllingExpr,
Dmitri Gribenko82360372013-05-10 13:06:58 +00001928 ArrayRef<TypeSourceInfo *> Types,
1929 ArrayRef<Expr *> Exprs) {
Peter Collingbourne91147592011-04-15 00:35:48 +00001930 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
Dmitri Gribenko82360372013-05-10 13:06:58 +00001931 ControllingExpr, Types, Exprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00001932 }
1933
Douglas Gregora16548e2009-08-11 05:31:07 +00001934 /// \brief Build a new overloaded operator call expression.
1935 ///
1936 /// By default, performs semantic analysis to build the new expression.
1937 /// The semantic analysis provides the behavior of template instantiation,
1938 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00001939 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00001940 /// argument-dependent lookup, etc. Subclasses may override this routine to
1941 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001942 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00001943 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00001944 Expr *Callee,
1945 Expr *First,
1946 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00001947
1948 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00001949 /// reinterpret_cast.
1950 ///
1951 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00001952 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00001953 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001954 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001955 Stmt::StmtClass Class,
1956 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001957 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001958 SourceLocation RAngleLoc,
1959 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001960 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001961 SourceLocation RParenLoc) {
1962 switch (Class) {
1963 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001964 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001965 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001966 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001967
1968 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001969 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001970 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001971 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001972
Douglas Gregora16548e2009-08-11 05:31:07 +00001973 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001974 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001975 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001976 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001977 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001978
Douglas Gregora16548e2009-08-11 05:31:07 +00001979 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001980 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001981 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001982 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001983
Douglas Gregora16548e2009-08-11 05:31:07 +00001984 default:
David Blaikie83d382b2011-09-23 05:06:16 +00001985 llvm_unreachable("Invalid C++ named cast");
Douglas Gregora16548e2009-08-11 05:31:07 +00001986 }
Douglas Gregora16548e2009-08-11 05:31:07 +00001987 }
Mike Stump11289f42009-09-09 15:08:12 +00001988
Douglas Gregora16548e2009-08-11 05:31:07 +00001989 /// \brief Build a new C++ static_cast expression.
1990 ///
1991 /// By default, performs semantic analysis to build the new expression.
1992 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001993 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001994 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001995 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001996 SourceLocation RAngleLoc,
1997 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001998 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001999 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002000 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00002001 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002002 SourceRange(LAngleLoc, RAngleLoc),
2003 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002004 }
2005
2006 /// \brief Build a new C++ dynamic_cast expression.
2007 ///
2008 /// By default, performs semantic analysis to build the new expression.
2009 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002010 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002011 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002012 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002013 SourceLocation RAngleLoc,
2014 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002015 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002016 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002017 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00002018 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002019 SourceRange(LAngleLoc, RAngleLoc),
2020 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002021 }
2022
2023 /// \brief Build a new C++ reinterpret_cast expression.
2024 ///
2025 /// By default, performs semantic analysis to build the new expression.
2026 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002027 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002028 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002029 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002030 SourceLocation RAngleLoc,
2031 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002032 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002033 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002034 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00002035 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002036 SourceRange(LAngleLoc, RAngleLoc),
2037 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002038 }
2039
2040 /// \brief Build a new C++ const_cast expression.
2041 ///
2042 /// By default, performs semantic analysis to build the new expression.
2043 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002044 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002045 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002046 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002047 SourceLocation RAngleLoc,
2048 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002049 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002050 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002051 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00002052 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002053 SourceRange(LAngleLoc, RAngleLoc),
2054 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002055 }
Mike Stump11289f42009-09-09 15:08:12 +00002056
Douglas Gregora16548e2009-08-11 05:31:07 +00002057 /// \brief Build a new C++ functional-style cast expression.
2058 ///
2059 /// By default, performs semantic analysis to build the new expression.
2060 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002061 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
2062 SourceLocation LParenLoc,
2063 Expr *Sub,
2064 SourceLocation RParenLoc) {
2065 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00002066 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00002067 RParenLoc);
2068 }
Mike Stump11289f42009-09-09 15:08:12 +00002069
Douglas Gregora16548e2009-08-11 05:31:07 +00002070 /// \brief Build a new C++ typeid(type) 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,
2076 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002077 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002078 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002079 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002080 }
Mike Stump11289f42009-09-09 15:08:12 +00002081
Francois Pichet9f4f2072010-09-08 12:20:18 +00002082
Douglas Gregora16548e2009-08-11 05:31:07 +00002083 /// \brief Build a new C++ typeid(expr) expression.
2084 ///
2085 /// By default, performs semantic analysis to build the new expression.
2086 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002087 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002088 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00002089 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002090 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002091 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002092 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002093 }
2094
Francois Pichet9f4f2072010-09-08 12:20:18 +00002095 /// \brief Build a new C++ __uuidof(type) expression.
2096 ///
2097 /// By default, performs semantic analysis to build the new expression.
2098 /// Subclasses may override this routine to provide different behavior.
2099 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2100 SourceLocation TypeidLoc,
2101 TypeSourceInfo *Operand,
2102 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002103 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
Francois Pichet9f4f2072010-09-08 12:20:18 +00002104 RParenLoc);
2105 }
2106
2107 /// \brief Build a new C++ __uuidof(expr) expression.
2108 ///
2109 /// By default, performs semantic analysis to build the new expression.
2110 /// Subclasses may override this routine to provide different behavior.
2111 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2112 SourceLocation TypeidLoc,
2113 Expr *Operand,
2114 SourceLocation RParenLoc) {
2115 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
2116 RParenLoc);
2117 }
2118
Douglas Gregora16548e2009-08-11 05:31:07 +00002119 /// \brief Build a new C++ "this" expression.
2120 ///
2121 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00002122 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00002123 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002124 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00002125 QualType ThisType,
2126 bool isImplicit) {
Eli Friedman20139d32012-01-11 02:36:31 +00002127 getSema().CheckCXXThisCapture(ThisLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002128 return getSema().Owned(
Douglas Gregorb15af892010-01-07 23:12:05 +00002129 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
2130 isImplicit));
Douglas Gregora16548e2009-08-11 05:31:07 +00002131 }
2132
2133 /// \brief Build a new C++ throw expression.
2134 ///
2135 /// By default, performs semantic analysis to build the new expression.
2136 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor53e191ed2011-07-06 22:04:06 +00002137 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
2138 bool IsThrownVariableInScope) {
2139 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00002140 }
2141
2142 /// \brief Build a new C++ default-argument expression.
2143 ///
2144 /// By default, builds a new default-argument expression, which does not
2145 /// require any semantic analysis. Subclasses may override this routine to
2146 /// provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002147 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00002148 ParmVarDecl *Param) {
2149 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
2150 Param));
Douglas Gregora16548e2009-08-11 05:31:07 +00002151 }
2152
Richard Smith852c9db2013-04-20 22:23:05 +00002153 /// \brief Build a new C++11 default-initialization expression.
2154 ///
2155 /// By default, builds a new default field initialization expression, which
2156 /// does not require any semantic analysis. Subclasses may override this
2157 /// routine to provide different behavior.
2158 ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc,
2159 FieldDecl *Field) {
2160 return getSema().Owned(CXXDefaultInitExpr::Create(getSema().Context, Loc,
2161 Field));
2162 }
2163
Douglas Gregora16548e2009-08-11 05:31:07 +00002164 /// \brief Build a new C++ zero-initialization expression.
2165 ///
2166 /// By default, performs semantic analysis to build the new expression.
2167 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002168 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
2169 SourceLocation LParenLoc,
2170 SourceLocation RParenLoc) {
2171 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002172 None, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002173 }
Mike Stump11289f42009-09-09 15:08:12 +00002174
Douglas Gregora16548e2009-08-11 05:31:07 +00002175 /// \brief Build a new C++ "new" expression.
2176 ///
2177 /// By default, performs semantic analysis to build the new expression.
2178 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002179 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002180 bool UseGlobal,
2181 SourceLocation PlacementLParen,
2182 MultiExprArg PlacementArgs,
2183 SourceLocation PlacementRParen,
2184 SourceRange TypeIdParens,
2185 QualType AllocatedType,
2186 TypeSourceInfo *AllocatedTypeInfo,
2187 Expr *ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002188 SourceRange DirectInitRange,
2189 Expr *Initializer) {
Mike Stump11289f42009-09-09 15:08:12 +00002190 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00002191 PlacementLParen,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002192 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00002193 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00002194 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002195 AllocatedType,
2196 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00002197 ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002198 DirectInitRange,
2199 Initializer);
Douglas Gregora16548e2009-08-11 05:31:07 +00002200 }
Mike Stump11289f42009-09-09 15:08:12 +00002201
Douglas Gregora16548e2009-08-11 05:31:07 +00002202 /// \brief Build a new C++ "delete" expression.
2203 ///
2204 /// By default, performs semantic analysis to build the new expression.
2205 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002206 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002207 bool IsGlobalDelete,
2208 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002209 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002210 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002211 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00002212 }
Mike Stump11289f42009-09-09 15:08:12 +00002213
Douglas Gregor29c42f22012-02-24 07:38:34 +00002214 /// \brief Build a new type trait expression.
2215 ///
2216 /// By default, performs semantic analysis to build the new expression.
2217 /// Subclasses may override this routine to provide different behavior.
2218 ExprResult RebuildTypeTrait(TypeTrait Trait,
2219 SourceLocation StartLoc,
2220 ArrayRef<TypeSourceInfo *> Args,
2221 SourceLocation RParenLoc) {
2222 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2223 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002224
John Wiegley6242b6a2011-04-28 00:16:57 +00002225 /// \brief Build a new array type trait expression.
2226 ///
2227 /// By default, performs semantic analysis to build the new expression.
2228 /// Subclasses may override this routine to provide different behavior.
2229 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2230 SourceLocation StartLoc,
2231 TypeSourceInfo *TSInfo,
2232 Expr *DimExpr,
2233 SourceLocation RParenLoc) {
2234 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2235 }
2236
John Wiegleyf9f65842011-04-25 06:54:41 +00002237 /// \brief Build a new expression trait expression.
2238 ///
2239 /// By default, performs semantic analysis to build the new expression.
2240 /// Subclasses may override this routine to provide different behavior.
2241 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2242 SourceLocation StartLoc,
2243 Expr *Queried,
2244 SourceLocation RParenLoc) {
2245 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2246 }
2247
Mike Stump11289f42009-09-09 15:08:12 +00002248 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00002249 /// expression.
2250 ///
2251 /// By default, performs semantic analysis to build the new expression.
2252 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002253 ExprResult RebuildDependentScopeDeclRefExpr(
2254 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002255 SourceLocation TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002256 const DeclarationNameInfo &NameInfo,
Richard Smithdb2630f2012-10-21 03:28:35 +00002257 const TemplateArgumentListInfo *TemplateArgs,
2258 bool IsAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002259 CXXScopeSpec SS;
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002260 SS.Adopt(QualifierLoc);
John McCalle66edc12009-11-24 19:00:30 +00002261
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002262 if (TemplateArgs || TemplateKWLoc.isValid())
Abramo Bagnara7945c982012-01-27 09:46:47 +00002263 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002264 NameInfo, TemplateArgs);
John McCalle66edc12009-11-24 19:00:30 +00002265
Richard Smithdb2630f2012-10-21 03:28:35 +00002266 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo,
2267 IsAddressOfOperand);
Douglas Gregora16548e2009-08-11 05:31:07 +00002268 }
2269
2270 /// \brief Build a new template-id 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 RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002275 SourceLocation TemplateKWLoc,
2276 LookupResult &R,
2277 bool RequiresADL,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002278 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnara7945c982012-01-27 09:46:47 +00002279 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2280 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002281 }
2282
2283 /// \brief Build a new object-construction expression.
2284 ///
2285 /// By default, performs semantic analysis to build the new expression.
2286 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002287 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002288 SourceLocation Loc,
2289 CXXConstructorDecl *Constructor,
2290 bool IsElidable,
2291 MultiExprArg Args,
2292 bool HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002293 bool ListInitialization,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002294 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00002295 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002296 SourceRange ParenRange) {
Benjamin Kramerf0623432012-08-23 22:51:59 +00002297 SmallVector<Expr*, 8> ConvertedArgs;
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002298 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00002299 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00002300 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002301
Douglas Gregordb121ba2009-12-14 16:27:04 +00002302 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002303 ConvertedArgs,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002304 HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002305 ListInitialization,
Chandler Carruth01718152010-10-25 08:47:36 +00002306 RequiresZeroInit, ConstructKind,
2307 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00002308 }
2309
2310 /// \brief Build a new object-construction expression.
2311 ///
2312 /// By default, performs semantic analysis to build the new expression.
2313 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002314 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2315 SourceLocation LParenLoc,
2316 MultiExprArg Args,
2317 SourceLocation RParenLoc) {
2318 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002319 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002320 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002321 RParenLoc);
2322 }
2323
2324 /// \brief Build a new object-construction expression.
2325 ///
2326 /// By default, performs semantic analysis to build the new expression.
2327 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002328 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2329 SourceLocation LParenLoc,
2330 MultiExprArg Args,
2331 SourceLocation RParenLoc) {
2332 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002333 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002334 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002335 RParenLoc);
2336 }
Mike Stump11289f42009-09-09 15:08:12 +00002337
Douglas Gregora16548e2009-08-11 05:31:07 +00002338 /// \brief Build a new member reference expression.
2339 ///
2340 /// By default, performs semantic analysis to build the new expression.
2341 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002342 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregore16af532011-02-28 18:50:33 +00002343 QualType BaseType,
2344 bool IsArrow,
2345 SourceLocation OperatorLoc,
2346 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002347 SourceLocation TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00002348 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002349 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00002350 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002351 CXXScopeSpec SS;
Douglas Gregore16af532011-02-28 18:50:33 +00002352 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002353
John McCallb268a282010-08-23 23:25:46 +00002354 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002355 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002356 SS, TemplateKWLoc,
2357 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002358 MemberNameInfo,
2359 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002360 }
2361
John McCall10eae182009-11-30 22:42:35 +00002362 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00002363 ///
2364 /// By default, performs semantic analysis to build the new expression.
2365 /// Subclasses may override this routine to provide different behavior.
Richard Smithcab9a7d2011-10-26 19:06:56 +00002366 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2367 SourceLocation OperatorLoc,
2368 bool IsArrow,
2369 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002370 SourceLocation TemplateKWLoc,
Richard Smithcab9a7d2011-10-26 19:06:56 +00002371 NamedDecl *FirstQualifierInScope,
2372 LookupResult &R,
John McCall10eae182009-11-30 22:42:35 +00002373 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00002374 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00002375 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002376
John McCallb268a282010-08-23 23:25:46 +00002377 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002378 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002379 SS, TemplateKWLoc,
2380 FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00002381 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00002382 }
Mike Stump11289f42009-09-09 15:08:12 +00002383
Sebastian Redl4202c0f2010-09-10 20:55:43 +00002384 /// \brief Build a new noexcept expression.
2385 ///
2386 /// By default, performs semantic analysis to build the new expression.
2387 /// Subclasses may override this routine to provide different behavior.
2388 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2389 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2390 }
2391
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002392 /// \brief Build a new expression to compute the length of a parameter pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00002393 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2394 SourceLocation PackLoc,
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002395 SourceLocation RParenLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002396 Optional<unsigned> Length) {
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002397 if (Length)
Chad Rosier1dcde962012-08-08 18:46:20 +00002398 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2399 OperatorLoc, Pack, PackLoc,
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002400 RParenLoc, *Length);
Chad Rosier1dcde962012-08-08 18:46:20 +00002401
2402 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2403 OperatorLoc, Pack, PackLoc,
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002404 RParenLoc);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002405 }
Ted Kremeneke65b0862012-03-06 20:05:56 +00002406
Patrick Beard0caa3942012-04-19 00:25:12 +00002407 /// \brief Build a new Objective-C boxed expression.
2408 ///
2409 /// By default, performs semantic analysis to build the new expression.
2410 /// Subclasses may override this routine to provide different behavior.
2411 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2412 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2413 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002414
Ted Kremeneke65b0862012-03-06 20:05:56 +00002415 /// \brief Build a new Objective-C array literal.
2416 ///
2417 /// By default, performs semantic analysis to build the new expression.
2418 /// Subclasses may override this routine to provide different behavior.
2419 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2420 Expr **Elements, unsigned NumElements) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002421 return getSema().BuildObjCArrayLiteral(Range,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002422 MultiExprArg(Elements, NumElements));
2423 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002424
2425 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002426 Expr *Base, Expr *Key,
2427 ObjCMethodDecl *getterMethod,
2428 ObjCMethodDecl *setterMethod) {
2429 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2430 getterMethod, setterMethod);
2431 }
2432
2433 /// \brief Build a new Objective-C dictionary literal.
2434 ///
2435 /// By default, performs semantic analysis to build the new expression.
2436 /// Subclasses may override this routine to provide different behavior.
2437 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
2438 ObjCDictionaryElement *Elements,
2439 unsigned NumElements) {
2440 return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements);
2441 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002442
James Dennett2a4d13c2012-06-15 07:13:21 +00002443 /// \brief Build a new Objective-C \@encode expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002444 ///
2445 /// By default, performs semantic analysis to build the new expression.
2446 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002447 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00002448 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002449 SourceLocation RParenLoc) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00002450 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002451 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00002452 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002453
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002454 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00002455 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002456 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002457 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002458 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002459 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002460 MultiExprArg Args,
2461 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002462 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2463 ReceiverTypeInfo->getType(),
2464 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002465 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002466 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002467 }
2468
2469 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00002470 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002471 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002472 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002473 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002474 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002475 MultiExprArg Args,
2476 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00002477 return SemaRef.BuildInstanceMessage(Receiver,
2478 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002479 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002480 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002481 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002482 }
2483
Douglas Gregord51d90d2010-04-26 20:11:03 +00002484 /// \brief Build a new Objective-C ivar reference expression.
2485 ///
2486 /// By default, performs semantic analysis to build the new expression.
2487 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002488 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002489 SourceLocation IvarLoc,
2490 bool IsArrow, bool IsFreeIvar) {
2491 // FIXME: We lose track of the IsFreeIvar bit.
2492 CXXScopeSpec SS;
John Wiegley01296292011-04-08 18:41:53 +00002493 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002494 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2495 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00002496 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002497 /*FIME:*/IvarLoc,
John McCall48871652010-08-21 09:40:31 +00002498 SS, 0,
John McCalle9cccd82010-06-16 08:42:20 +00002499 false);
John Wiegley01296292011-04-08 18:41:53 +00002500 if (Result.isInvalid() || Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002501 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002502
Douglas Gregord51d90d2010-04-26 20:11:03 +00002503 if (Result.get())
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002504 return Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00002505
John Wiegley01296292011-04-08 18:41:53 +00002506 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Abramo Bagnara7945c982012-01-27 09:46:47 +00002507 /*FIXME:*/IvarLoc, IsArrow,
2508 SS, SourceLocation(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00002509 /*FirstQualifierInScope=*/0,
Chad Rosier1dcde962012-08-08 18:46:20 +00002510 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002511 /*TemplateArgs=*/0);
2512 }
Douglas Gregor9faee212010-04-26 20:47:02 +00002513
2514 /// \brief Build a new Objective-C property reference expression.
2515 ///
2516 /// By default, performs semantic analysis to build the new expression.
2517 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002518 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall526ab472011-10-25 17:37:35 +00002519 ObjCPropertyDecl *Property,
2520 SourceLocation PropertyLoc) {
Douglas Gregor9faee212010-04-26 20:47:02 +00002521 CXXScopeSpec SS;
John Wiegley01296292011-04-08 18:41:53 +00002522 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregor9faee212010-04-26 20:47:02 +00002523 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2524 Sema::LookupMemberName);
2525 bool IsArrow = false;
John McCalldadc5752010-08-24 06:29:42 +00002526 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregor9faee212010-04-26 20:47:02 +00002527 /*FIME:*/PropertyLoc,
John McCall48871652010-08-21 09:40:31 +00002528 SS, 0, false);
John Wiegley01296292011-04-08 18:41:53 +00002529 if (Result.isInvalid() || Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002530 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002531
Douglas Gregor9faee212010-04-26 20:47:02 +00002532 if (Result.get())
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002533 return Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00002534
John Wiegley01296292011-04-08 18:41:53 +00002535 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Chad Rosier1dcde962012-08-08 18:46:20 +00002536 /*FIXME:*/PropertyLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002537 SS, SourceLocation(),
Douglas Gregor9faee212010-04-26 20:47:02 +00002538 /*FirstQualifierInScope=*/0,
Chad Rosier1dcde962012-08-08 18:46:20 +00002539 R,
Douglas Gregor9faee212010-04-26 20:47:02 +00002540 /*TemplateArgs=*/0);
2541 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002542
John McCallb7bd14f2010-12-02 01:19:52 +00002543 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002544 ///
2545 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00002546 /// Subclasses may override this routine to provide different behavior.
2547 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2548 ObjCMethodDecl *Getter,
2549 ObjCMethodDecl *Setter,
2550 SourceLocation PropertyLoc) {
2551 // Since these expressions can only be value-dependent, we do not
2552 // need to perform semantic analysis again.
2553 return Owned(
2554 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2555 VK_LValue, OK_ObjCProperty,
2556 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002557 }
2558
Douglas Gregord51d90d2010-04-26 20:11:03 +00002559 /// \brief Build a new Objective-C "isa" expression.
2560 ///
2561 /// By default, performs semantic analysis to build the new expression.
2562 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002563 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00002564 SourceLocation OpLoc,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002565 bool IsArrow) {
2566 CXXScopeSpec SS;
John Wiegley01296292011-04-08 18:41:53 +00002567 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002568 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2569 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00002570 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00002571 OpLoc,
John McCall48871652010-08-21 09:40:31 +00002572 SS, 0, false);
John Wiegley01296292011-04-08 18:41:53 +00002573 if (Result.isInvalid() || Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002574 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002575
Douglas Gregord51d90d2010-04-26 20:11:03 +00002576 if (Result.get())
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002577 return Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00002578
John Wiegley01296292011-04-08 18:41:53 +00002579 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00002580 OpLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002581 SS, SourceLocation(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00002582 /*FirstQualifierInScope=*/0,
Chad Rosier1dcde962012-08-08 18:46:20 +00002583 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002584 /*TemplateArgs=*/0);
2585 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002586
Douglas Gregora16548e2009-08-11 05:31:07 +00002587 /// \brief Build a new shuffle vector expression.
2588 ///
2589 /// By default, performs semantic analysis to build the new expression.
2590 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002591 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002592 MultiExprArg SubExprs,
2593 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002594 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00002595 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00002596 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2597 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2598 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
David Blaikieff7d47a2012-12-19 00:45:41 +00002599 assert(!Lookup.empty() && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00002600
Douglas Gregora16548e2009-08-11 05:31:07 +00002601 // Build a reference to the __builtin_shufflevector builtin
David Blaikieff7d47a2012-12-19 00:45:41 +00002602 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
Eli Friedman34866c72012-08-31 00:14:07 +00002603 Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false,
2604 SemaRef.Context.BuiltinFnTy,
2605 VK_RValue, BuiltinLoc);
2606 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
2607 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
2608 CK_BuiltinFnToFnPtr).take();
Mike Stump11289f42009-09-09 15:08:12 +00002609
2610 // Build the CallExpr
Alp Toker314cc812014-01-25 16:55:45 +00002611 ExprResult TheCall = SemaRef.Owned(new (SemaRef.Context) CallExpr(
2612 SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(),
2613 Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00002614
Douglas Gregora16548e2009-08-11 05:31:07 +00002615 // Type-check the __builtin_shufflevector expression.
John Wiegley01296292011-04-08 18:41:53 +00002616 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.take()));
Douglas Gregora16548e2009-08-11 05:31:07 +00002617 }
John McCall31f82722010-11-12 08:19:04 +00002618
Hal Finkelc4d7c822013-09-18 03:29:45 +00002619 /// \brief Build a new convert vector expression.
2620 ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc,
2621 Expr *SrcExpr, TypeSourceInfo *DstTInfo,
2622 SourceLocation RParenLoc) {
2623 return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo,
2624 BuiltinLoc, RParenLoc);
2625 }
2626
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002627 /// \brief Build a new template argument pack expansion.
2628 ///
2629 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00002630 /// for a template argument. Subclasses may override this routine to provide
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002631 /// different behavior.
2632 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002633 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002634 Optional<unsigned> NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002635 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00002636 case TemplateArgument::Expression: {
2637 ExprResult Result
Douglas Gregorb8840002011-01-14 21:20:45 +00002638 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2639 EllipsisLoc, NumExpansions);
Douglas Gregor98318c22011-01-03 21:37:45 +00002640 if (Result.isInvalid())
2641 return TemplateArgumentLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00002642
Douglas Gregor98318c22011-01-03 21:37:45 +00002643 return TemplateArgumentLoc(Result.get(), Result.get());
2644 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002645
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002646 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002647 return TemplateArgumentLoc(TemplateArgument(
2648 Pattern.getArgument().getAsTemplate(),
Douglas Gregore1d60df2011-01-14 23:41:42 +00002649 NumExpansions),
Douglas Gregor9d802122011-03-02 17:09:35 +00002650 Pattern.getTemplateQualifierLoc(),
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002651 Pattern.getTemplateNameLoc(),
2652 EllipsisLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00002653
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002654 case TemplateArgument::Null:
2655 case TemplateArgument::Integral:
2656 case TemplateArgument::Declaration:
2657 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002658 case TemplateArgument::TemplateExpansion:
Eli Friedmanb826a002012-09-26 02:36:12 +00002659 case TemplateArgument::NullPtr:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002660 llvm_unreachable("Pack expansion pattern has no parameter packs");
Chad Rosier1dcde962012-08-08 18:46:20 +00002661
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002662 case TemplateArgument::Type:
Chad Rosier1dcde962012-08-08 18:46:20 +00002663 if (TypeSourceInfo *Expansion
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002664 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002665 EllipsisLoc,
2666 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002667 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2668 Expansion);
2669 break;
2670 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002671
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002672 return TemplateArgumentLoc();
2673 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002674
Douglas Gregor968f23a2011-01-03 19:31:53 +00002675 /// \brief Build a new expression pack expansion.
2676 ///
2677 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00002678 /// for an expression. Subclasses may override this routine to provide
Douglas Gregor968f23a2011-01-03 19:31:53 +00002679 /// different behavior.
Douglas Gregorb8840002011-01-14 21:20:45 +00002680 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002681 Optional<unsigned> NumExpansions) {
Douglas Gregorb8840002011-01-14 21:20:45 +00002682 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002683 }
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002684
2685 /// \brief Build a new atomic operation expression.
2686 ///
2687 /// By default, performs semantic analysis to build the new expression.
2688 /// Subclasses may override this routine to provide different behavior.
2689 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2690 MultiExprArg SubExprs,
2691 QualType RetTy,
2692 AtomicExpr::AtomicOp Op,
2693 SourceLocation RParenLoc) {
2694 // Just create the expression; there is not any interesting semantic
2695 // analysis here because we can't actually build an AtomicExpr until
2696 // we are sure it is semantically sound.
Benjamin Kramerc215e762012-08-24 11:54:20 +00002697 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002698 RParenLoc);
2699 }
2700
John McCall31f82722010-11-12 08:19:04 +00002701private:
Douglas Gregor14454802011-02-25 02:25:35 +00002702 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2703 QualType ObjectType,
2704 NamedDecl *FirstQualifierInScope,
2705 CXXScopeSpec &SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00002706
2707 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2708 QualType ObjectType,
2709 NamedDecl *FirstQualifierInScope,
2710 CXXScopeSpec &SS);
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00002711
2712 TypeSourceInfo *TransformTSIInObjectScope(TypeLoc TL, QualType ObjectType,
2713 NamedDecl *FirstQualifierInScope,
2714 CXXScopeSpec &SS);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002715};
Douglas Gregora16548e2009-08-11 05:31:07 +00002716
Douglas Gregorebe10102009-08-20 07:17:43 +00002717template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002718StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002719 if (!S)
2720 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00002721
Douglas Gregorebe10102009-08-20 07:17:43 +00002722 switch (S->getStmtClass()) {
2723 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00002724
Douglas Gregorebe10102009-08-20 07:17:43 +00002725 // Transform individual statement nodes
2726#define STMT(Node, Parent) \
2727 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCallbd066782011-02-09 08:16:59 +00002728#define ABSTRACT_STMT(Node)
Douglas Gregorebe10102009-08-20 07:17:43 +00002729#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00002730#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002731
Douglas Gregorebe10102009-08-20 07:17:43 +00002732 // Transform expressions by calling TransformExpr.
2733#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00002734#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00002735#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00002736#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00002737 {
John McCalldadc5752010-08-24 06:29:42 +00002738 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00002739 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002740 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002741
Richard Smith945f8d32013-01-14 22:39:08 +00002742 return getSema().ActOnExprStmt(E);
Douglas Gregorebe10102009-08-20 07:17:43 +00002743 }
Mike Stump11289f42009-09-09 15:08:12 +00002744 }
2745
John McCallc3007a22010-10-26 07:05:15 +00002746 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00002747}
Mike Stump11289f42009-09-09 15:08:12 +00002748
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00002749template<typename Derived>
2750OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) {
2751 if (!S)
2752 return S;
2753
2754 switch (S->getClauseKind()) {
2755 default: break;
2756 // Transform individual clause nodes
2757#define OPENMP_CLAUSE(Name, Class) \
2758 case OMPC_ ## Name : \
2759 return getDerived().Transform ## Class(cast<Class>(S));
2760#include "clang/Basic/OpenMPKinds.def"
2761 }
2762
2763 return S;
2764}
2765
Mike Stump11289f42009-09-09 15:08:12 +00002766
Douglas Gregore922c772009-08-04 22:27:00 +00002767template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002768ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002769 if (!E)
2770 return SemaRef.Owned(E);
2771
2772 switch (E->getStmtClass()) {
2773 case Stmt::NoStmtClass: break;
2774#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00002775#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00002776#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00002777 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00002778#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002779 }
2780
John McCallc3007a22010-10-26 07:05:15 +00002781 return SemaRef.Owned(E);
Douglas Gregor766b0bb2009-08-06 22:17:10 +00002782}
2783
2784template<typename Derived>
Richard Smithd59b8322012-12-19 01:39:02 +00002785ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
2786 bool CXXDirectInit) {
2787 // Initializers are instantiated like expressions, except that various outer
2788 // layers are stripped.
2789 if (!Init)
2790 return SemaRef.Owned(Init);
2791
2792 if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init))
2793 Init = ExprTemp->getSubExpr();
2794
Richard Smithe6ca4752013-05-30 22:40:16 +00002795 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
2796 Init = MTE->GetTemporaryExpr();
2797
Richard Smithd59b8322012-12-19 01:39:02 +00002798 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
2799 Init = Binder->getSubExpr();
2800
2801 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
2802 Init = ICE->getSubExprAsWritten();
2803
Richard Smithcc1b96d2013-06-12 22:31:48 +00002804 if (CXXStdInitializerListExpr *ILE =
2805 dyn_cast<CXXStdInitializerListExpr>(Init))
2806 return TransformInitializer(ILE->getSubExpr(), CXXDirectInit);
2807
Richard Smith38a549b2012-12-21 08:13:35 +00002808 // If this is not a direct-initializer, we only need to reconstruct
2809 // InitListExprs. Other forms of copy-initialization will be a no-op if
2810 // the initializer is already the right type.
2811 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
2812 if (!CXXDirectInit && !(Construct && Construct->isListInitialization()))
2813 return getDerived().TransformExpr(Init);
2814
2815 // Revert value-initialization back to empty parens.
2816 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
2817 SourceRange Parens = VIE->getSourceRange();
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002818 return getDerived().RebuildParenListExpr(Parens.getBegin(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00002819 Parens.getEnd());
2820 }
2821
2822 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
2823 if (isa<ImplicitValueInitExpr>(Init))
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002824 return getDerived().RebuildParenListExpr(SourceLocation(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00002825 SourceLocation());
2826
2827 // Revert initialization by constructor back to a parenthesized or braced list
2828 // of expressions. Any other form of initializer can just be reused directly.
2829 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
Richard Smithd59b8322012-12-19 01:39:02 +00002830 return getDerived().TransformExpr(Init);
2831
2832 SmallVector<Expr*, 8> NewArgs;
2833 bool ArgChanged = false;
2834 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
2835 /*IsCall*/true, NewArgs, &ArgChanged))
2836 return ExprError();
2837
2838 // If this was list initialization, revert to list form.
2839 if (Construct->isListInitialization())
2840 return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs,
2841 Construct->getLocEnd(),
2842 Construct->getType());
2843
Richard Smithd59b8322012-12-19 01:39:02 +00002844 // Build a ParenListExpr to represent anything else.
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00002845 SourceRange Parens = Construct->getParenOrBraceRange();
Richard Smithd59b8322012-12-19 01:39:02 +00002846 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
2847 Parens.getEnd());
2848}
2849
2850template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00002851bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2852 unsigned NumInputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00002853 bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +00002854 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00002855 bool *ArgChanged) {
2856 for (unsigned I = 0; I != NumInputs; ++I) {
2857 // If requested, drop call arguments that need to be dropped.
2858 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2859 if (ArgChanged)
2860 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002861
Douglas Gregora3efea12011-01-03 19:04:46 +00002862 break;
2863 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002864
Douglas Gregor968f23a2011-01-03 19:31:53 +00002865 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2866 Expr *Pattern = Expansion->getPattern();
Chad Rosier1dcde962012-08-08 18:46:20 +00002867
Chris Lattner01cf8db2011-07-20 06:58:45 +00002868 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor968f23a2011-01-03 19:31:53 +00002869 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2870 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00002871
Douglas Gregor968f23a2011-01-03 19:31:53 +00002872 // Determine whether the set of unexpanded parameter packs can and should
2873 // be expanded.
2874 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002875 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00002876 Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
2877 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor968f23a2011-01-03 19:31:53 +00002878 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2879 Pattern->getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00002880 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002881 Expand, RetainExpansion,
2882 NumExpansions))
Douglas Gregor968f23a2011-01-03 19:31:53 +00002883 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002884
Douglas Gregor968f23a2011-01-03 19:31:53 +00002885 if (!Expand) {
2886 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00002887 // transformation on the pack expansion, producing another pack
Douglas Gregor968f23a2011-01-03 19:31:53 +00002888 // expansion.
2889 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2890 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2891 if (OutPattern.isInvalid())
2892 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002893
2894 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregorb8840002011-01-14 21:20:45 +00002895 Expansion->getEllipsisLoc(),
2896 NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002897 if (Out.isInvalid())
2898 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002899
Douglas Gregor968f23a2011-01-03 19:31:53 +00002900 if (ArgChanged)
2901 *ArgChanged = true;
2902 Outputs.push_back(Out.get());
2903 continue;
2904 }
John McCall542e7c62011-07-06 07:30:07 +00002905
2906 // Record right away that the argument was changed. This needs
2907 // to happen even if the array expands to nothing.
2908 if (ArgChanged) *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002909
Douglas Gregor968f23a2011-01-03 19:31:53 +00002910 // The transform has determined that we should perform an elementwise
2911 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002912 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor968f23a2011-01-03 19:31:53 +00002913 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2914 ExprResult Out = getDerived().TransformExpr(Pattern);
2915 if (Out.isInvalid())
2916 return true;
2917
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002918 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregorb8840002011-01-14 21:20:45 +00002919 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2920 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002921 if (Out.isInvalid())
2922 return true;
2923 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002924
Douglas Gregor968f23a2011-01-03 19:31:53 +00002925 Outputs.push_back(Out.get());
2926 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002927
Douglas Gregor968f23a2011-01-03 19:31:53 +00002928 continue;
2929 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002930
Richard Smithd59b8322012-12-19 01:39:02 +00002931 ExprResult Result =
2932 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
2933 : getDerived().TransformExpr(Inputs[I]);
Douglas Gregora3efea12011-01-03 19:04:46 +00002934 if (Result.isInvalid())
2935 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002936
Douglas Gregora3efea12011-01-03 19:04:46 +00002937 if (Result.get() != Inputs[I] && ArgChanged)
2938 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002939
2940 Outputs.push_back(Result.get());
Douglas Gregora3efea12011-01-03 19:04:46 +00002941 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002942
Douglas Gregora3efea12011-01-03 19:04:46 +00002943 return false;
2944}
2945
2946template<typename Derived>
Douglas Gregor14454802011-02-25 02:25:35 +00002947NestedNameSpecifierLoc
2948TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2949 NestedNameSpecifierLoc NNS,
2950 QualType ObjectType,
2951 NamedDecl *FirstQualifierInScope) {
Chris Lattner01cf8db2011-07-20 06:58:45 +00002952 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier1dcde962012-08-08 18:46:20 +00002953 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregor14454802011-02-25 02:25:35 +00002954 Qualifier = Qualifier.getPrefix())
2955 Qualifiers.push_back(Qualifier);
2956
2957 CXXScopeSpec SS;
2958 while (!Qualifiers.empty()) {
2959 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2960 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier1dcde962012-08-08 18:46:20 +00002961
Douglas Gregor14454802011-02-25 02:25:35 +00002962 switch (QNNS->getKind()) {
2963 case NestedNameSpecifier::Identifier:
Chad Rosier1dcde962012-08-08 18:46:20 +00002964 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
Douglas Gregor14454802011-02-25 02:25:35 +00002965 *QNNS->getAsIdentifier(),
Chad Rosier1dcde962012-08-08 18:46:20 +00002966 Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00002967 Q.getLocalEndLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00002968 ObjectType, false, SS,
Douglas Gregor14454802011-02-25 02:25:35 +00002969 FirstQualifierInScope, false))
2970 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00002971
Douglas Gregor14454802011-02-25 02:25:35 +00002972 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00002973
Douglas Gregor14454802011-02-25 02:25:35 +00002974 case NestedNameSpecifier::Namespace: {
2975 NamespaceDecl *NS
2976 = cast_or_null<NamespaceDecl>(
2977 getDerived().TransformDecl(
2978 Q.getLocalBeginLoc(),
2979 QNNS->getAsNamespace()));
2980 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2981 break;
2982 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002983
Douglas Gregor14454802011-02-25 02:25:35 +00002984 case NestedNameSpecifier::NamespaceAlias: {
2985 NamespaceAliasDecl *Alias
2986 = cast_or_null<NamespaceAliasDecl>(
2987 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2988 QNNS->getAsNamespaceAlias()));
Chad Rosier1dcde962012-08-08 18:46:20 +00002989 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00002990 Q.getLocalEndLoc());
2991 break;
2992 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002993
Douglas Gregor14454802011-02-25 02:25:35 +00002994 case NestedNameSpecifier::Global:
2995 // There is no meaningful transformation that one could perform on the
2996 // global scope.
2997 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2998 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00002999
Douglas Gregor14454802011-02-25 02:25:35 +00003000 case NestedNameSpecifier::TypeSpecWithTemplate:
3001 case NestedNameSpecifier::TypeSpec: {
3002 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
3003 FirstQualifierInScope, SS);
Chad Rosier1dcde962012-08-08 18:46:20 +00003004
Douglas Gregor14454802011-02-25 02:25:35 +00003005 if (!TL)
3006 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003007
Douglas Gregor14454802011-02-25 02:25:35 +00003008 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Richard Smith2bf7fdb2013-01-02 11:42:31 +00003009 (SemaRef.getLangOpts().CPlusPlus11 &&
Douglas Gregor14454802011-02-25 02:25:35 +00003010 TL.getType()->isEnumeralType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003011 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003012 "Can't get cv-qualifiers here");
Richard Smith91c7bbd2011-10-20 03:28:47 +00003013 if (TL.getType()->isEnumeralType())
3014 SemaRef.Diag(TL.getBeginLoc(),
3015 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregor14454802011-02-25 02:25:35 +00003016 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
3017 Q.getLocalEndLoc());
3018 break;
3019 }
Richard Trieude756fb2011-05-07 01:36:37 +00003020 // If the nested-name-specifier is an invalid type def, don't emit an
3021 // error because a previous error should have already been emitted.
David Blaikie6adc78e2013-02-18 22:06:02 +00003022 TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
3023 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003024 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieude756fb2011-05-07 01:36:37 +00003025 << TL.getType() << SS.getRange();
3026 }
Douglas Gregor14454802011-02-25 02:25:35 +00003027 return NestedNameSpecifierLoc();
3028 }
Douglas Gregore16af532011-02-28 18:50:33 +00003029 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003030
Douglas Gregore16af532011-02-28 18:50:33 +00003031 // The qualifier-in-scope and object type only apply to the leftmost entity.
Douglas Gregor14454802011-02-25 02:25:35 +00003032 FirstQualifierInScope = 0;
Douglas Gregore16af532011-02-28 18:50:33 +00003033 ObjectType = QualType();
Douglas Gregor14454802011-02-25 02:25:35 +00003034 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003035
Douglas Gregor14454802011-02-25 02:25:35 +00003036 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier1dcde962012-08-08 18:46:20 +00003037 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003038 !getDerived().AlwaysRebuild())
3039 return NNS;
Chad Rosier1dcde962012-08-08 18:46:20 +00003040
3041 // If we can re-use the source-location data from the original
Douglas Gregor14454802011-02-25 02:25:35 +00003042 // nested-name-specifier, do so.
3043 if (SS.location_size() == NNS.getDataLength() &&
3044 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
3045 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
3046
3047 // Allocate new nested-name-specifier location information.
3048 return SS.getWithLocInContext(SemaRef.Context);
3049}
3050
3051template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003052DeclarationNameInfo
3053TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00003054::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003055 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003056 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003057 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003058
3059 switch (Name.getNameKind()) {
3060 case DeclarationName::Identifier:
3061 case DeclarationName::ObjCZeroArgSelector:
3062 case DeclarationName::ObjCOneArgSelector:
3063 case DeclarationName::ObjCMultiArgSelector:
3064 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00003065 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00003066 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003067 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00003068
Douglas Gregorf816bd72009-09-03 22:13:48 +00003069 case DeclarationName::CXXConstructorName:
3070 case DeclarationName::CXXDestructorName:
3071 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003072 TypeSourceInfo *NewTInfo;
3073 CanQualType NewCanTy;
3074 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00003075 NewTInfo = getDerived().TransformType(OldTInfo);
3076 if (!NewTInfo)
3077 return DeclarationNameInfo();
3078 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003079 }
3080 else {
3081 NewTInfo = 0;
3082 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00003083 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003084 if (NewT.isNull())
3085 return DeclarationNameInfo();
3086 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
3087 }
Mike Stump11289f42009-09-09 15:08:12 +00003088
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003089 DeclarationName NewName
3090 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
3091 NewCanTy);
3092 DeclarationNameInfo NewNameInfo(NameInfo);
3093 NewNameInfo.setName(NewName);
3094 NewNameInfo.setNamedTypeInfo(NewTInfo);
3095 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00003096 }
Mike Stump11289f42009-09-09 15:08:12 +00003097 }
3098
David Blaikie83d382b2011-09-23 05:06:16 +00003099 llvm_unreachable("Unknown name kind.");
Douglas Gregorf816bd72009-09-03 22:13:48 +00003100}
3101
3102template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003103TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00003104TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
3105 TemplateName Name,
3106 SourceLocation NameLoc,
3107 QualType ObjectType,
3108 NamedDecl *FirstQualifierInScope) {
3109 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
3110 TemplateDecl *Template = QTN->getTemplateDecl();
3111 assert(Template && "qualified template name must refer to a template");
Chad Rosier1dcde962012-08-08 18:46:20 +00003112
Douglas Gregor9db53502011-03-02 18:07:45 +00003113 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003114 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003115 Template));
3116 if (!TransTemplate)
3117 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003118
Douglas Gregor9db53502011-03-02 18:07:45 +00003119 if (!getDerived().AlwaysRebuild() &&
3120 SS.getScopeRep() == QTN->getQualifier() &&
3121 TransTemplate == Template)
3122 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003123
Douglas Gregor9db53502011-03-02 18:07:45 +00003124 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
3125 TransTemplate);
3126 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003127
Douglas Gregor9db53502011-03-02 18:07:45 +00003128 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
3129 if (SS.getScopeRep()) {
3130 // These apply to the scope specifier, not the template.
3131 ObjectType = QualType();
3132 FirstQualifierInScope = 0;
Chad Rosier1dcde962012-08-08 18:46:20 +00003133 }
3134
Douglas Gregor9db53502011-03-02 18:07:45 +00003135 if (!getDerived().AlwaysRebuild() &&
3136 SS.getScopeRep() == DTN->getQualifier() &&
3137 ObjectType.isNull())
3138 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003139
Douglas Gregor9db53502011-03-02 18:07:45 +00003140 if (DTN->isIdentifier()) {
3141 return getDerived().RebuildTemplateName(SS,
Chad Rosier1dcde962012-08-08 18:46:20 +00003142 *DTN->getIdentifier(),
Douglas Gregor9db53502011-03-02 18:07:45 +00003143 NameLoc,
3144 ObjectType,
3145 FirstQualifierInScope);
3146 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003147
Douglas Gregor9db53502011-03-02 18:07:45 +00003148 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
3149 ObjectType);
3150 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003151
Douglas Gregor9db53502011-03-02 18:07:45 +00003152 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
3153 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003154 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003155 Template));
3156 if (!TransTemplate)
3157 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003158
Douglas Gregor9db53502011-03-02 18:07:45 +00003159 if (!getDerived().AlwaysRebuild() &&
3160 TransTemplate == Template)
3161 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003162
Douglas Gregor9db53502011-03-02 18:07:45 +00003163 return TemplateName(TransTemplate);
3164 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003165
Douglas Gregor9db53502011-03-02 18:07:45 +00003166 if (SubstTemplateTemplateParmPackStorage *SubstPack
3167 = Name.getAsSubstTemplateTemplateParmPack()) {
3168 TemplateTemplateParmDecl *TransParam
3169 = cast_or_null<TemplateTemplateParmDecl>(
3170 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
3171 if (!TransParam)
3172 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003173
Douglas Gregor9db53502011-03-02 18:07:45 +00003174 if (!getDerived().AlwaysRebuild() &&
3175 TransParam == SubstPack->getParameterPack())
3176 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003177
3178 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregor9db53502011-03-02 18:07:45 +00003179 SubstPack->getArgumentPack());
3180 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003181
Douglas Gregor9db53502011-03-02 18:07:45 +00003182 // These should be getting filtered out before they reach the AST.
3183 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregor9db53502011-03-02 18:07:45 +00003184}
3185
3186template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003187void TreeTransform<Derived>::InventTemplateArgumentLoc(
3188 const TemplateArgument &Arg,
3189 TemplateArgumentLoc &Output) {
3190 SourceLocation Loc = getDerived().getBaseLocation();
3191 switch (Arg.getKind()) {
3192 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003193 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00003194 break;
3195
3196 case TemplateArgument::Type:
3197 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00003198 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier1dcde962012-08-08 18:46:20 +00003199
John McCall0ad16662009-10-29 08:12:44 +00003200 break;
3201
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003202 case TemplateArgument::Template:
Douglas Gregor9d802122011-03-02 17:09:35 +00003203 case TemplateArgument::TemplateExpansion: {
3204 NestedNameSpecifierLocBuilder Builder;
3205 TemplateName Template = Arg.getAsTemplate();
3206 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3207 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3208 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3209 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003210
Douglas Gregor9d802122011-03-02 17:09:35 +00003211 if (Arg.getKind() == TemplateArgument::Template)
Chad Rosier1dcde962012-08-08 18:46:20 +00003212 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003213 Builder.getWithLocInContext(SemaRef.Context),
3214 Loc);
3215 else
Chad Rosier1dcde962012-08-08 18:46:20 +00003216 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003217 Builder.getWithLocInContext(SemaRef.Context),
3218 Loc, Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003219
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003220 break;
Douglas Gregor9d802122011-03-02 17:09:35 +00003221 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003222
John McCall0ad16662009-10-29 08:12:44 +00003223 case TemplateArgument::Expression:
3224 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3225 break;
3226
3227 case TemplateArgument::Declaration:
3228 case TemplateArgument::Integral:
3229 case TemplateArgument::Pack:
Eli Friedmanb826a002012-09-26 02:36:12 +00003230 case TemplateArgument::NullPtr:
John McCall0d07eb32009-10-29 18:45:58 +00003231 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00003232 break;
3233 }
3234}
3235
3236template<typename Derived>
3237bool TreeTransform<Derived>::TransformTemplateArgument(
3238 const TemplateArgumentLoc &Input,
3239 TemplateArgumentLoc &Output) {
3240 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00003241 switch (Arg.getKind()) {
3242 case TemplateArgument::Null:
3243 case TemplateArgument::Integral:
Eli Friedmancda3db82012-09-25 01:02:42 +00003244 case TemplateArgument::Pack:
3245 case TemplateArgument::Declaration:
Eli Friedmanb826a002012-09-26 02:36:12 +00003246 case TemplateArgument::NullPtr:
3247 llvm_unreachable("Unexpected TemplateArgument");
Mike Stump11289f42009-09-09 15:08:12 +00003248
Douglas Gregore922c772009-08-04 22:27:00 +00003249 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00003250 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall0ad16662009-10-29 08:12:44 +00003251 if (DI == NULL)
John McCallbcd03502009-12-07 02:54:59 +00003252 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00003253
3254 DI = getDerived().TransformType(DI);
3255 if (!DI) return true;
3256
3257 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3258 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003259 }
Mike Stump11289f42009-09-09 15:08:12 +00003260
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003261 case TemplateArgument::Template: {
Douglas Gregor9d802122011-03-02 17:09:35 +00003262 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3263 if (QualifierLoc) {
3264 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3265 if (!QualifierLoc)
3266 return true;
3267 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003268
Douglas Gregordf846d12011-03-02 18:46:51 +00003269 CXXScopeSpec SS;
3270 SS.Adopt(QualifierLoc);
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003271 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00003272 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3273 Input.getTemplateNameLoc());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003274 if (Template.isNull())
3275 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003276
Douglas Gregor9d802122011-03-02 17:09:35 +00003277 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003278 Input.getTemplateNameLoc());
3279 return false;
3280 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003281
3282 case TemplateArgument::TemplateExpansion:
3283 llvm_unreachable("Caller should expand pack expansions");
3284
Douglas Gregore922c772009-08-04 22:27:00 +00003285 case TemplateArgument::Expression: {
Richard Smith764d2fe2011-12-20 02:08:33 +00003286 // Template argument expressions are constant expressions.
Mike Stump11289f42009-09-09 15:08:12 +00003287 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smith764d2fe2011-12-20 02:08:33 +00003288 Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003289
John McCall0ad16662009-10-29 08:12:44 +00003290 Expr *InputExpr = Input.getSourceExpression();
3291 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3292
Chris Lattnercdb591a2011-04-25 20:37:58 +00003293 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanc6237c62012-02-29 03:16:56 +00003294 E = SemaRef.ActOnConstantExpression(E);
John McCall0ad16662009-10-29 08:12:44 +00003295 if (E.isInvalid()) return true;
John McCallb268a282010-08-23 23:25:46 +00003296 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall0ad16662009-10-29 08:12:44 +00003297 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003298 }
Douglas Gregore922c772009-08-04 22:27:00 +00003299 }
Mike Stump11289f42009-09-09 15:08:12 +00003300
Douglas Gregore922c772009-08-04 22:27:00 +00003301 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00003302 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00003303}
3304
Douglas Gregorfe921a72010-12-20 23:36:19 +00003305/// \brief Iterator adaptor that invents template argument location information
3306/// for each of the template arguments in its underlying iterator.
3307template<typename Derived, typename InputIterator>
3308class TemplateArgumentLocInventIterator {
3309 TreeTransform<Derived> &Self;
3310 InputIterator Iter;
Chad Rosier1dcde962012-08-08 18:46:20 +00003311
Douglas Gregorfe921a72010-12-20 23:36:19 +00003312public:
3313 typedef TemplateArgumentLoc value_type;
3314 typedef TemplateArgumentLoc reference;
3315 typedef typename std::iterator_traits<InputIterator>::difference_type
3316 difference_type;
3317 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00003318
Douglas Gregorfe921a72010-12-20 23:36:19 +00003319 class pointer {
3320 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00003321
Douglas Gregorfe921a72010-12-20 23:36:19 +00003322 public:
3323 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003324
Douglas Gregorfe921a72010-12-20 23:36:19 +00003325 const TemplateArgumentLoc *operator->() const { return &Arg; }
3326 };
Chad Rosier1dcde962012-08-08 18:46:20 +00003327
Douglas Gregorfe921a72010-12-20 23:36:19 +00003328 TemplateArgumentLocInventIterator() { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003329
Douglas Gregorfe921a72010-12-20 23:36:19 +00003330 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3331 InputIterator Iter)
3332 : Self(Self), Iter(Iter) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003333
Douglas Gregorfe921a72010-12-20 23:36:19 +00003334 TemplateArgumentLocInventIterator &operator++() {
3335 ++Iter;
3336 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00003337 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003338
Douglas Gregorfe921a72010-12-20 23:36:19 +00003339 TemplateArgumentLocInventIterator operator++(int) {
3340 TemplateArgumentLocInventIterator Old(*this);
3341 ++(*this);
3342 return Old;
3343 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003344
Douglas Gregorfe921a72010-12-20 23:36:19 +00003345 reference operator*() const {
3346 TemplateArgumentLoc Result;
3347 Self.InventTemplateArgumentLoc(*Iter, Result);
3348 return Result;
3349 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003350
Douglas Gregorfe921a72010-12-20 23:36:19 +00003351 pointer operator->() const { return pointer(**this); }
Chad Rosier1dcde962012-08-08 18:46:20 +00003352
Douglas Gregorfe921a72010-12-20 23:36:19 +00003353 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3354 const TemplateArgumentLocInventIterator &Y) {
3355 return X.Iter == Y.Iter;
3356 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00003357
Douglas Gregorfe921a72010-12-20 23:36:19 +00003358 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3359 const TemplateArgumentLocInventIterator &Y) {
3360 return X.Iter != Y.Iter;
3361 }
3362};
Chad Rosier1dcde962012-08-08 18:46:20 +00003363
Douglas Gregor42cafa82010-12-20 17:42:22 +00003364template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00003365template<typename InputIterator>
3366bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3367 InputIterator Last,
Douglas Gregor42cafa82010-12-20 17:42:22 +00003368 TemplateArgumentListInfo &Outputs) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00003369 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00003370 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00003371 TemplateArgumentLoc In = *First;
Chad Rosier1dcde962012-08-08 18:46:20 +00003372
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003373 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3374 // Unpack argument packs, which we translate them into separate
3375 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00003376 // FIXME: We could do much better if we could guarantee that the
3377 // TemplateArgumentLocInfo for the pack expansion would be usable for
3378 // all of the template arguments in the argument pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00003379 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003380 TemplateArgument::pack_iterator>
3381 PackLocIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00003382 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003383 In.getArgument().pack_begin()),
3384 PackLocIterator(*this,
3385 In.getArgument().pack_end()),
3386 Outputs))
3387 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003388
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003389 continue;
3390 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003391
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003392 if (In.getArgument().isPackExpansion()) {
3393 // We have a pack expansion, for which we will be substituting into
3394 // the pattern.
3395 SourceLocation Ellipsis;
David Blaikie05785d12013-02-20 22:23:23 +00003396 Optional<unsigned> OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003397 TemplateArgumentLoc Pattern
Eli Friedman94e9eaa2013-06-20 04:11:21 +00003398 = getSema().getTemplateArgumentPackExpansionPattern(
3399 In, Ellipsis, OrigNumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00003400
Chris Lattner01cf8db2011-07-20 06:58:45 +00003401 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003402 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3403 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00003404
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003405 // Determine whether the set of unexpanded parameter packs can and should
3406 // be expanded.
3407 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003408 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00003409 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003410 if (getDerived().TryExpandParameterPacks(Ellipsis,
3411 Pattern.getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003412 Unexpanded,
Chad Rosier1dcde962012-08-08 18:46:20 +00003413 Expand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003414 RetainExpansion,
3415 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003416 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003417
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003418 if (!Expand) {
3419 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00003420 // transformation on the pack expansion, producing another pack
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003421 // expansion.
3422 TemplateArgumentLoc OutPattern;
3423 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3424 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3425 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003426
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003427 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3428 NumExpansions);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003429 if (Out.getArgument().isNull())
3430 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003431
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003432 Outputs.addArgument(Out);
3433 continue;
3434 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003435
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003436 // The transform has determined that we should perform an elementwise
3437 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003438 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003439 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3440
3441 if (getDerived().TransformTemplateArgument(Pattern, Out))
3442 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003443
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003444 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003445 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3446 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003447 if (Out.getArgument().isNull())
3448 return true;
3449 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003450
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003451 Outputs.addArgument(Out);
3452 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003453
Douglas Gregor48d24112011-01-10 20:53:55 +00003454 // If we're supposed to retain a pack expansion, do so by temporarily
3455 // forgetting the partially-substituted parameter pack.
3456 if (RetainExpansion) {
3457 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00003458
Douglas Gregor48d24112011-01-10 20:53:55 +00003459 if (getDerived().TransformTemplateArgument(Pattern, Out))
3460 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003461
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003462 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3463 OrigNumExpansions);
Douglas Gregor48d24112011-01-10 20:53:55 +00003464 if (Out.getArgument().isNull())
3465 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003466
Douglas Gregor48d24112011-01-10 20:53:55 +00003467 Outputs.addArgument(Out);
3468 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003469
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003470 continue;
3471 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003472
3473 // The simple case:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003474 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor42cafa82010-12-20 17:42:22 +00003475 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003476
Douglas Gregor42cafa82010-12-20 17:42:22 +00003477 Outputs.addArgument(Out);
3478 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003479
Douglas Gregor42cafa82010-12-20 17:42:22 +00003480 return false;
3481
3482}
3483
Douglas Gregord6ff3322009-08-04 16:50:30 +00003484//===----------------------------------------------------------------------===//
3485// Type transformation
3486//===----------------------------------------------------------------------===//
3487
3488template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003489QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00003490 if (getDerived().AlreadyTransformed(T))
3491 return T;
Mike Stump11289f42009-09-09 15:08:12 +00003492
John McCall550e0c22009-10-21 00:40:46 +00003493 // Temporary workaround. All of these transformations should
3494 // eventually turn into transformations on TypeLocs.
Douglas Gregor2d525f02011-01-25 19:13:18 +00003495 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3496 getDerived().getBaseLocation());
Chad Rosier1dcde962012-08-08 18:46:20 +00003497
John McCall31f82722010-11-12 08:19:04 +00003498 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00003499
John McCall550e0c22009-10-21 00:40:46 +00003500 if (!NewDI)
3501 return QualType();
3502
3503 return NewDI->getType();
3504}
3505
3506template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003507TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smith764d2fe2011-12-20 02:08:33 +00003508 // Refine the base location to the type's location.
3509 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3510 getDerived().getBaseEntity());
John McCall550e0c22009-10-21 00:40:46 +00003511 if (getDerived().AlreadyTransformed(DI->getType()))
3512 return DI;
3513
3514 TypeLocBuilder TLB;
3515
3516 TypeLoc TL = DI->getTypeLoc();
3517 TLB.reserve(TL.getFullDataSize());
3518
John McCall31f82722010-11-12 08:19:04 +00003519 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00003520 if (Result.isNull())
3521 return 0;
3522
John McCallbcd03502009-12-07 02:54:59 +00003523 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00003524}
3525
3526template<typename Derived>
3527QualType
John McCall31f82722010-11-12 08:19:04 +00003528TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003529 switch (T.getTypeLocClass()) {
3530#define ABSTRACT_TYPELOC(CLASS, PARENT)
David Blaikie6adc78e2013-02-18 22:06:02 +00003531#define TYPELOC(CLASS, PARENT) \
3532 case TypeLoc::CLASS: \
3533 return getDerived().Transform##CLASS##Type(TLB, \
3534 T.castAs<CLASS##TypeLoc>());
John McCall550e0c22009-10-21 00:40:46 +00003535#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00003536 }
Mike Stump11289f42009-09-09 15:08:12 +00003537
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003538 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00003539}
3540
3541/// FIXME: By default, this routine adds type qualifiers only to types
3542/// that can have qualifiers, and silently suppresses those qualifiers
3543/// that are not permitted (e.g., qualifiers on reference or function
3544/// types). This is the right thing for template instantiation, but
3545/// probably not for other clients.
3546template<typename Derived>
3547QualType
3548TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003549 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00003550 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00003551
John McCall31f82722010-11-12 08:19:04 +00003552 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00003553 if (Result.isNull())
3554 return QualType();
3555
3556 // Silently suppress qualifiers if the result type can't be qualified.
3557 // FIXME: this is the right thing for template instantiation, but
3558 // probably not for other clients.
3559 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00003560 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00003561
John McCall31168b02011-06-15 23:02:42 +00003562 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore46db902011-06-17 22:11:49 +00003563 // resulting type.
3564 if (Quals.hasObjCLifetime()) {
3565 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3566 Quals.removeObjCLifetime();
Douglas Gregord7357a92011-06-17 23:16:24 +00003567 else if (Result.getObjCLifetime()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003568 // Objective-C ARC:
Douglas Gregore46db902011-06-17 22:11:49 +00003569 // A lifetime qualifier applied to a substituted template parameter
3570 // overrides the lifetime qualifier from the template argument.
Douglas Gregorf4e43312013-01-17 23:59:28 +00003571 const AutoType *AutoTy;
Chad Rosier1dcde962012-08-08 18:46:20 +00003572 if (const SubstTemplateTypeParmType *SubstTypeParam
Douglas Gregore46db902011-06-17 22:11:49 +00003573 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3574 QualType Replacement = SubstTypeParam->getReplacementType();
3575 Qualifiers Qs = Replacement.getQualifiers();
3576 Qs.removeObjCLifetime();
Chad Rosier1dcde962012-08-08 18:46:20 +00003577 Replacement
Douglas Gregore46db902011-06-17 22:11:49 +00003578 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3579 Qs);
3580 Result = SemaRef.Context.getSubstTemplateTypeParmType(
Chad Rosier1dcde962012-08-08 18:46:20 +00003581 SubstTypeParam->getReplacedParameter(),
Douglas Gregore46db902011-06-17 22:11:49 +00003582 Replacement);
3583 TLB.TypeWasModifiedSafely(Result);
Douglas Gregorf4e43312013-01-17 23:59:28 +00003584 } else if ((AutoTy = dyn_cast<AutoType>(Result)) && AutoTy->isDeduced()) {
3585 // 'auto' types behave the same way as template parameters.
3586 QualType Deduced = AutoTy->getDeducedType();
3587 Qualifiers Qs = Deduced.getQualifiers();
3588 Qs.removeObjCLifetime();
3589 Deduced = SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(),
3590 Qs);
Faisal Vali2b391ab2013-09-26 19:54:12 +00003591 Result = SemaRef.Context.getAutoType(Deduced, AutoTy->isDecltypeAuto(),
3592 AutoTy->isDependentType());
Douglas Gregorf4e43312013-01-17 23:59:28 +00003593 TLB.TypeWasModifiedSafely(Result);
Douglas Gregore46db902011-06-17 22:11:49 +00003594 } else {
Douglas Gregord7357a92011-06-17 23:16:24 +00003595 // Otherwise, complain about the addition of a qualifier to an
3596 // already-qualified type.
Eli Friedman7152fbe2013-06-07 20:31:48 +00003597 SourceRange R = T.getUnqualifiedLoc().getSourceRange();
Argyrios Kyrtzidiscff00d92011-06-24 00:08:59 +00003598 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregord7357a92011-06-17 23:16:24 +00003599 << Result << R;
Chad Rosier1dcde962012-08-08 18:46:20 +00003600
Douglas Gregore46db902011-06-17 22:11:49 +00003601 Quals.removeObjCLifetime();
3602 }
3603 }
3604 }
John McCallcb0f89a2010-06-05 06:41:15 +00003605 if (!Quals.empty()) {
3606 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
Richard Smithdeec0742013-03-27 23:36:39 +00003607 // BuildQualifiedType might not add qualifiers if they are invalid.
3608 if (Result.hasLocalQualifiers())
3609 TLB.push<QualifiedTypeLoc>(Result);
John McCallcb0f89a2010-06-05 06:41:15 +00003610 // No location information to preserve.
3611 }
John McCall550e0c22009-10-21 00:40:46 +00003612
3613 return Result;
3614}
3615
Douglas Gregor14454802011-02-25 02:25:35 +00003616template<typename Derived>
3617TypeLoc
3618TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3619 QualType ObjectType,
3620 NamedDecl *UnqualLookup,
3621 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003622 if (getDerived().AlreadyTransformed(TL.getType()))
Douglas Gregor14454802011-02-25 02:25:35 +00003623 return TL;
Chad Rosier1dcde962012-08-08 18:46:20 +00003624
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003625 TypeSourceInfo *TSI =
3626 TransformTSIInObjectScope(TL, ObjectType, UnqualLookup, SS);
3627 if (TSI)
3628 return TSI->getTypeLoc();
3629 return TypeLoc();
Douglas Gregor14454802011-02-25 02:25:35 +00003630}
3631
Douglas Gregor579c15f2011-03-02 18:32:08 +00003632template<typename Derived>
3633TypeSourceInfo *
3634TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3635 QualType ObjectType,
3636 NamedDecl *UnqualLookup,
3637 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003638 if (getDerived().AlreadyTransformed(TSInfo->getType()))
Douglas Gregor579c15f2011-03-02 18:32:08 +00003639 return TSInfo;
Chad Rosier1dcde962012-08-08 18:46:20 +00003640
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003641 return TransformTSIInObjectScope(TSInfo->getTypeLoc(), ObjectType,
3642 UnqualLookup, SS);
3643}
3644
3645template <typename Derived>
3646TypeSourceInfo *TreeTransform<Derived>::TransformTSIInObjectScope(
3647 TypeLoc TL, QualType ObjectType, NamedDecl *UnqualLookup,
3648 CXXScopeSpec &SS) {
3649 QualType T = TL.getType();
3650 assert(!getDerived().AlreadyTransformed(T));
3651
Douglas Gregor579c15f2011-03-02 18:32:08 +00003652 TypeLocBuilder TLB;
3653 QualType Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00003654
Douglas Gregor579c15f2011-03-02 18:32:08 +00003655 if (isa<TemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00003656 TemplateSpecializationTypeLoc SpecTL =
3657 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00003658
Douglas Gregor579c15f2011-03-02 18:32:08 +00003659 TemplateName Template
3660 = getDerived().TransformTemplateName(SS,
3661 SpecTL.getTypePtr()->getTemplateName(),
3662 SpecTL.getTemplateNameLoc(),
3663 ObjectType, UnqualLookup);
Chad Rosier1dcde962012-08-08 18:46:20 +00003664 if (Template.isNull())
Douglas Gregor579c15f2011-03-02 18:32:08 +00003665 return 0;
Chad Rosier1dcde962012-08-08 18:46:20 +00003666
3667 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregor579c15f2011-03-02 18:32:08 +00003668 Template);
3669 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00003670 DependentTemplateSpecializationTypeLoc SpecTL =
3671 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00003672
Douglas Gregor579c15f2011-03-02 18:32:08 +00003673 TemplateName Template
Chad Rosier1dcde962012-08-08 18:46:20 +00003674 = getDerived().RebuildTemplateName(SS,
3675 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00003676 SpecTL.getTemplateNameLoc(),
Douglas Gregor579c15f2011-03-02 18:32:08 +00003677 ObjectType, UnqualLookup);
3678 if (Template.isNull())
3679 return 0;
Chad Rosier1dcde962012-08-08 18:46:20 +00003680
3681 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregor579c15f2011-03-02 18:32:08 +00003682 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00003683 Template,
3684 SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00003685 } else {
3686 // Nothing special needs to be done for these.
3687 Result = getDerived().TransformType(TLB, TL);
3688 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003689
3690 if (Result.isNull())
Douglas Gregor579c15f2011-03-02 18:32:08 +00003691 return 0;
Chad Rosier1dcde962012-08-08 18:46:20 +00003692
Douglas Gregor579c15f2011-03-02 18:32:08 +00003693 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3694}
3695
John McCall550e0c22009-10-21 00:40:46 +00003696template <class TyLoc> static inline
3697QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3698 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3699 NewT.setNameLoc(T.getNameLoc());
3700 return T.getType();
3701}
3702
John McCall550e0c22009-10-21 00:40:46 +00003703template<typename Derived>
3704QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003705 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00003706 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3707 NewT.setBuiltinLoc(T.getBuiltinLoc());
3708 if (T.needsExtraLocalData())
3709 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3710 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003711}
Mike Stump11289f42009-09-09 15:08:12 +00003712
Douglas Gregord6ff3322009-08-04 16:50:30 +00003713template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003714QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003715 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003716 // FIXME: recurse?
3717 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003718}
Mike Stump11289f42009-09-09 15:08:12 +00003719
Reid Kleckner0503a872013-12-05 01:23:43 +00003720template <typename Derived>
3721QualType TreeTransform<Derived>::TransformAdjustedType(TypeLocBuilder &TLB,
3722 AdjustedTypeLoc TL) {
3723 // Adjustments applied during transformation are handled elsewhere.
3724 return getDerived().TransformType(TLB, TL.getOriginalLoc());
3725}
3726
Douglas Gregord6ff3322009-08-04 16:50:30 +00003727template<typename Derived>
Reid Kleckner8a365022013-06-24 17:51:48 +00003728QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
3729 DecayedTypeLoc TL) {
3730 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
3731 if (OriginalType.isNull())
3732 return QualType();
3733
3734 QualType Result = TL.getType();
3735 if (getDerived().AlwaysRebuild() ||
3736 OriginalType != TL.getOriginalLoc().getType())
3737 Result = SemaRef.Context.getDecayedType(OriginalType);
3738 TLB.push<DecayedTypeLoc>(Result);
3739 // Nothing to set for DecayedTypeLoc.
3740 return Result;
3741}
3742
3743template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003744QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003745 PointerTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003746 QualType PointeeType
3747 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003748 if (PointeeType.isNull())
3749 return QualType();
3750
3751 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00003752 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003753 // A dependent pointer type 'T *' has is being transformed such
3754 // that an Objective-C class type is being replaced for 'T'. The
3755 // resulting pointer type is an ObjCObjectPointerType, not a
3756 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00003757 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier1dcde962012-08-08 18:46:20 +00003758
John McCall8b07ec22010-05-15 11:32:37 +00003759 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3760 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003761 return Result;
3762 }
John McCall31f82722010-11-12 08:19:04 +00003763
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003764 if (getDerived().AlwaysRebuild() ||
3765 PointeeType != TL.getPointeeLoc().getType()) {
3766 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3767 if (Result.isNull())
3768 return QualType();
3769 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003770
John McCall31168b02011-06-15 23:02:42 +00003771 // Objective-C ARC can add lifetime qualifiers to the type that we're
3772 // pointing to.
3773 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier1dcde962012-08-08 18:46:20 +00003774
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003775 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3776 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00003777 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003778}
Mike Stump11289f42009-09-09 15:08:12 +00003779
3780template<typename Derived>
3781QualType
John McCall550e0c22009-10-21 00:40:46 +00003782TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003783 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00003784 QualType PointeeType
Chad Rosier1dcde962012-08-08 18:46:20 +00003785 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3786 if (PointeeType.isNull())
3787 return QualType();
3788
3789 QualType Result = TL.getType();
3790 if (getDerived().AlwaysRebuild() ||
3791 PointeeType != TL.getPointeeLoc().getType()) {
3792 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00003793 TL.getSigilLoc());
3794 if (Result.isNull())
3795 return QualType();
3796 }
3797
Douglas Gregor049211a2010-04-22 16:50:51 +00003798 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00003799 NewT.setSigilLoc(TL.getSigilLoc());
3800 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003801}
3802
John McCall70dd5f62009-10-30 00:06:24 +00003803/// Transforms a reference type. Note that somewhat paradoxically we
3804/// don't care whether the type itself is an l-value type or an r-value
3805/// type; we only care if the type was *written* as an l-value type
3806/// or an r-value type.
3807template<typename Derived>
3808QualType
3809TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003810 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00003811 const ReferenceType *T = TL.getTypePtr();
3812
3813 // Note that this works with the pointee-as-written.
3814 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3815 if (PointeeType.isNull())
3816 return QualType();
3817
3818 QualType Result = TL.getType();
3819 if (getDerived().AlwaysRebuild() ||
3820 PointeeType != T->getPointeeTypeAsWritten()) {
3821 Result = getDerived().RebuildReferenceType(PointeeType,
3822 T->isSpelledAsLValue(),
3823 TL.getSigilLoc());
3824 if (Result.isNull())
3825 return QualType();
3826 }
3827
John McCall31168b02011-06-15 23:02:42 +00003828 // Objective-C ARC can add lifetime qualifiers to the type that we're
3829 // referring to.
3830 TLB.TypeWasModifiedSafely(
3831 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3832
John McCall70dd5f62009-10-30 00:06:24 +00003833 // r-value references can be rebuilt as l-value references.
3834 ReferenceTypeLoc NewTL;
3835 if (isa<LValueReferenceType>(Result))
3836 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3837 else
3838 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3839 NewTL.setSigilLoc(TL.getSigilLoc());
3840
3841 return Result;
3842}
3843
Mike Stump11289f42009-09-09 15:08:12 +00003844template<typename Derived>
3845QualType
John McCall550e0c22009-10-21 00:40:46 +00003846TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003847 LValueReferenceTypeLoc TL) {
3848 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003849}
3850
Mike Stump11289f42009-09-09 15:08:12 +00003851template<typename Derived>
3852QualType
John McCall550e0c22009-10-21 00:40:46 +00003853TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003854 RValueReferenceTypeLoc TL) {
3855 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003856}
Mike Stump11289f42009-09-09 15:08:12 +00003857
Douglas Gregord6ff3322009-08-04 16:50:30 +00003858template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003859QualType
John McCall550e0c22009-10-21 00:40:46 +00003860TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003861 MemberPointerTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003862 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003863 if (PointeeType.isNull())
3864 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003865
Abramo Bagnara509357842011-03-05 14:42:21 +00003866 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
3867 TypeSourceInfo* NewClsTInfo = 0;
3868 if (OldClsTInfo) {
3869 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3870 if (!NewClsTInfo)
3871 return QualType();
3872 }
3873
3874 const MemberPointerType *T = TL.getTypePtr();
3875 QualType OldClsType = QualType(T->getClass(), 0);
3876 QualType NewClsType;
3877 if (NewClsTInfo)
3878 NewClsType = NewClsTInfo->getType();
3879 else {
3880 NewClsType = getDerived().TransformType(OldClsType);
3881 if (NewClsType.isNull())
3882 return QualType();
3883 }
Mike Stump11289f42009-09-09 15:08:12 +00003884
John McCall550e0c22009-10-21 00:40:46 +00003885 QualType Result = TL.getType();
3886 if (getDerived().AlwaysRebuild() ||
3887 PointeeType != T->getPointeeType() ||
Abramo Bagnara509357842011-03-05 14:42:21 +00003888 NewClsType != OldClsType) {
3889 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall70dd5f62009-10-30 00:06:24 +00003890 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00003891 if (Result.isNull())
3892 return QualType();
3893 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00003894
Reid Kleckner0503a872013-12-05 01:23:43 +00003895 // If we had to adjust the pointee type when building a member pointer, make
3896 // sure to push TypeLoc info for it.
3897 const MemberPointerType *MPT = Result->getAs<MemberPointerType>();
3898 if (MPT && PointeeType != MPT->getPointeeType()) {
3899 assert(isa<AdjustedType>(MPT->getPointeeType()));
3900 TLB.push<AdjustedTypeLoc>(MPT->getPointeeType());
3901 }
3902
John McCall550e0c22009-10-21 00:40:46 +00003903 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3904 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnara509357842011-03-05 14:42:21 +00003905 NewTL.setClassTInfo(NewClsTInfo);
John McCall550e0c22009-10-21 00:40:46 +00003906
3907 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003908}
3909
Mike Stump11289f42009-09-09 15:08:12 +00003910template<typename Derived>
3911QualType
John McCall550e0c22009-10-21 00:40:46 +00003912TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003913 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003914 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003915 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003916 if (ElementType.isNull())
3917 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003918
John McCall550e0c22009-10-21 00:40:46 +00003919 QualType Result = TL.getType();
3920 if (getDerived().AlwaysRebuild() ||
3921 ElementType != T->getElementType()) {
3922 Result = getDerived().RebuildConstantArrayType(ElementType,
3923 T->getSizeModifier(),
3924 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00003925 T->getIndexTypeCVRQualifiers(),
3926 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003927 if (Result.isNull())
3928 return QualType();
3929 }
Eli Friedmanf7f102f2012-01-25 22:19:07 +00003930
3931 // We might have either a ConstantArrayType or a VariableArrayType now:
3932 // a ConstantArrayType is allowed to have an element type which is a
3933 // VariableArrayType if the type is dependent. Fortunately, all array
3934 // types have the same location layout.
3935 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00003936 NewTL.setLBracketLoc(TL.getLBracketLoc());
3937 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00003938
John McCall550e0c22009-10-21 00:40:46 +00003939 Expr *Size = TL.getSizeExpr();
3940 if (Size) {
Richard Smith764d2fe2011-12-20 02:08:33 +00003941 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3942 Sema::ConstantEvaluated);
John McCall550e0c22009-10-21 00:40:46 +00003943 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
Eli Friedmanc6237c62012-02-29 03:16:56 +00003944 Size = SemaRef.ActOnConstantExpression(Size).take();
John McCall550e0c22009-10-21 00:40:46 +00003945 }
3946 NewTL.setSizeExpr(Size);
3947
3948 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003949}
Mike Stump11289f42009-09-09 15:08:12 +00003950
Douglas Gregord6ff3322009-08-04 16:50:30 +00003951template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003952QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00003953 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003954 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003955 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003956 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003957 if (ElementType.isNull())
3958 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003959
John McCall550e0c22009-10-21 00:40:46 +00003960 QualType Result = TL.getType();
3961 if (getDerived().AlwaysRebuild() ||
3962 ElementType != T->getElementType()) {
3963 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00003964 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00003965 T->getIndexTypeCVRQualifiers(),
3966 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003967 if (Result.isNull())
3968 return QualType();
3969 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003970
John McCall550e0c22009-10-21 00:40:46 +00003971 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3972 NewTL.setLBracketLoc(TL.getLBracketLoc());
3973 NewTL.setRBracketLoc(TL.getRBracketLoc());
3974 NewTL.setSizeExpr(0);
3975
3976 return Result;
3977}
3978
3979template<typename Derived>
3980QualType
3981TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003982 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003983 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003984 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3985 if (ElementType.isNull())
3986 return QualType();
3987
John McCalldadc5752010-08-24 06:29:42 +00003988 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00003989 = getDerived().TransformExpr(T->getSizeExpr());
3990 if (SizeResult.isInvalid())
3991 return QualType();
3992
John McCallb268a282010-08-23 23:25:46 +00003993 Expr *Size = SizeResult.take();
John McCall550e0c22009-10-21 00:40:46 +00003994
3995 QualType Result = TL.getType();
3996 if (getDerived().AlwaysRebuild() ||
3997 ElementType != T->getElementType() ||
3998 Size != T->getSizeExpr()) {
3999 Result = getDerived().RebuildVariableArrayType(ElementType,
4000 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00004001 Size,
John McCall550e0c22009-10-21 00:40:46 +00004002 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004003 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004004 if (Result.isNull())
4005 return QualType();
4006 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004007
Serge Pavlov774c6d02014-02-06 03:49:11 +00004008 // We might have constant size array now, but fortunately it has the same
4009 // location layout.
4010 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004011 NewTL.setLBracketLoc(TL.getLBracketLoc());
4012 NewTL.setRBracketLoc(TL.getRBracketLoc());
4013 NewTL.setSizeExpr(Size);
4014
4015 return Result;
4016}
4017
4018template<typename Derived>
4019QualType
4020TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004021 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004022 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004023 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4024 if (ElementType.isNull())
4025 return QualType();
4026
Richard Smith764d2fe2011-12-20 02:08:33 +00004027 // Array bounds are constant expressions.
4028 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4029 Sema::ConstantEvaluated);
John McCall550e0c22009-10-21 00:40:46 +00004030
John McCall33ddac02011-01-19 10:06:00 +00004031 // Prefer the expression from the TypeLoc; the other may have been uniqued.
4032 Expr *origSize = TL.getSizeExpr();
4033 if (!origSize) origSize = T->getSizeExpr();
4034
4035 ExprResult sizeResult
4036 = getDerived().TransformExpr(origSize);
Eli Friedmanc6237c62012-02-29 03:16:56 +00004037 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall33ddac02011-01-19 10:06:00 +00004038 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00004039 return QualType();
4040
John McCall33ddac02011-01-19 10:06:00 +00004041 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004042
4043 QualType Result = TL.getType();
4044 if (getDerived().AlwaysRebuild() ||
4045 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00004046 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00004047 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
4048 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00004049 size,
John McCall550e0c22009-10-21 00:40:46 +00004050 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004051 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004052 if (Result.isNull())
4053 return QualType();
4054 }
John McCall550e0c22009-10-21 00:40:46 +00004055
4056 // We might have any sort of array type now, but fortunately they
4057 // all have the same location layout.
4058 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4059 NewTL.setLBracketLoc(TL.getLBracketLoc());
4060 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00004061 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00004062
4063 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004064}
Mike Stump11289f42009-09-09 15:08:12 +00004065
4066template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004067QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00004068 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004069 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004070 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004071
4072 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00004073 QualType ElementType = getDerived().TransformType(T->getElementType());
4074 if (ElementType.isNull())
4075 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004076
Richard Smith764d2fe2011-12-20 02:08:33 +00004077 // Vector sizes are constant expressions.
4078 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4079 Sema::ConstantEvaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00004080
John McCalldadc5752010-08-24 06:29:42 +00004081 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanc6237c62012-02-29 03:16:56 +00004082 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004083 if (Size.isInvalid())
4084 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004085
John McCall550e0c22009-10-21 00:40:46 +00004086 QualType Result = TL.getType();
4087 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00004088 ElementType != T->getElementType() ||
4089 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00004090 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCallb268a282010-08-23 23:25:46 +00004091 Size.take(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00004092 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00004093 if (Result.isNull())
4094 return QualType();
4095 }
John McCall550e0c22009-10-21 00:40:46 +00004096
4097 // Result might be dependent or not.
4098 if (isa<DependentSizedExtVectorType>(Result)) {
4099 DependentSizedExtVectorTypeLoc NewTL
4100 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
4101 NewTL.setNameLoc(TL.getNameLoc());
4102 } else {
4103 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4104 NewTL.setNameLoc(TL.getNameLoc());
4105 }
4106
4107 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004108}
Mike Stump11289f42009-09-09 15:08:12 +00004109
4110template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004111QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004112 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004113 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004114 QualType ElementType = getDerived().TransformType(T->getElementType());
4115 if (ElementType.isNull())
4116 return QualType();
4117
John McCall550e0c22009-10-21 00:40:46 +00004118 QualType Result = TL.getType();
4119 if (getDerived().AlwaysRebuild() ||
4120 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00004121 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00004122 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00004123 if (Result.isNull())
4124 return QualType();
4125 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004126
John McCall550e0c22009-10-21 00:40:46 +00004127 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
4128 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004129
John McCall550e0c22009-10-21 00:40:46 +00004130 return Result;
4131}
4132
4133template<typename Derived>
4134QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004135 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004136 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004137 QualType ElementType = getDerived().TransformType(T->getElementType());
4138 if (ElementType.isNull())
4139 return QualType();
4140
4141 QualType Result = TL.getType();
4142 if (getDerived().AlwaysRebuild() ||
4143 ElementType != T->getElementType()) {
4144 Result = getDerived().RebuildExtVectorType(ElementType,
4145 T->getNumElements(),
4146 /*FIXME*/ SourceLocation());
4147 if (Result.isNull())
4148 return QualType();
4149 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004150
John McCall550e0c22009-10-21 00:40:46 +00004151 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4152 NewTL.setNameLoc(TL.getNameLoc());
4153
4154 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004155}
Mike Stump11289f42009-09-09 15:08:12 +00004156
David Blaikie05785d12013-02-20 22:23:23 +00004157template <typename Derived>
4158ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
4159 ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
4160 bool ExpectParameterPack) {
John McCall58f10c32010-03-11 09:03:00 +00004161 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor715e4612011-01-14 22:40:04 +00004162 TypeSourceInfo *NewDI = 0;
Chad Rosier1dcde962012-08-08 18:46:20 +00004163
Douglas Gregor715e4612011-01-14 22:40:04 +00004164 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004165 // If we're substituting into a pack expansion type and we know the
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004166 // length we want to expand to, just substitute for the pattern.
Douglas Gregor715e4612011-01-14 22:40:04 +00004167 TypeLoc OldTL = OldDI->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004168 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004169
Douglas Gregor715e4612011-01-14 22:40:04 +00004170 TypeLocBuilder TLB;
4171 TypeLoc NewTL = OldDI->getTypeLoc();
4172 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00004173
4174 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor715e4612011-01-14 22:40:04 +00004175 OldExpansionTL.getPatternLoc());
4176 if (Result.isNull())
4177 return 0;
Chad Rosier1dcde962012-08-08 18:46:20 +00004178
4179 Result = RebuildPackExpansionType(Result,
4180 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor715e4612011-01-14 22:40:04 +00004181 OldExpansionTL.getEllipsisLoc(),
4182 NumExpansions);
4183 if (Result.isNull())
4184 return 0;
Chad Rosier1dcde962012-08-08 18:46:20 +00004185
Douglas Gregor715e4612011-01-14 22:40:04 +00004186 PackExpansionTypeLoc NewExpansionTL
4187 = TLB.push<PackExpansionTypeLoc>(Result);
4188 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
4189 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
4190 } else
4191 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00004192 if (!NewDI)
4193 return 0;
4194
John McCall8fb0d9d2011-05-01 22:35:37 +00004195 if (NewDI == OldDI && indexAdjustment == 0)
John McCall58f10c32010-03-11 09:03:00 +00004196 return OldParm;
John McCall8fb0d9d2011-05-01 22:35:37 +00004197
4198 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
4199 OldParm->getDeclContext(),
4200 OldParm->getInnerLocStart(),
4201 OldParm->getLocation(),
4202 OldParm->getIdentifier(),
4203 NewDI->getType(),
4204 NewDI,
4205 OldParm->getStorageClass(),
John McCall8fb0d9d2011-05-01 22:35:37 +00004206 /* DefArg */ NULL);
4207 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
4208 OldParm->getFunctionScopeIndex() + indexAdjustment);
4209 return newParm;
John McCall58f10c32010-03-11 09:03:00 +00004210}
4211
4212template<typename Derived>
4213bool TreeTransform<Derived>::
Douglas Gregordd472162011-01-07 00:20:55 +00004214 TransformFunctionTypeParams(SourceLocation Loc,
4215 ParmVarDecl **Params, unsigned NumParams,
4216 const QualType *ParamTypes,
Chris Lattner01cf8db2011-07-20 06:58:45 +00004217 SmallVectorImpl<QualType> &OutParamTypes,
4218 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004219 int indexAdjustment = 0;
4220
Douglas Gregordd472162011-01-07 00:20:55 +00004221 for (unsigned i = 0; i != NumParams; ++i) {
4222 if (ParmVarDecl *OldParm = Params[i]) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004223 assert(OldParm->getFunctionScopeIndex() == i);
4224
David Blaikie05785d12013-02-20 22:23:23 +00004225 Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004226 ParmVarDecl *NewParm = 0;
Douglas Gregor5499af42011-01-05 23:12:31 +00004227 if (OldParm->isParameterPack()) {
4228 // We have a function parameter pack that may need to be expanded.
Chris Lattner01cf8db2011-07-20 06:58:45 +00004229 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00004230
Douglas Gregor5499af42011-01-05 23:12:31 +00004231 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004232 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004233 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004234 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4235 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004236 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4237
Douglas Gregor5499af42011-01-05 23:12:31 +00004238 // Determine whether we should expand the parameter packs.
4239 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004240 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004241 Optional<unsigned> OrigNumExpansions =
4242 ExpansionTL.getTypePtr()->getNumExpansions();
Douglas Gregor715e4612011-01-14 22:40:04 +00004243 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004244 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4245 Pattern.getSourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004246 Unexpanded,
4247 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004248 RetainExpansion,
4249 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004250 return true;
4251 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004252
Douglas Gregor5499af42011-01-05 23:12:31 +00004253 if (ShouldExpand) {
4254 // Expand the function parameter pack into multiple, separate
4255 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00004256 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004257 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004258 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier1dcde962012-08-08 18:46:20 +00004259 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004260 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004261 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004262 OrigNumExpansions,
4263 /*ExpectParameterPack=*/false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004264 if (!NewParm)
4265 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004266
Douglas Gregordd472162011-01-07 00:20:55 +00004267 OutParamTypes.push_back(NewParm->getType());
4268 if (PVars)
4269 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004270 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004271
4272 // If we're supposed to retain a pack expansion, do so by temporarily
4273 // forgetting the partially-substituted parameter pack.
4274 if (RetainExpansion) {
4275 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00004276 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004277 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004278 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004279 OrigNumExpansions,
4280 /*ExpectParameterPack=*/false);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004281 if (!NewParm)
4282 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004283
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004284 OutParamTypes.push_back(NewParm->getType());
4285 if (PVars)
4286 PVars->push_back(NewParm);
4287 }
4288
John McCall8fb0d9d2011-05-01 22:35:37 +00004289 // The next parameter should have the same adjustment as the
4290 // last thing we pushed, but we post-incremented indexAdjustment
4291 // on every push. Also, if we push nothing, the adjustment should
4292 // go down by one.
4293 indexAdjustment--;
4294
Douglas Gregor5499af42011-01-05 23:12:31 +00004295 // We're done with the pack expansion.
4296 continue;
4297 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004298
4299 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004300 // expansion.
Douglas Gregorc52264e2011-03-02 02:04:06 +00004301 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4302 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004303 indexAdjustment,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004304 NumExpansions,
4305 /*ExpectParameterPack=*/true);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004306 } else {
David Blaikie05785d12013-02-20 22:23:23 +00004307 NewParm = getDerived().TransformFunctionTypeParam(
David Blaikie7a30dc52013-02-21 01:47:18 +00004308 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004309 }
Douglas Gregorc52264e2011-03-02 02:04:06 +00004310
John McCall58f10c32010-03-11 09:03:00 +00004311 if (!NewParm)
4312 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004313
Douglas Gregordd472162011-01-07 00:20:55 +00004314 OutParamTypes.push_back(NewParm->getType());
4315 if (PVars)
4316 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004317 continue;
4318 }
John McCall58f10c32010-03-11 09:03:00 +00004319
4320 // Deal with the possibility that we don't have a parameter
4321 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00004322 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00004323 bool IsPackExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004324 Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004325 QualType NewType;
Chad Rosier1dcde962012-08-08 18:46:20 +00004326 if (const PackExpansionType *Expansion
Douglas Gregor5499af42011-01-05 23:12:31 +00004327 = dyn_cast<PackExpansionType>(OldType)) {
4328 // We have a function parameter pack that may need to be expanded.
4329 QualType Pattern = Expansion->getPattern();
Chris Lattner01cf8db2011-07-20 06:58:45 +00004330 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor5499af42011-01-05 23:12:31 +00004331 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00004332
Douglas Gregor5499af42011-01-05 23:12:31 +00004333 // Determine whether we should expand the parameter packs.
4334 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004335 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00004336 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004337 Unexpanded,
4338 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004339 RetainExpansion,
4340 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00004341 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00004342 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004343
Douglas Gregor5499af42011-01-05 23:12:31 +00004344 if (ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004345 // Expand the function parameter pack into multiple, separate
Douglas Gregor5499af42011-01-05 23:12:31 +00004346 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004347 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004348 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4349 QualType NewType = getDerived().TransformType(Pattern);
4350 if (NewType.isNull())
4351 return true;
John McCall58f10c32010-03-11 09:03:00 +00004352
Douglas Gregordd472162011-01-07 00:20:55 +00004353 OutParamTypes.push_back(NewType);
4354 if (PVars)
4355 PVars->push_back(0);
Douglas Gregor5499af42011-01-05 23:12:31 +00004356 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004357
Douglas Gregor5499af42011-01-05 23:12:31 +00004358 // We're done with the pack expansion.
4359 continue;
4360 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004361
Douglas Gregor48d24112011-01-10 20:53:55 +00004362 // If we're supposed to retain a pack expansion, do so by temporarily
4363 // forgetting the partially-substituted parameter pack.
4364 if (RetainExpansion) {
4365 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4366 QualType NewType = getDerived().TransformType(Pattern);
4367 if (NewType.isNull())
4368 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004369
Douglas Gregor48d24112011-01-10 20:53:55 +00004370 OutParamTypes.push_back(NewType);
4371 if (PVars)
4372 PVars->push_back(0);
4373 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004374
Chad Rosier1dcde962012-08-08 18:46:20 +00004375 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004376 // expansion.
4377 OldType = Expansion->getPattern();
4378 IsPackExpansion = true;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004379 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4380 NewType = getDerived().TransformType(OldType);
4381 } else {
4382 NewType = getDerived().TransformType(OldType);
Douglas Gregor5499af42011-01-05 23:12:31 +00004383 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004384
Douglas Gregor5499af42011-01-05 23:12:31 +00004385 if (NewType.isNull())
4386 return true;
4387
4388 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004389 NewType = getSema().Context.getPackExpansionType(NewType,
4390 NumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00004391
Douglas Gregordd472162011-01-07 00:20:55 +00004392 OutParamTypes.push_back(NewType);
4393 if (PVars)
4394 PVars->push_back(0);
John McCall58f10c32010-03-11 09:03:00 +00004395 }
4396
John McCall8fb0d9d2011-05-01 22:35:37 +00004397#ifndef NDEBUG
4398 if (PVars) {
4399 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4400 if (ParmVarDecl *parm = (*PVars)[i])
4401 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor5499af42011-01-05 23:12:31 +00004402 }
John McCall8fb0d9d2011-05-01 22:35:37 +00004403#endif
4404
4405 return false;
4406}
John McCall58f10c32010-03-11 09:03:00 +00004407
4408template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004409QualType
John McCall550e0c22009-10-21 00:40:46 +00004410TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004411 FunctionProtoTypeLoc TL) {
Douglas Gregor3024f072012-04-16 07:05:22 +00004412 return getDerived().TransformFunctionProtoType(TLB, TL, 0, 0);
4413}
4414
4415template<typename Derived>
4416QualType
4417TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
4418 FunctionProtoTypeLoc TL,
4419 CXXRecordDecl *ThisContext,
4420 unsigned ThisTypeQuals) {
Douglas Gregor4afc2362010-08-31 00:26:14 +00004421 // Transform the parameters and return type.
4422 //
Richard Smithf623c962012-04-17 00:58:00 +00004423 // We are required to instantiate the params and return type in source order.
Douglas Gregor7fb25412010-10-01 18:44:50 +00004424 // When the function has a trailing return type, we instantiate the
4425 // parameters before the return type, since the return type can then refer
4426 // to the parameters themselves (via decltype, sizeof, etc.).
4427 //
Chris Lattner01cf8db2011-07-20 06:58:45 +00004428 SmallVector<QualType, 4> ParamTypes;
4429 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall424cec92011-01-19 06:33:43 +00004430 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00004431
Douglas Gregor7fb25412010-10-01 18:44:50 +00004432 QualType ResultType;
4433
Richard Smith1226c602012-08-14 22:51:13 +00004434 if (T->hasTrailingReturn()) {
Alp Toker9cacbab2014-01-20 20:26:09 +00004435 if (getDerived().TransformFunctionTypeParams(
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004436 TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(),
Alp Toker9cacbab2014-01-20 20:26:09 +00004437 TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004438 return QualType();
4439
Douglas Gregor3024f072012-04-16 07:05:22 +00004440 {
4441 // C++11 [expr.prim.general]p3:
Chad Rosier1dcde962012-08-08 18:46:20 +00004442 // If a declaration declares a member function or member function
4443 // template of a class X, the expression this is a prvalue of type
Douglas Gregor3024f072012-04-16 07:05:22 +00004444 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier1dcde962012-08-08 18:46:20 +00004445 // and the end of the function-definition, member-declarator, or
Douglas Gregor3024f072012-04-16 07:05:22 +00004446 // declarator.
4447 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier1dcde962012-08-08 18:46:20 +00004448
Alp Toker42a16a62014-01-25 23:51:36 +00004449 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor3024f072012-04-16 07:05:22 +00004450 if (ResultType.isNull())
4451 return QualType();
4452 }
Douglas Gregor7fb25412010-10-01 18:44:50 +00004453 }
4454 else {
Alp Toker42a16a62014-01-25 23:51:36 +00004455 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00004456 if (ResultType.isNull())
4457 return QualType();
4458
Alp Toker9cacbab2014-01-20 20:26:09 +00004459 if (getDerived().TransformFunctionTypeParams(
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004460 TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(),
Alp Toker9cacbab2014-01-20 20:26:09 +00004461 TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004462 return QualType();
4463 }
4464
Richard Smithf623c962012-04-17 00:58:00 +00004465 // FIXME: Need to transform the exception-specification too.
4466
John McCall550e0c22009-10-21 00:40:46 +00004467 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00004468 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() ||
Alp Toker9cacbab2014-01-20 20:26:09 +00004469 T->getNumParams() != ParamTypes.size() ||
4470 !std::equal(T->param_type_begin(), T->param_type_end(),
4471 ParamTypes.begin())) {
Jordan Rose5c382722013-03-08 21:51:21 +00004472 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +00004473 T->getExtProtoInfo());
John McCall550e0c22009-10-21 00:40:46 +00004474 if (Result.isNull())
4475 return QualType();
4476 }
Mike Stump11289f42009-09-09 15:08:12 +00004477
John McCall550e0c22009-10-21 00:40:46 +00004478 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004479 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00004480 NewTL.setLParenLoc(TL.getLParenLoc());
4481 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004482 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004483 for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i)
4484 NewTL.setParam(i, ParamDecls[i]);
John McCall550e0c22009-10-21 00:40:46 +00004485
4486 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004487}
Mike Stump11289f42009-09-09 15:08:12 +00004488
Douglas Gregord6ff3322009-08-04 16:50:30 +00004489template<typename Derived>
4490QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00004491 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004492 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004493 const FunctionNoProtoType *T = TL.getTypePtr();
Alp Toker42a16a62014-01-25 23:51:36 +00004494 QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
John McCall550e0c22009-10-21 00:40:46 +00004495 if (ResultType.isNull())
4496 return QualType();
4497
4498 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00004499 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType())
John McCall550e0c22009-10-21 00:40:46 +00004500 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4501
4502 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004503 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00004504 NewTL.setLParenLoc(TL.getLParenLoc());
4505 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004506 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCall550e0c22009-10-21 00:40:46 +00004507
4508 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004509}
Mike Stump11289f42009-09-09 15:08:12 +00004510
John McCallb96ec562009-12-04 22:46:56 +00004511template<typename Derived> QualType
4512TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004513 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004514 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004515 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00004516 if (!D)
4517 return QualType();
4518
4519 QualType Result = TL.getType();
4520 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4521 Result = getDerived().RebuildUnresolvedUsingType(D);
4522 if (Result.isNull())
4523 return QualType();
4524 }
4525
4526 // We might get an arbitrary type spec type back. We should at
4527 // least always get a type spec type, though.
4528 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4529 NewTL.setNameLoc(TL.getNameLoc());
4530
4531 return Result;
4532}
4533
Douglas Gregord6ff3322009-08-04 16:50:30 +00004534template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004535QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004536 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004537 const TypedefType *T = TL.getTypePtr();
Richard Smithdda56e42011-04-15 14:24:37 +00004538 TypedefNameDecl *Typedef
4539 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4540 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004541 if (!Typedef)
4542 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004543
John McCall550e0c22009-10-21 00:40:46 +00004544 QualType Result = TL.getType();
4545 if (getDerived().AlwaysRebuild() ||
4546 Typedef != T->getDecl()) {
4547 Result = getDerived().RebuildTypedefType(Typedef);
4548 if (Result.isNull())
4549 return QualType();
4550 }
Mike Stump11289f42009-09-09 15:08:12 +00004551
John McCall550e0c22009-10-21 00:40:46 +00004552 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4553 NewTL.setNameLoc(TL.getNameLoc());
4554
4555 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004556}
Mike Stump11289f42009-09-09 15:08:12 +00004557
Douglas Gregord6ff3322009-08-04 16:50:30 +00004558template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004559QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004560 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00004561 // typeof expressions are not potentially evaluated contexts
Eli Friedman15681d62012-09-26 04:34:21 +00004562 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4563 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00004564
John McCalldadc5752010-08-24 06:29:42 +00004565 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004566 if (E.isInvalid())
4567 return QualType();
4568
Eli Friedmane4f22df2012-02-29 04:03:55 +00004569 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
4570 if (E.isInvalid())
4571 return QualType();
4572
John McCall550e0c22009-10-21 00:40:46 +00004573 QualType Result = TL.getType();
4574 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00004575 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004576 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00004577 if (Result.isNull())
4578 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004579 }
John McCall550e0c22009-10-21 00:40:46 +00004580 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00004581
John McCall550e0c22009-10-21 00:40:46 +00004582 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004583 NewTL.setTypeofLoc(TL.getTypeofLoc());
4584 NewTL.setLParenLoc(TL.getLParenLoc());
4585 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00004586
4587 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004588}
Mike Stump11289f42009-09-09 15:08:12 +00004589
4590template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004591QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004592 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00004593 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4594 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4595 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00004596 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004597
John McCall550e0c22009-10-21 00:40:46 +00004598 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00004599 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4600 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00004601 if (Result.isNull())
4602 return QualType();
4603 }
Mike Stump11289f42009-09-09 15:08:12 +00004604
John McCall550e0c22009-10-21 00:40:46 +00004605 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004606 NewTL.setTypeofLoc(TL.getTypeofLoc());
4607 NewTL.setLParenLoc(TL.getLParenLoc());
4608 NewTL.setRParenLoc(TL.getRParenLoc());
4609 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00004610
4611 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004612}
Mike Stump11289f42009-09-09 15:08:12 +00004613
4614template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004615QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004616 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004617 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004618
Douglas Gregore922c772009-08-04 22:27:00 +00004619 // decltype expressions are not potentially evaluated contexts
Richard Smithfd555f62012-02-22 02:04:18 +00004620 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, 0,
4621 /*IsDecltype=*/ true);
Mike Stump11289f42009-09-09 15:08:12 +00004622
John McCalldadc5752010-08-24 06:29:42 +00004623 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004624 if (E.isInvalid())
4625 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004626
Richard Smithfd555f62012-02-22 02:04:18 +00004627 E = getSema().ActOnDecltypeExpression(E.take());
4628 if (E.isInvalid())
4629 return QualType();
4630
John McCall550e0c22009-10-21 00:40:46 +00004631 QualType Result = TL.getType();
4632 if (getDerived().AlwaysRebuild() ||
4633 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004634 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004635 if (Result.isNull())
4636 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004637 }
John McCall550e0c22009-10-21 00:40:46 +00004638 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00004639
John McCall550e0c22009-10-21 00:40:46 +00004640 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4641 NewTL.setNameLoc(TL.getNameLoc());
4642
4643 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004644}
4645
4646template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00004647QualType TreeTransform<Derived>::TransformUnaryTransformType(
4648 TypeLocBuilder &TLB,
4649 UnaryTransformTypeLoc TL) {
4650 QualType Result = TL.getType();
4651 if (Result->isDependentType()) {
4652 const UnaryTransformType *T = TL.getTypePtr();
4653 QualType NewBase =
4654 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4655 Result = getDerived().RebuildUnaryTransformType(NewBase,
4656 T->getUTTKind(),
4657 TL.getKWLoc());
4658 if (Result.isNull())
4659 return QualType();
4660 }
4661
4662 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4663 NewTL.setKWLoc(TL.getKWLoc());
4664 NewTL.setParensRange(TL.getParensRange());
4665 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4666 return Result;
4667}
4668
4669template<typename Derived>
Richard Smith30482bc2011-02-20 03:19:35 +00004670QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4671 AutoTypeLoc TL) {
4672 const AutoType *T = TL.getTypePtr();
4673 QualType OldDeduced = T->getDeducedType();
4674 QualType NewDeduced;
4675 if (!OldDeduced.isNull()) {
4676 NewDeduced = getDerived().TransformType(OldDeduced);
4677 if (NewDeduced.isNull())
4678 return QualType();
4679 }
4680
4681 QualType Result = TL.getType();
Richard Smith27d807c2013-04-30 13:56:41 +00004682 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
4683 T->isDependentType()) {
Richard Smith74aeef52013-04-26 16:15:35 +00004684 Result = getDerived().RebuildAutoType(NewDeduced, T->isDecltypeAuto());
Richard Smith30482bc2011-02-20 03:19:35 +00004685 if (Result.isNull())
4686 return QualType();
4687 }
4688
4689 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4690 NewTL.setNameLoc(TL.getNameLoc());
4691
4692 return Result;
4693}
4694
4695template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004696QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004697 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004698 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004699 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004700 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4701 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004702 if (!Record)
4703 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004704
John McCall550e0c22009-10-21 00:40:46 +00004705 QualType Result = TL.getType();
4706 if (getDerived().AlwaysRebuild() ||
4707 Record != T->getDecl()) {
4708 Result = getDerived().RebuildRecordType(Record);
4709 if (Result.isNull())
4710 return QualType();
4711 }
Mike Stump11289f42009-09-09 15:08:12 +00004712
John McCall550e0c22009-10-21 00:40:46 +00004713 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4714 NewTL.setNameLoc(TL.getNameLoc());
4715
4716 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004717}
Mike Stump11289f42009-09-09 15:08:12 +00004718
4719template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004720QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004721 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004722 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004723 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004724 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4725 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004726 if (!Enum)
4727 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004728
John McCall550e0c22009-10-21 00:40:46 +00004729 QualType Result = TL.getType();
4730 if (getDerived().AlwaysRebuild() ||
4731 Enum != T->getDecl()) {
4732 Result = getDerived().RebuildEnumType(Enum);
4733 if (Result.isNull())
4734 return QualType();
4735 }
Mike Stump11289f42009-09-09 15:08:12 +00004736
John McCall550e0c22009-10-21 00:40:46 +00004737 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4738 NewTL.setNameLoc(TL.getNameLoc());
4739
4740 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004741}
John McCallfcc33b02009-09-05 00:15:47 +00004742
John McCalle78aac42010-03-10 03:28:59 +00004743template<typename Derived>
4744QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4745 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004746 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00004747 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4748 TL.getTypePtr()->getDecl());
4749 if (!D) return QualType();
4750
4751 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4752 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4753 return T;
4754}
4755
Douglas Gregord6ff3322009-08-04 16:50:30 +00004756template<typename Derived>
4757QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004758 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004759 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004760 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004761}
4762
Mike Stump11289f42009-09-09 15:08:12 +00004763template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00004764QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004765 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004766 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004767 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00004768
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004769 // Substitute into the replacement type, which itself might involve something
4770 // that needs to be transformed. This only tends to occur with default
4771 // template arguments of template template parameters.
4772 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4773 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4774 if (Replacement.isNull())
4775 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00004776
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004777 // Always canonicalize the replacement type.
4778 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4779 QualType Result
Chad Rosier1dcde962012-08-08 18:46:20 +00004780 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004781 Replacement);
Chad Rosier1dcde962012-08-08 18:46:20 +00004782
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004783 // Propagate type-source information.
4784 SubstTemplateTypeParmTypeLoc NewTL
4785 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4786 NewTL.setNameLoc(TL.getNameLoc());
4787 return Result;
4788
John McCallcebee162009-10-18 09:09:24 +00004789}
4790
4791template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00004792QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4793 TypeLocBuilder &TLB,
4794 SubstTemplateTypeParmPackTypeLoc TL) {
4795 return TransformTypeSpecType(TLB, TL);
4796}
4797
4798template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00004799QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00004800 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004801 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00004802 const TemplateSpecializationType *T = TL.getTypePtr();
4803
Douglas Gregordf846d12011-03-02 18:46:51 +00004804 // The nested-name-specifier never matters in a TemplateSpecializationType,
4805 // because we can't have a dependent nested-name-specifier anyway.
4806 CXXScopeSpec SS;
Mike Stump11289f42009-09-09 15:08:12 +00004807 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00004808 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4809 TL.getTemplateNameLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004810 if (Template.isNull())
4811 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004812
John McCall31f82722010-11-12 08:19:04 +00004813 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4814}
4815
Eli Friedman0dfb8892011-10-06 23:00:33 +00004816template<typename Derived>
4817QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
4818 AtomicTypeLoc TL) {
4819 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
4820 if (ValueType.isNull())
4821 return QualType();
4822
4823 QualType Result = TL.getType();
4824 if (getDerived().AlwaysRebuild() ||
4825 ValueType != TL.getValueLoc().getType()) {
4826 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
4827 if (Result.isNull())
4828 return QualType();
4829 }
4830
4831 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
4832 NewTL.setKWLoc(TL.getKWLoc());
4833 NewTL.setLParenLoc(TL.getLParenLoc());
4834 NewTL.setRParenLoc(TL.getRParenLoc());
4835
4836 return Result;
4837}
4838
Chad Rosier1dcde962012-08-08 18:46:20 +00004839 /// \brief Simple iterator that traverses the template arguments in a
Douglas Gregorfe921a72010-12-20 23:36:19 +00004840 /// container that provides a \c getArgLoc() member function.
4841 ///
4842 /// This iterator is intended to be used with the iterator form of
4843 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4844 template<typename ArgLocContainer>
4845 class TemplateArgumentLocContainerIterator {
4846 ArgLocContainer *Container;
4847 unsigned Index;
Chad Rosier1dcde962012-08-08 18:46:20 +00004848
Douglas Gregorfe921a72010-12-20 23:36:19 +00004849 public:
4850 typedef TemplateArgumentLoc value_type;
4851 typedef TemplateArgumentLoc reference;
4852 typedef int difference_type;
4853 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00004854
Douglas Gregorfe921a72010-12-20 23:36:19 +00004855 class pointer {
4856 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00004857
Douglas Gregorfe921a72010-12-20 23:36:19 +00004858 public:
4859 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00004860
Douglas Gregorfe921a72010-12-20 23:36:19 +00004861 const TemplateArgumentLoc *operator->() const {
4862 return &Arg;
4863 }
4864 };
Chad Rosier1dcde962012-08-08 18:46:20 +00004865
4866
Douglas Gregorfe921a72010-12-20 23:36:19 +00004867 TemplateArgumentLocContainerIterator() {}
Chad Rosier1dcde962012-08-08 18:46:20 +00004868
Douglas Gregorfe921a72010-12-20 23:36:19 +00004869 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4870 unsigned Index)
4871 : Container(&Container), Index(Index) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00004872
Douglas Gregorfe921a72010-12-20 23:36:19 +00004873 TemplateArgumentLocContainerIterator &operator++() {
4874 ++Index;
4875 return *this;
4876 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004877
Douglas Gregorfe921a72010-12-20 23:36:19 +00004878 TemplateArgumentLocContainerIterator operator++(int) {
4879 TemplateArgumentLocContainerIterator Old(*this);
4880 ++(*this);
4881 return Old;
4882 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004883
Douglas Gregorfe921a72010-12-20 23:36:19 +00004884 TemplateArgumentLoc operator*() const {
4885 return Container->getArgLoc(Index);
4886 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004887
Douglas Gregorfe921a72010-12-20 23:36:19 +00004888 pointer operator->() const {
4889 return pointer(Container->getArgLoc(Index));
4890 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004891
Douglas Gregorfe921a72010-12-20 23:36:19 +00004892 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004893 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004894 return X.Container == Y.Container && X.Index == Y.Index;
4895 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004896
Douglas Gregorfe921a72010-12-20 23:36:19 +00004897 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004898 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004899 return !(X == Y);
4900 }
4901 };
Chad Rosier1dcde962012-08-08 18:46:20 +00004902
4903
John McCall31f82722010-11-12 08:19:04 +00004904template <typename Derived>
4905QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4906 TypeLocBuilder &TLB,
4907 TemplateSpecializationTypeLoc TL,
4908 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00004909 TemplateArgumentListInfo NewTemplateArgs;
4910 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4911 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00004912 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4913 ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00004914 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregorfe921a72010-12-20 23:36:19 +00004915 ArgIterator(TL, TL.getNumArgs()),
4916 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00004917 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004918
John McCall0ad16662009-10-29 08:12:44 +00004919 // FIXME: maybe don't rebuild if all the template arguments are the same.
4920
4921 QualType Result =
4922 getDerived().RebuildTemplateSpecializationType(Template,
4923 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00004924 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00004925
4926 if (!Result.isNull()) {
Richard Smith3f1b5d02011-05-05 21:57:07 +00004927 // Specializations of template template parameters are represented as
4928 // TemplateSpecializationTypes, and substitution of type alias templates
4929 // within a dependent context can transform them into
4930 // DependentTemplateSpecializationTypes.
4931 if (isa<DependentTemplateSpecializationType>(Result)) {
4932 DependentTemplateSpecializationTypeLoc NewTL
4933 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004934 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3f1b5d02011-05-05 21:57:07 +00004935 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00004936 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004937 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3f1b5d02011-05-05 21:57:07 +00004938 NewTL.setLAngleLoc(TL.getLAngleLoc());
4939 NewTL.setRAngleLoc(TL.getRAngleLoc());
4940 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4941 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4942 return Result;
4943 }
4944
John McCall0ad16662009-10-29 08:12:44 +00004945 TemplateSpecializationTypeLoc NewTL
4946 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004947 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall0ad16662009-10-29 08:12:44 +00004948 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4949 NewTL.setLAngleLoc(TL.getLAngleLoc());
4950 NewTL.setRAngleLoc(TL.getRAngleLoc());
4951 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4952 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004953 }
Mike Stump11289f42009-09-09 15:08:12 +00004954
John McCall0ad16662009-10-29 08:12:44 +00004955 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004956}
Mike Stump11289f42009-09-09 15:08:12 +00004957
Douglas Gregor5a064722011-02-28 17:23:35 +00004958template <typename Derived>
4959QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4960 TypeLocBuilder &TLB,
4961 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +00004962 TemplateName Template,
4963 CXXScopeSpec &SS) {
Douglas Gregor5a064722011-02-28 17:23:35 +00004964 TemplateArgumentListInfo NewTemplateArgs;
4965 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4966 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4967 typedef TemplateArgumentLocContainerIterator<
4968 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00004969 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor5a064722011-02-28 17:23:35 +00004970 ArgIterator(TL, TL.getNumArgs()),
4971 NewTemplateArgs))
4972 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00004973
Douglas Gregor5a064722011-02-28 17:23:35 +00004974 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier1dcde962012-08-08 18:46:20 +00004975
Douglas Gregor5a064722011-02-28 17:23:35 +00004976 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4977 QualType Result
4978 = getSema().Context.getDependentTemplateSpecializationType(
4979 TL.getTypePtr()->getKeyword(),
4980 DTN->getQualifier(),
4981 DTN->getIdentifier(),
4982 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00004983
Douglas Gregor5a064722011-02-28 17:23:35 +00004984 DependentTemplateSpecializationTypeLoc NewTL
4985 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004986 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004987 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00004988 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004989 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00004990 NewTL.setLAngleLoc(TL.getLAngleLoc());
4991 NewTL.setRAngleLoc(TL.getRAngleLoc());
4992 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4993 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4994 return Result;
4995 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004996
4997 QualType Result
Douglas Gregor5a064722011-02-28 17:23:35 +00004998 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004999 TL.getTemplateNameLoc(),
Douglas Gregor5a064722011-02-28 17:23:35 +00005000 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00005001
Douglas Gregor5a064722011-02-28 17:23:35 +00005002 if (!Result.isNull()) {
5003 /// FIXME: Wrap this in an elaborated-type-specifier?
5004 TemplateSpecializationTypeLoc NewTL
5005 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005006 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005007 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00005008 NewTL.setLAngleLoc(TL.getLAngleLoc());
5009 NewTL.setRAngleLoc(TL.getRAngleLoc());
5010 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5011 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5012 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005013
Douglas Gregor5a064722011-02-28 17:23:35 +00005014 return Result;
5015}
5016
Mike Stump11289f42009-09-09 15:08:12 +00005017template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005018QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00005019TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005020 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005021 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00005022
Douglas Gregor844cb502011-03-01 18:12:44 +00005023 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara6150c882010-05-11 21:36:43 +00005024 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor844cb502011-03-01 18:12:44 +00005025 if (TL.getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005026 QualifierLoc
Douglas Gregor844cb502011-03-01 18:12:44 +00005027 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5028 if (!QualifierLoc)
Abramo Bagnara6150c882010-05-11 21:36:43 +00005029 return QualType();
5030 }
Mike Stump11289f42009-09-09 15:08:12 +00005031
John McCall31f82722010-11-12 08:19:04 +00005032 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
5033 if (NamedT.isNull())
5034 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00005035
Richard Smith3f1b5d02011-05-05 21:57:07 +00005036 // C++0x [dcl.type.elab]p2:
5037 // If the identifier resolves to a typedef-name or the simple-template-id
5038 // resolves to an alias template specialization, the
5039 // elaborated-type-specifier is ill-formed.
Richard Smith0c4a34b2011-05-14 15:04:18 +00005040 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
5041 if (const TemplateSpecializationType *TST =
5042 NamedT->getAs<TemplateSpecializationType>()) {
5043 TemplateName Template = TST->getTemplateName();
5044 if (TypeAliasTemplateDecl *TAT =
5045 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
5046 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
5047 diag::err_tag_reference_non_tag) << 4;
5048 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
5049 }
Richard Smith3f1b5d02011-05-05 21:57:07 +00005050 }
5051 }
5052
John McCall550e0c22009-10-21 00:40:46 +00005053 QualType Result = TL.getType();
5054 if (getDerived().AlwaysRebuild() ||
Douglas Gregor844cb502011-03-01 18:12:44 +00005055 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00005056 NamedT != T->getNamedType()) {
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005057 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00005058 T->getKeyword(),
Douglas Gregor844cb502011-03-01 18:12:44 +00005059 QualifierLoc, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00005060 if (Result.isNull())
5061 return QualType();
5062 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00005063
Abramo Bagnara6150c882010-05-11 21:36:43 +00005064 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005065 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005066 NewTL.setQualifierLoc(QualifierLoc);
John McCall550e0c22009-10-21 00:40:46 +00005067 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005068}
Mike Stump11289f42009-09-09 15:08:12 +00005069
5070template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00005071QualType TreeTransform<Derived>::TransformAttributedType(
5072 TypeLocBuilder &TLB,
5073 AttributedTypeLoc TL) {
5074 const AttributedType *oldType = TL.getTypePtr();
5075 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
5076 if (modifiedType.isNull())
5077 return QualType();
5078
5079 QualType result = TL.getType();
5080
5081 // FIXME: dependent operand expressions?
5082 if (getDerived().AlwaysRebuild() ||
5083 modifiedType != oldType->getModifiedType()) {
5084 // TODO: this is really lame; we should really be rebuilding the
5085 // equivalent type from first principles.
5086 QualType equivalentType
5087 = getDerived().TransformType(oldType->getEquivalentType());
5088 if (equivalentType.isNull())
5089 return QualType();
5090 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
5091 modifiedType,
5092 equivalentType);
5093 }
5094
5095 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
5096 newTL.setAttrNameLoc(TL.getAttrNameLoc());
5097 if (TL.hasAttrOperand())
5098 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5099 if (TL.hasAttrExprOperand())
5100 newTL.setAttrExprOperand(TL.getAttrExprOperand());
5101 else if (TL.hasAttrEnumOperand())
5102 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
5103
5104 return result;
5105}
5106
5107template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00005108QualType
5109TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
5110 ParenTypeLoc TL) {
5111 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
5112 if (Inner.isNull())
5113 return QualType();
5114
5115 QualType Result = TL.getType();
5116 if (getDerived().AlwaysRebuild() ||
5117 Inner != TL.getInnerLoc().getType()) {
5118 Result = getDerived().RebuildParenType(Inner);
5119 if (Result.isNull())
5120 return QualType();
5121 }
5122
5123 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
5124 NewTL.setLParenLoc(TL.getLParenLoc());
5125 NewTL.setRParenLoc(TL.getRParenLoc());
5126 return Result;
5127}
5128
5129template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00005130QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005131 DependentNameTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005132 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00005133
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005134 NestedNameSpecifierLoc QualifierLoc
5135 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5136 if (!QualifierLoc)
Douglas Gregord6ff3322009-08-04 16:50:30 +00005137 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005138
John McCallc392f372010-06-11 00:33:02 +00005139 QualType Result
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005140 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005141 TL.getElaboratedKeywordLoc(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005142 QualifierLoc,
5143 T->getIdentifier(),
John McCallc392f372010-06-11 00:33:02 +00005144 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00005145 if (Result.isNull())
5146 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005147
Abramo Bagnarad7548482010-05-19 21:37:53 +00005148 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
5149 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00005150 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
5151
Abramo Bagnarad7548482010-05-19 21:37:53 +00005152 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005153 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005154 NewTL.setQualifierLoc(QualifierLoc);
John McCallc392f372010-06-11 00:33:02 +00005155 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00005156 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005157 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005158 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00005159 NewTL.setNameLoc(TL.getNameLoc());
5160 }
John McCall550e0c22009-10-21 00:40:46 +00005161 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005162}
Mike Stump11289f42009-09-09 15:08:12 +00005163
Douglas Gregord6ff3322009-08-04 16:50:30 +00005164template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00005165QualType TreeTransform<Derived>::
5166 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005167 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregora7a795b2011-03-01 20:11:18 +00005168 NestedNameSpecifierLoc QualifierLoc;
5169 if (TL.getQualifierLoc()) {
5170 QualifierLoc
5171 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5172 if (!QualifierLoc)
Douglas Gregor5a064722011-02-28 17:23:35 +00005173 return QualType();
5174 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005175
John McCall31f82722010-11-12 08:19:04 +00005176 return getDerived()
Douglas Gregora7a795b2011-03-01 20:11:18 +00005177 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall31f82722010-11-12 08:19:04 +00005178}
5179
5180template<typename Derived>
5181QualType TreeTransform<Derived>::
Douglas Gregora7a795b2011-03-01 20:11:18 +00005182TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
5183 DependentTemplateSpecializationTypeLoc TL,
5184 NestedNameSpecifierLoc QualifierLoc) {
5185 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00005186
Douglas Gregora7a795b2011-03-01 20:11:18 +00005187 TemplateArgumentListInfo NewTemplateArgs;
5188 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5189 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00005190
Douglas Gregora7a795b2011-03-01 20:11:18 +00005191 typedef TemplateArgumentLocContainerIterator<
5192 DependentTemplateSpecializationTypeLoc> ArgIterator;
5193 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5194 ArgIterator(TL, TL.getNumArgs()),
5195 NewTemplateArgs))
5196 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005197
Douglas Gregora7a795b2011-03-01 20:11:18 +00005198 QualType Result
5199 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
5200 QualifierLoc,
5201 T->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005202 TL.getTemplateNameLoc(),
Douglas Gregora7a795b2011-03-01 20:11:18 +00005203 NewTemplateArgs);
5204 if (Result.isNull())
5205 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005206
Douglas Gregora7a795b2011-03-01 20:11:18 +00005207 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
5208 QualType NamedT = ElabT->getNamedType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005209
Douglas Gregora7a795b2011-03-01 20:11:18 +00005210 // Copy information relevant to the template specialization.
5211 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor43f788f2011-03-07 02:33:33 +00005212 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005213 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005214 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005215 NamedTL.setLAngleLoc(TL.getLAngleLoc());
5216 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005217 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005218 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier1dcde962012-08-08 18:46:20 +00005219
Douglas Gregora7a795b2011-03-01 20:11:18 +00005220 // Copy information relevant to the elaborated type.
5221 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005222 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005223 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor43f788f2011-03-07 02:33:33 +00005224 } else if (isa<DependentTemplateSpecializationType>(Result)) {
5225 DependentTemplateSpecializationTypeLoc SpecTL
5226 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005227 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005228 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005229 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005230 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005231 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5232 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005233 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005234 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005235 } else {
Douglas Gregor43f788f2011-03-07 02:33:33 +00005236 TemplateSpecializationTypeLoc SpecTL
5237 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005238 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005239 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005240 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5241 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005242 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005243 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005244 }
5245 return Result;
5246}
5247
5248template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00005249QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5250 PackExpansionTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005251 QualType Pattern
5252 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor822d0302011-01-12 17:07:58 +00005253 if (Pattern.isNull())
5254 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005255
5256 QualType Result = TL.getType();
Douglas Gregor822d0302011-01-12 17:07:58 +00005257 if (getDerived().AlwaysRebuild() ||
5258 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005259 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00005260 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00005261 TL.getEllipsisLoc(),
5262 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00005263 if (Result.isNull())
5264 return QualType();
5265 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005266
Douglas Gregor822d0302011-01-12 17:07:58 +00005267 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5268 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5269 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00005270}
5271
5272template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005273QualType
5274TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005275 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005276 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00005277 TLB.pushFullCopy(TL);
5278 return TL.getType();
5279}
5280
5281template<typename Derived>
5282QualType
5283TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005284 ObjCObjectTypeLoc TL) {
John McCall8b07ec22010-05-15 11:32:37 +00005285 // ObjCObjectType is never dependent.
5286 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00005287 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005288}
Mike Stump11289f42009-09-09 15:08:12 +00005289
5290template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005291QualType
5292TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005293 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005294 // ObjCObjectPointerType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00005295 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00005296 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00005297}
5298
Douglas Gregord6ff3322009-08-04 16:50:30 +00005299//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00005300// Statement transformation
5301//===----------------------------------------------------------------------===//
5302template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005303StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005304TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00005305 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005306}
5307
5308template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005309StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005310TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
5311 return getDerived().TransformCompoundStmt(S, false);
5312}
5313
5314template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005315StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005316TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00005317 bool IsStmtExpr) {
Dmitri Gribenko800ddf32012-02-14 22:14:32 +00005318 Sema::CompoundScopeRAII CompoundScope(getSema());
5319
John McCall1ababa62010-08-27 19:56:05 +00005320 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00005321 bool SubStmtChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005322 SmallVector<Stmt*, 8> Statements;
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005323 for (auto *B : S->body()) {
5324 StmtResult Result = getDerived().TransformStmt(B);
John McCall1ababa62010-08-27 19:56:05 +00005325 if (Result.isInvalid()) {
5326 // Immediately fail if this was a DeclStmt, since it's very
5327 // likely that this will cause problems for future statements.
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005328 if (isa<DeclStmt>(B))
John McCall1ababa62010-08-27 19:56:05 +00005329 return StmtError();
5330
5331 // Otherwise, just keep processing substatements and fail later.
5332 SubStmtInvalid = true;
5333 continue;
5334 }
Mike Stump11289f42009-09-09 15:08:12 +00005335
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005336 SubStmtChanged = SubStmtChanged || Result.get() != B;
Douglas Gregorebe10102009-08-20 07:17:43 +00005337 Statements.push_back(Result.takeAs<Stmt>());
5338 }
Mike Stump11289f42009-09-09 15:08:12 +00005339
John McCall1ababa62010-08-27 19:56:05 +00005340 if (SubStmtInvalid)
5341 return StmtError();
5342
Douglas Gregorebe10102009-08-20 07:17:43 +00005343 if (!getDerived().AlwaysRebuild() &&
5344 !SubStmtChanged)
John McCallc3007a22010-10-26 07:05:15 +00005345 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005346
5347 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00005348 Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00005349 S->getRBracLoc(),
5350 IsStmtExpr);
5351}
Mike Stump11289f42009-09-09 15:08:12 +00005352
Douglas Gregorebe10102009-08-20 07:17:43 +00005353template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005354StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005355TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005356 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00005357 {
Eli Friedman1f4f9dd2012-01-18 02:54:10 +00005358 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5359 Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005360
Eli Friedman06577382009-11-19 03:14:00 +00005361 // Transform the left-hand case value.
5362 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00005363 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman06577382009-11-19 03:14:00 +00005364 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005365 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005366
Eli Friedman06577382009-11-19 03:14:00 +00005367 // Transform the right-hand case value (for the GNU case-range extension).
5368 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00005369 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman06577382009-11-19 03:14:00 +00005370 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005371 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00005372 }
Mike Stump11289f42009-09-09 15:08:12 +00005373
Douglas Gregorebe10102009-08-20 07:17:43 +00005374 // Build the case statement.
5375 // Case statements are always rebuilt so that they will attached to their
5376 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005377 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00005378 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005379 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00005380 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005381 S->getColonLoc());
5382 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005383 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005384
Douglas Gregorebe10102009-08-20 07:17:43 +00005385 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00005386 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005387 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005388 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005389
Douglas Gregorebe10102009-08-20 07:17:43 +00005390 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00005391 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005392}
5393
5394template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005395StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005396TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005397 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00005398 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005399 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005400 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005401
Douglas Gregorebe10102009-08-20 07:17:43 +00005402 // Default statements are always rebuilt
5403 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00005404 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005405}
Mike Stump11289f42009-09-09 15:08:12 +00005406
Douglas Gregorebe10102009-08-20 07:17:43 +00005407template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005408StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005409TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005410 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005411 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005412 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005413
Chris Lattnercab02a62011-02-17 20:34:02 +00005414 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5415 S->getDecl());
5416 if (!LD)
5417 return StmtError();
Richard Smithc202b282012-04-14 00:33:13 +00005418
5419
Douglas Gregorebe10102009-08-20 07:17:43 +00005420 // FIXME: Pass the real colon location in.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00005421 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005422 cast<LabelDecl>(LD), SourceLocation(),
5423 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005424}
Mike Stump11289f42009-09-09 15:08:12 +00005425
Douglas Gregorebe10102009-08-20 07:17:43 +00005426template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005427StmtResult
Richard Smithc202b282012-04-14 00:33:13 +00005428TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
5429 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5430 if (SubStmt.isInvalid())
5431 return StmtError();
5432
5433 // TODO: transform attributes
5434 if (SubStmt.get() == S->getSubStmt() /* && attrs are the same */)
5435 return S;
5436
5437 return getDerived().RebuildAttributedStmt(S->getAttrLoc(),
5438 S->getAttrs(),
5439 SubStmt.get());
5440}
5441
5442template<typename Derived>
5443StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005444TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005445 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005446 ExprResult Cond;
Douglas Gregor633caca2009-11-23 23:44:04 +00005447 VarDecl *ConditionVar = 0;
5448 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005449 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00005450 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005451 getDerived().TransformDefinition(
5452 S->getConditionVariable()->getLocation(),
5453 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00005454 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005455 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005456 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00005457 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005458
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005459 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005460 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005461
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005462 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00005463 if (S->getCond()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005464 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005465 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005466 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005467 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005468
John McCallb268a282010-08-23 23:25:46 +00005469 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005470 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005471 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005472
John McCallb268a282010-08-23 23:25:46 +00005473 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5474 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005475 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005476
Douglas Gregorebe10102009-08-20 07:17:43 +00005477 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00005478 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00005479 if (Then.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005480 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005481
Douglas Gregorebe10102009-08-20 07:17:43 +00005482 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00005483 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00005484 if (Else.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005485 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005486
Douglas Gregorebe10102009-08-20 07:17:43 +00005487 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00005488 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005489 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005490 Then.get() == S->getThen() &&
5491 Else.get() == S->getElse())
John McCallc3007a22010-10-26 07:05:15 +00005492 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005493
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005494 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00005495 Then.get(),
John McCallb268a282010-08-23 23:25:46 +00005496 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005497}
5498
5499template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005500StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005501TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005502 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00005503 ExprResult Cond;
Douglas Gregordcf19622009-11-24 17:07:59 +00005504 VarDecl *ConditionVar = 0;
5505 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005506 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00005507 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005508 getDerived().TransformDefinition(
5509 S->getConditionVariable()->getLocation(),
5510 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00005511 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005512 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005513 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00005514 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005515
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005516 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005517 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005518 }
Mike Stump11289f42009-09-09 15:08:12 +00005519
Douglas Gregorebe10102009-08-20 07:17:43 +00005520 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005521 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00005522 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00005523 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00005524 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005525 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005526
Douglas Gregorebe10102009-08-20 07:17:43 +00005527 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005528 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005529 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005530 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005531
Douglas Gregorebe10102009-08-20 07:17:43 +00005532 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00005533 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5534 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005535}
Mike Stump11289f42009-09-09 15:08:12 +00005536
Douglas Gregorebe10102009-08-20 07:17:43 +00005537template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005538StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005539TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005540 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005541 ExprResult Cond;
Douglas Gregor680f8612009-11-24 21:15:44 +00005542 VarDecl *ConditionVar = 0;
5543 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005544 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00005545 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005546 getDerived().TransformDefinition(
5547 S->getConditionVariable()->getLocation(),
5548 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00005549 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005550 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005551 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00005552 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005553
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005554 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005555 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005556
5557 if (S->getCond()) {
5558 // Convert the condition to a boolean value.
Chad Rosier1dcde962012-08-08 18:46:20 +00005559 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005560 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005561 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005562 return StmtError();
John McCallb268a282010-08-23 23:25:46 +00005563 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00005564 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005565 }
Mike Stump11289f42009-09-09 15:08:12 +00005566
John McCallb268a282010-08-23 23:25:46 +00005567 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5568 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005569 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005570
Douglas Gregorebe10102009-08-20 07:17:43 +00005571 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005572 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005573 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005574 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005575
Douglas Gregorebe10102009-08-20 07:17:43 +00005576 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00005577 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005578 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005579 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00005580 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005581
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005582 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00005583 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005584}
Mike Stump11289f42009-09-09 15:08:12 +00005585
Douglas Gregorebe10102009-08-20 07:17:43 +00005586template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005587StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005588TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005589 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005590 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005591 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005592 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005593
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005594 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005595 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005596 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005597 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005598
Douglas Gregorebe10102009-08-20 07:17:43 +00005599 if (!getDerived().AlwaysRebuild() &&
5600 Cond.get() == S->getCond() &&
5601 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005602 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005603
John McCallb268a282010-08-23 23:25:46 +00005604 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5605 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005606 S->getRParenLoc());
5607}
Mike Stump11289f42009-09-09 15:08:12 +00005608
Douglas Gregorebe10102009-08-20 07:17:43 +00005609template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005610StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005611TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005612 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00005613 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00005614 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005615 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005616
Douglas Gregorebe10102009-08-20 07:17:43 +00005617 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005618 ExprResult Cond;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005619 VarDecl *ConditionVar = 0;
5620 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005621 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005622 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005623 getDerived().TransformDefinition(
5624 S->getConditionVariable()->getLocation(),
5625 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005626 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005627 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005628 } else {
5629 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005630
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005631 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005632 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005633
5634 if (S->getCond()) {
5635 // Convert the condition to a boolean value.
Chad Rosier1dcde962012-08-08 18:46:20 +00005636 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005637 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005638 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005639 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005640
John McCallb268a282010-08-23 23:25:46 +00005641 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005642 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005643 }
Mike Stump11289f42009-09-09 15:08:12 +00005644
Chad Rosier1dcde962012-08-08 18:46:20 +00005645 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
John McCallb268a282010-08-23 23:25:46 +00005646 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005647 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005648
Douglas Gregorebe10102009-08-20 07:17:43 +00005649 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00005650 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005651 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005652 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005653
Richard Smith945f8d32013-01-14 22:39:08 +00005654 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
John McCallb268a282010-08-23 23:25:46 +00005655 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005656 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005657
Douglas Gregorebe10102009-08-20 07:17:43 +00005658 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005659 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005660 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005661 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005662
Douglas Gregorebe10102009-08-20 07:17:43 +00005663 if (!getDerived().AlwaysRebuild() &&
5664 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00005665 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005666 Inc.get() == S->getInc() &&
5667 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005668 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005669
Douglas Gregorebe10102009-08-20 07:17:43 +00005670 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005671 Init.get(), FullCond, ConditionVar,
5672 FullInc, S->getRParenLoc(), Body.get());
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>::TransformGotoStmt(GotoStmt *S) {
Chris Lattnercab02a62011-02-17 20:34:02 +00005678 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5679 S->getLabel());
5680 if (!LD)
5681 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005682
Douglas Gregorebe10102009-08-20 07:17:43 +00005683 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00005684 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005685 cast<LabelDecl>(LD));
Douglas Gregorebe10102009-08-20 07:17:43 +00005686}
5687
5688template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005689StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005690TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005691 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00005692 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005693 return StmtError();
Eli Friedman9ccdb1d2012-01-31 22:47:07 +00005694 Target = SemaRef.MaybeCreateExprWithCleanups(Target.take());
Mike Stump11289f42009-09-09 15:08:12 +00005695
Douglas Gregorebe10102009-08-20 07:17:43 +00005696 if (!getDerived().AlwaysRebuild() &&
5697 Target.get() == S->getTarget())
John McCallc3007a22010-10-26 07:05:15 +00005698 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005699
5700 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00005701 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005702}
5703
5704template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005705StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005706TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00005707 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005708}
Mike Stump11289f42009-09-09 15:08:12 +00005709
Douglas Gregorebe10102009-08-20 07:17:43 +00005710template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005711StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005712TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00005713 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005714}
Mike Stump11289f42009-09-09 15:08:12 +00005715
Douglas Gregorebe10102009-08-20 07:17:43 +00005716template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005717StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005718TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005719 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregorebe10102009-08-20 07:17:43 +00005720 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005721 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00005722
Mike Stump11289f42009-09-09 15:08:12 +00005723 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00005724 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00005725 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005726}
Mike Stump11289f42009-09-09 15:08:12 +00005727
Douglas Gregorebe10102009-08-20 07:17:43 +00005728template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005729StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005730TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005731 bool DeclChanged = false;
Chris Lattner01cf8db2011-07-20 06:58:45 +00005732 SmallVector<Decl *, 4> Decls;
Aaron Ballman535bbcc2014-03-14 17:01:24 +00005733 for (auto *D : S->decls()) {
5734 Decl *Transformed = getDerived().TransformDefinition(D->getLocation(), D);
Douglas Gregorebe10102009-08-20 07:17:43 +00005735 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00005736 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005737
Aaron Ballman535bbcc2014-03-14 17:01:24 +00005738 if (Transformed != D)
Douglas Gregorebe10102009-08-20 07:17:43 +00005739 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00005740
Douglas Gregorebe10102009-08-20 07:17:43 +00005741 Decls.push_back(Transformed);
5742 }
Mike Stump11289f42009-09-09 15:08:12 +00005743
Douglas Gregorebe10102009-08-20 07:17:43 +00005744 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCallc3007a22010-10-26 07:05:15 +00005745 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005746
Rafael Espindolaab417692013-07-09 12:05:01 +00005747 return getDerived().RebuildDeclStmt(Decls, S->getStartLoc(), S->getEndLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005748}
Mike Stump11289f42009-09-09 15:08:12 +00005749
Douglas Gregorebe10102009-08-20 07:17:43 +00005750template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005751StmtResult
Chad Rosierde70e0e2012-08-25 00:11:56 +00005752TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005753
Benjamin Kramerf0623432012-08-23 22:51:59 +00005754 SmallVector<Expr*, 8> Constraints;
5755 SmallVector<Expr*, 8> Exprs;
Chris Lattner01cf8db2011-07-20 06:58:45 +00005756 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00005757
John McCalldadc5752010-08-24 06:29:42 +00005758 ExprResult AsmString;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005759 SmallVector<Expr*, 8> Clobbers;
Anders Carlssonaaeef072010-01-24 05:50:09 +00005760
5761 bool ExprsChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00005762
Anders Carlssonaaeef072010-01-24 05:50:09 +00005763 // Go through the outputs.
5764 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005765 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005766
Anders Carlssonaaeef072010-01-24 05:50:09 +00005767 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005768 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005769
Anders Carlssonaaeef072010-01-24 05:50:09 +00005770 // Transform the output expr.
5771 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005772 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005773 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005774 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005775
Anders Carlssonaaeef072010-01-24 05:50:09 +00005776 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00005777
John McCallb268a282010-08-23 23:25:46 +00005778 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005779 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005780
Anders Carlssonaaeef072010-01-24 05:50:09 +00005781 // Go through the inputs.
5782 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005783 Names.push_back(S->getInputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005784
Anders Carlssonaaeef072010-01-24 05:50:09 +00005785 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005786 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005787
Anders Carlssonaaeef072010-01-24 05:50:09 +00005788 // Transform the input expr.
5789 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005790 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005791 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005792 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005793
Anders Carlssonaaeef072010-01-24 05:50:09 +00005794 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00005795
John McCallb268a282010-08-23 23:25:46 +00005796 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005797 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005798
Anders Carlssonaaeef072010-01-24 05:50:09 +00005799 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCallc3007a22010-10-26 07:05:15 +00005800 return SemaRef.Owned(S);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005801
5802 // Go through the clobbers.
5803 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosierd9fb09a2012-08-27 23:28:41 +00005804 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00005805
5806 // No need to transform the asm string literal.
5807 AsmString = SemaRef.Owned(S->getAsmString());
Chad Rosierde70e0e2012-08-25 00:11:56 +00005808 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
5809 S->isVolatile(), S->getNumOutputs(),
5810 S->getNumInputs(), Names.data(),
5811 Constraints, Exprs, AsmString.get(),
5812 Clobbers, S->getRParenLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005813}
5814
Chad Rosier32503022012-06-11 20:47:18 +00005815template<typename Derived>
5816StmtResult
5817TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier99fc3812012-08-07 00:29:06 +00005818 ArrayRef<Token> AsmToks =
5819 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier3ed0bd92012-08-08 19:48:07 +00005820
John McCallf413f5e2013-05-03 00:10:13 +00005821 bool HadError = false, HadChange = false;
5822
5823 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
5824 SmallVector<Expr*, 8> TransformedExprs;
5825 TransformedExprs.reserve(SrcExprs.size());
5826 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
5827 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
5828 if (!Result.isUsable()) {
5829 HadError = true;
5830 } else {
5831 HadChange |= (Result.get() != SrcExprs[i]);
5832 TransformedExprs.push_back(Result.take());
5833 }
5834 }
5835
5836 if (HadError) return StmtError();
5837 if (!HadChange && !getDerived().AlwaysRebuild())
5838 return Owned(S);
5839
Chad Rosierb6f46c12012-08-15 16:53:30 +00005840 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
John McCallf413f5e2013-05-03 00:10:13 +00005841 AsmToks, S->getAsmString(),
5842 S->getNumOutputs(), S->getNumInputs(),
5843 S->getAllConstraints(), S->getClobbers(),
5844 TransformedExprs, S->getEndLoc());
Chad Rosier32503022012-06-11 20:47:18 +00005845}
Douglas Gregorebe10102009-08-20 07:17:43 +00005846
5847template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005848StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005849TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005850 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00005851 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005852 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005853 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005854
Douglas Gregor96c79492010-04-23 22:50:49 +00005855 // Transform the @catch statements (if present).
5856 bool AnyCatchChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005857 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor96c79492010-04-23 22:50:49 +00005858 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00005859 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00005860 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005861 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00005862 if (Catch.get() != S->getCatchStmt(I))
5863 AnyCatchChanged = true;
5864 CatchStmts.push_back(Catch.release());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005865 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005866
Douglas Gregor306de2f2010-04-22 23:59:56 +00005867 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00005868 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00005869 if (S->getFinallyStmt()) {
5870 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5871 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005872 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00005873 }
5874
5875 // If nothing changed, just retain this statement.
5876 if (!getDerived().AlwaysRebuild() &&
5877 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00005878 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00005879 Finally.get() == S->getFinallyStmt())
John McCallc3007a22010-10-26 07:05:15 +00005880 return SemaRef.Owned(S);
Chad Rosier1dcde962012-08-08 18:46:20 +00005881
Douglas Gregor306de2f2010-04-22 23:59:56 +00005882 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00005883 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00005884 CatchStmts, Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005885}
Mike Stump11289f42009-09-09 15:08:12 +00005886
Douglas Gregorebe10102009-08-20 07:17:43 +00005887template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005888StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005889TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005890 // Transform the @catch parameter, if there is one.
5891 VarDecl *Var = 0;
5892 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5893 TypeSourceInfo *TSInfo = 0;
5894 if (FromVar->getTypeSourceInfo()) {
5895 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5896 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005897 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005898 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005899
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005900 QualType T;
5901 if (TSInfo)
5902 T = TSInfo->getType();
5903 else {
5904 T = getDerived().TransformType(FromVar->getType());
5905 if (T.isNull())
Chad Rosier1dcde962012-08-08 18:46:20 +00005906 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005907 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005908
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005909 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5910 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00005911 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005912 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005913
John McCalldadc5752010-08-24 06:29:42 +00005914 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005915 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005916 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005917
5918 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005919 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005920 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005921}
Mike Stump11289f42009-09-09 15:08:12 +00005922
Douglas Gregorebe10102009-08-20 07:17:43 +00005923template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005924StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005925TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005926 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005927 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005928 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005929 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005930
Douglas Gregor306de2f2010-04-22 23:59:56 +00005931 // If nothing changed, just retain this statement.
5932 if (!getDerived().AlwaysRebuild() &&
5933 Body.get() == S->getFinallyBody())
John McCallc3007a22010-10-26 07:05:15 +00005934 return SemaRef.Owned(S);
Douglas Gregor306de2f2010-04-22 23:59:56 +00005935
5936 // Build a new statement.
5937 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00005938 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005939}
Mike Stump11289f42009-09-09 15:08:12 +00005940
Douglas Gregorebe10102009-08-20 07:17:43 +00005941template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005942StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005943TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005944 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00005945 if (S->getThrowExpr()) {
5946 Operand = getDerived().TransformExpr(S->getThrowExpr());
5947 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005948 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00005949 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005950
Douglas Gregor2900c162010-04-22 21:44:01 +00005951 if (!getDerived().AlwaysRebuild() &&
5952 Operand.get() == S->getThrowExpr())
John McCallc3007a22010-10-26 07:05:15 +00005953 return getSema().Owned(S);
Chad Rosier1dcde962012-08-08 18:46:20 +00005954
John McCallb268a282010-08-23 23:25:46 +00005955 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005956}
Mike Stump11289f42009-09-09 15:08:12 +00005957
Douglas Gregorebe10102009-08-20 07:17:43 +00005958template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005959StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005960TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00005961 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00005962 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00005963 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00005964 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005965 return StmtError();
John McCalld9bb7432011-07-27 21:50:02 +00005966 Object =
5967 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
5968 Object.get());
5969 if (Object.isInvalid())
5970 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005971
Douglas Gregor6148de72010-04-22 22:01:21 +00005972 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005973 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00005974 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005975 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005976
Douglas Gregor6148de72010-04-22 22:01:21 +00005977 // If nothing change, just retain the current statement.
5978 if (!getDerived().AlwaysRebuild() &&
5979 Object.get() == S->getSynchExpr() &&
5980 Body.get() == S->getSynchBody())
John McCallc3007a22010-10-26 07:05:15 +00005981 return SemaRef.Owned(S);
Douglas Gregor6148de72010-04-22 22:01:21 +00005982
5983 // Build a new statement.
5984 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00005985 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005986}
5987
5988template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005989StmtResult
John McCall31168b02011-06-15 23:02:42 +00005990TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
5991 ObjCAutoreleasePoolStmt *S) {
5992 // Transform the body.
5993 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
5994 if (Body.isInvalid())
5995 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005996
John McCall31168b02011-06-15 23:02:42 +00005997 // If nothing changed, just retain this statement.
5998 if (!getDerived().AlwaysRebuild() &&
5999 Body.get() == S->getSubStmt())
6000 return SemaRef.Owned(S);
6001
6002 // Build a new statement.
6003 return getDerived().RebuildObjCAutoreleasePoolStmt(
6004 S->getAtLoc(), Body.get());
6005}
6006
6007template<typename Derived>
6008StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006009TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00006010 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00006011 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00006012 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006013 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006014 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006015
Douglas Gregorf68a5082010-04-22 23:10:45 +00006016 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00006017 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006018 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006019 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006020
Douglas Gregorf68a5082010-04-22 23:10:45 +00006021 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006022 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006023 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006024 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006025
Douglas Gregorf68a5082010-04-22 23:10:45 +00006026 // If nothing changed, just retain this statement.
6027 if (!getDerived().AlwaysRebuild() &&
6028 Element.get() == S->getElement() &&
6029 Collection.get() == S->getCollection() &&
6030 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00006031 return SemaRef.Owned(S);
Chad Rosier1dcde962012-08-08 18:46:20 +00006032
Douglas Gregorf68a5082010-04-22 23:10:45 +00006033 // Build a new statement.
6034 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00006035 Element.get(),
6036 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00006037 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006038 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006039}
6040
David Majnemer5f7efef2013-10-15 09:50:08 +00006041template <typename Derived>
6042StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006043 // Transform the exception declaration, if any.
6044 VarDecl *Var = 0;
David Majnemer5f7efef2013-10-15 09:50:08 +00006045 if (VarDecl *ExceptionDecl = S->getExceptionDecl()) {
6046 TypeSourceInfo *T =
6047 getDerived().TransformType(ExceptionDecl->getTypeSourceInfo());
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00006048 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006049 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006050
David Majnemer5f7efef2013-10-15 09:50:08 +00006051 Var = getDerived().RebuildExceptionDecl(
6052 ExceptionDecl, T, ExceptionDecl->getInnerLocStart(),
6053 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
Douglas Gregorb412e172010-07-25 18:17:45 +00006054 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00006055 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00006056 }
Mike Stump11289f42009-09-09 15:08:12 +00006057
Douglas Gregorebe10102009-08-20 07:17:43 +00006058 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00006059 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00006060 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006061 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006062
David Majnemer5f7efef2013-10-15 09:50:08 +00006063 if (!getDerived().AlwaysRebuild() && !Var &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006064 Handler.get() == S->getHandlerBlock())
John McCallc3007a22010-10-26 07:05:15 +00006065 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00006066
David Majnemer5f7efef2013-10-15 09:50:08 +00006067 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006068}
Mike Stump11289f42009-09-09 15:08:12 +00006069
David Majnemer5f7efef2013-10-15 09:50:08 +00006070template <typename Derived>
6071StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006072 // Transform the try block itself.
David Majnemer5f7efef2013-10-15 09:50:08 +00006073 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
Douglas Gregorebe10102009-08-20 07:17:43 +00006074 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006075 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006076
Douglas Gregorebe10102009-08-20 07:17:43 +00006077 // Transform the handlers.
6078 bool HandlerChanged = false;
David Majnemer5f7efef2013-10-15 09:50:08 +00006079 SmallVector<Stmt *, 8> Handlers;
Douglas Gregorebe10102009-08-20 07:17:43 +00006080 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
David Majnemer5f7efef2013-10-15 09:50:08 +00006081 StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I));
Douglas Gregorebe10102009-08-20 07:17:43 +00006082 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006083 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006084
Douglas Gregorebe10102009-08-20 07:17:43 +00006085 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
6086 Handlers.push_back(Handler.takeAs<Stmt>());
6087 }
Mike Stump11289f42009-09-09 15:08:12 +00006088
David Majnemer5f7efef2013-10-15 09:50:08 +00006089 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006090 !HandlerChanged)
John McCallc3007a22010-10-26 07:05:15 +00006091 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00006092
John McCallb268a282010-08-23 23:25:46 +00006093 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006094 Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00006095}
Mike Stump11289f42009-09-09 15:08:12 +00006096
Richard Smith02e85f32011-04-14 22:09:26 +00006097template<typename Derived>
6098StmtResult
6099TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
6100 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
6101 if (Range.isInvalid())
6102 return StmtError();
6103
6104 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
6105 if (BeginEnd.isInvalid())
6106 return StmtError();
6107
6108 ExprResult Cond = getDerived().TransformExpr(S->getCond());
6109 if (Cond.isInvalid())
6110 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006111 if (Cond.get())
6112 Cond = SemaRef.CheckBooleanCondition(Cond.take(), S->getColonLoc());
6113 if (Cond.isInvalid())
6114 return StmtError();
6115 if (Cond.get())
6116 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.take());
Richard Smith02e85f32011-04-14 22:09:26 +00006117
6118 ExprResult Inc = getDerived().TransformExpr(S->getInc());
6119 if (Inc.isInvalid())
6120 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006121 if (Inc.get())
6122 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.take());
Richard Smith02e85f32011-04-14 22:09:26 +00006123
6124 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
6125 if (LoopVar.isInvalid())
6126 return StmtError();
6127
6128 StmtResult NewStmt = S;
6129 if (getDerived().AlwaysRebuild() ||
6130 Range.get() != S->getRangeStmt() ||
6131 BeginEnd.get() != S->getBeginEndStmt() ||
6132 Cond.get() != S->getCond() ||
6133 Inc.get() != S->getInc() ||
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006134 LoopVar.get() != S->getLoopVarStmt()) {
Richard Smith02e85f32011-04-14 22:09:26 +00006135 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6136 S->getColonLoc(), Range.get(),
6137 BeginEnd.get(), Cond.get(),
6138 Inc.get(), LoopVar.get(),
6139 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006140 if (NewStmt.isInvalid())
6141 return StmtError();
6142 }
Richard Smith02e85f32011-04-14 22:09:26 +00006143
6144 StmtResult Body = getDerived().TransformStmt(S->getBody());
6145 if (Body.isInvalid())
6146 return StmtError();
6147
6148 // Body has changed but we didn't rebuild the for-range statement. Rebuild
6149 // it now so we have a new statement to attach the body to.
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006150 if (Body.get() != S->getBody() && NewStmt.get() == S) {
Richard Smith02e85f32011-04-14 22:09:26 +00006151 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6152 S->getColonLoc(), Range.get(),
6153 BeginEnd.get(), Cond.get(),
6154 Inc.get(), LoopVar.get(),
6155 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006156 if (NewStmt.isInvalid())
6157 return StmtError();
6158 }
Richard Smith02e85f32011-04-14 22:09:26 +00006159
6160 if (NewStmt.get() == S)
6161 return SemaRef.Owned(S);
6162
6163 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
6164}
6165
John Wiegley1c0675e2011-04-28 01:08:34 +00006166template<typename Derived>
6167StmtResult
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006168TreeTransform<Derived>::TransformMSDependentExistsStmt(
6169 MSDependentExistsStmt *S) {
6170 // Transform the nested-name-specifier, if any.
6171 NestedNameSpecifierLoc QualifierLoc;
6172 if (S->getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006173 QualifierLoc
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006174 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
6175 if (!QualifierLoc)
6176 return StmtError();
6177 }
6178
6179 // Transform the declaration name.
6180 DeclarationNameInfo NameInfo = S->getNameInfo();
6181 if (NameInfo.getName()) {
6182 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6183 if (!NameInfo.getName())
6184 return StmtError();
6185 }
6186
6187 // Check whether anything changed.
6188 if (!getDerived().AlwaysRebuild() &&
6189 QualifierLoc == S->getQualifierLoc() &&
6190 NameInfo.getName() == S->getNameInfo().getName())
6191 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006192
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006193 // Determine whether this name exists, if we can.
6194 CXXScopeSpec SS;
6195 SS.Adopt(QualifierLoc);
6196 bool Dependent = false;
6197 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/0, SS, NameInfo)) {
6198 case Sema::IER_Exists:
6199 if (S->isIfExists())
6200 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006201
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006202 return new (getSema().Context) NullStmt(S->getKeywordLoc());
6203
6204 case Sema::IER_DoesNotExist:
6205 if (S->isIfNotExists())
6206 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006207
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006208 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00006209
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006210 case Sema::IER_Dependent:
6211 Dependent = true;
6212 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006213
Douglas Gregor4a2a8f72011-10-25 03:44:56 +00006214 case Sema::IER_Error:
6215 return StmtError();
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006216 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006217
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006218 // We need to continue with the instantiation, so do so now.
6219 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
6220 if (SubStmt.isInvalid())
6221 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006222
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006223 // If we have resolved the name, just transform to the substatement.
6224 if (!Dependent)
6225 return SubStmt;
Chad Rosier1dcde962012-08-08 18:46:20 +00006226
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006227 // The name is still dependent, so build a dependent expression again.
6228 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
6229 S->isIfExists(),
6230 QualifierLoc,
6231 NameInfo,
6232 SubStmt.get());
6233}
6234
6235template<typename Derived>
John McCall5e77d762013-04-16 07:28:30 +00006236ExprResult
6237TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
6238 NestedNameSpecifierLoc QualifierLoc;
6239 if (E->getQualifierLoc()) {
6240 QualifierLoc
6241 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6242 if (!QualifierLoc)
6243 return ExprError();
6244 }
6245
6246 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
6247 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
6248 if (!PD)
6249 return ExprError();
6250
6251 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
6252 if (Base.isInvalid())
6253 return ExprError();
6254
6255 return new (SemaRef.getASTContext())
6256 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
6257 SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
6258 QualifierLoc, E->getMemberLoc());
6259}
6260
David Majnemerfad8f482013-10-15 09:33:02 +00006261template <typename Derived>
6262StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00006263 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006264 if (TryBlock.isInvalid())
6265 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006266
6267 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
David Majnemer7e755502013-10-15 09:30:14 +00006268 if (Handler.isInvalid())
6269 return StmtError();
6270
David Majnemerfad8f482013-10-15 09:33:02 +00006271 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
6272 Handler.get() == S->getHandler())
John Wiegley1c0675e2011-04-28 01:08:34 +00006273 return SemaRef.Owned(S);
6274
David Majnemerfad8f482013-10-15 09:33:02 +00006275 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(),
6276 TryBlock.take(), Handler.take());
John Wiegley1c0675e2011-04-28 01:08:34 +00006277}
6278
David Majnemerfad8f482013-10-15 09:33:02 +00006279template <typename Derived>
6280StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
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().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.take());
John Wiegley1c0675e2011-04-28 01:08:34 +00006286}
6287
David Majnemerfad8f482013-10-15 09:33:02 +00006288template <typename Derived>
6289StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
John Wiegley1c0675e2011-04-28 01:08:34 +00006290 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
David Majnemerfad8f482013-10-15 09:33:02 +00006291 if (FilterExpr.isInvalid())
6292 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006293
David Majnemer7e755502013-10-15 09:30:14 +00006294 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006295 if (Block.isInvalid())
6296 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006297
David Majnemerfad8f482013-10-15 09:33:02 +00006298 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.take(),
John Wiegley1c0675e2011-04-28 01:08:34 +00006299 Block.take());
6300}
6301
David Majnemerfad8f482013-10-15 09:33:02 +00006302template <typename Derived>
6303StmtResult TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
6304 if (isa<SEHFinallyStmt>(Handler))
John Wiegley1c0675e2011-04-28 01:08:34 +00006305 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
6306 else
6307 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
6308}
6309
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006310template<typename Derived>
6311StmtResult
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006312TreeTransform<Derived>::TransformOMPExecutableDirective(
6313 OMPExecutableDirective *D) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00006314
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006315 // Transform the clauses
Alexey Bataev758e55e2013-09-06 18:03:48 +00006316 llvm::SmallVector<OMPClause *, 16> TClauses;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006317 ArrayRef<OMPClause *> Clauses = D->clauses();
6318 TClauses.reserve(Clauses.size());
6319 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
6320 I != E; ++I) {
6321 if (*I) {
6322 OMPClause *Clause = getDerived().TransformOMPClause(*I);
Alexey Bataev758e55e2013-09-06 18:03:48 +00006323 if (!Clause) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006324 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00006325 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006326 TClauses.push_back(Clause);
6327 }
6328 else {
6329 TClauses.push_back(0);
6330 }
6331 }
Alexey Bataev758e55e2013-09-06 18:03:48 +00006332 if (!D->getAssociatedStmt()) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006333 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00006334 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006335 StmtResult AssociatedStmt =
6336 getDerived().TransformStmt(D->getAssociatedStmt());
Alexey Bataev758e55e2013-09-06 18:03:48 +00006337 if (AssociatedStmt.isInvalid()) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006338 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00006339 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006340
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006341 return getDerived().RebuildOMPExecutableDirective(D->getDirectiveKind(),
6342 TClauses,
6343 AssociatedStmt.take(),
6344 D->getLocStart(),
6345 D->getLocEnd());
6346}
6347
6348template<typename Derived>
6349StmtResult
6350TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
6351 DeclarationNameInfo DirName;
Alexey Bataev3d76e772014-03-07 04:01:56 +00006352 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, 0);
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006353 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6354 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6355 return Res;
6356}
6357
6358template<typename Derived>
6359StmtResult
6360TreeTransform<Derived>::TransformOMPSimdDirective(OMPSimdDirective *D) {
6361 DeclarationNameInfo DirName;
Alexey Bataev96d15102014-03-07 04:16:48 +00006362 getDerived().getSema().StartOpenMPDSABlock(OMPD_simd, DirName, 0);
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006363 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6364 getDerived().getSema().EndOpenMPDSABlock(Res.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00006365 return Res;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006366}
6367
6368template<typename Derived>
6369OMPClause *
Alexey Bataevaadd52e2014-02-13 05:29:23 +00006370TreeTransform<Derived>::TransformOMPIfClause(OMPIfClause *C) {
Alexey Bataevaf7849e2014-03-05 06:45:14 +00006371 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
6372 if (Cond.isInvalid())
6373 return 0;
6374 return getDerived().RebuildOMPIfClause(Cond.take(), C->getLocStart(),
Alexey Bataevaadd52e2014-02-13 05:29:23 +00006375 C->getLParenLoc(), C->getLocEnd());
6376}
6377
6378template<typename Derived>
6379OMPClause *
Alexey Bataev568a8332014-03-06 06:15:19 +00006380TreeTransform<Derived>::TransformOMPNumThreadsClause(OMPNumThreadsClause *C) {
6381 ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads());
6382 if (NumThreads.isInvalid())
6383 return 0;
6384 return getDerived().RebuildOMPNumThreadsClause(NumThreads.take(),
6385 C->getLocStart(),
6386 C->getLParenLoc(),
6387 C->getLocEnd());
6388}
6389
Alexey Bataev62c87d22014-03-21 04:51:18 +00006390template <typename Derived>
6391OMPClause *
6392TreeTransform<Derived>::TransformOMPSafelenClause(OMPSafelenClause *C) {
6393 ExprResult E = getDerived().TransformExpr(C->getSafelen());
6394 if (E.isInvalid())
6395 return 0;
6396 return getDerived().RebuildOMPSafelenClause(
6397 E.take(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
6398}
6399
Alexey Bataev568a8332014-03-06 06:15:19 +00006400template<typename Derived>
6401OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006402TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
6403 return getDerived().RebuildOMPDefaultClause(C->getDefaultKind(),
6404 C->getDefaultKindKwLoc(),
6405 C->getLocStart(),
6406 C->getLParenLoc(),
6407 C->getLocEnd());
6408}
6409
6410template<typename Derived>
6411OMPClause *
Alexey Bataevbcbadb62014-05-06 06:04:14 +00006412TreeTransform<Derived>::TransformOMPProcBindClause(OMPProcBindClause *C) {
6413 return getDerived().RebuildOMPProcBindClause(C->getProcBindKind(),
6414 C->getProcBindKindKwLoc(),
6415 C->getLocStart(),
6416 C->getLParenLoc(),
6417 C->getLocEnd());
6418}
6419
6420template<typename Derived>
6421OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006422TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00006423 llvm::SmallVector<Expr *, 16> Vars;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006424 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00006425 for (auto *VE : C->varlists()) {
6426 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006427 if (EVar.isInvalid())
6428 return 0;
6429 Vars.push_back(EVar.take());
6430 }
6431 return getDerived().RebuildOMPPrivateClause(Vars,
6432 C->getLocStart(),
6433 C->getLParenLoc(),
6434 C->getLocEnd());
6435}
6436
Alexey Bataev758e55e2013-09-06 18:03:48 +00006437template<typename Derived>
6438OMPClause *
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006439TreeTransform<Derived>::TransformOMPFirstprivateClause(
6440 OMPFirstprivateClause *C) {
6441 llvm::SmallVector<Expr *, 16> Vars;
6442 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00006443 for (auto *VE : C->varlists()) {
6444 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006445 if (EVar.isInvalid())
6446 return 0;
6447 Vars.push_back(EVar.take());
6448 }
6449 return getDerived().RebuildOMPFirstprivateClause(Vars,
6450 C->getLocStart(),
6451 C->getLParenLoc(),
6452 C->getLocEnd());
6453}
6454
6455template<typename Derived>
6456OMPClause *
Alexey Bataev758e55e2013-09-06 18:03:48 +00006457TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
6458 llvm::SmallVector<Expr *, 16> Vars;
6459 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00006460 for (auto *VE : C->varlists()) {
6461 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev758e55e2013-09-06 18:03:48 +00006462 if (EVar.isInvalid())
6463 return 0;
6464 Vars.push_back(EVar.take());
6465 }
6466 return getDerived().RebuildOMPSharedClause(Vars,
6467 C->getLocStart(),
6468 C->getLParenLoc(),
6469 C->getLocEnd());
6470}
6471
Alexey Bataevd48bcd82014-03-31 03:36:38 +00006472template<typename Derived>
6473OMPClause *
Alexander Musman8dba6642014-04-22 13:09:42 +00006474TreeTransform<Derived>::TransformOMPLinearClause(OMPLinearClause *C) {
6475 llvm::SmallVector<Expr *, 16> Vars;
6476 Vars.reserve(C->varlist_size());
6477 for (auto *VE : C->varlists()) {
6478 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
6479 if (EVar.isInvalid())
6480 return 0;
6481 Vars.push_back(EVar.take());
6482 }
6483 ExprResult Step = getDerived().TransformExpr(C->getStep());
6484 if (Step.isInvalid())
6485 return 0;
6486 return getDerived().RebuildOMPLinearClause(
6487 Vars, Step.take(), C->getLocStart(), C->getLParenLoc(), C->getColonLoc(),
6488 C->getLocEnd());
6489}
6490
6491template<typename Derived>
6492OMPClause *
Alexey Bataevd48bcd82014-03-31 03:36:38 +00006493TreeTransform<Derived>::TransformOMPCopyinClause(OMPCopyinClause *C) {
6494 llvm::SmallVector<Expr *, 16> Vars;
6495 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00006496 for (auto *VE : C->varlists()) {
6497 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd48bcd82014-03-31 03:36:38 +00006498 if (EVar.isInvalid())
6499 return 0;
6500 Vars.push_back(EVar.take());
6501 }
6502 return getDerived().RebuildOMPCopyinClause(Vars,
6503 C->getLocStart(),
6504 C->getLParenLoc(),
6505 C->getLocEnd());
6506}
6507
Douglas Gregorebe10102009-08-20 07:17:43 +00006508//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00006509// Expression transformation
6510//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00006511template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006512ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006513TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006514 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006515}
Mike Stump11289f42009-09-09 15:08:12 +00006516
6517template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006518ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006519TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregorea972d32011-02-28 21:54:11 +00006520 NestedNameSpecifierLoc QualifierLoc;
6521 if (E->getQualifierLoc()) {
6522 QualifierLoc
6523 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6524 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00006525 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00006526 }
John McCallce546572009-12-08 09:08:17 +00006527
6528 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006529 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6530 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006531 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00006532 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006533
John McCall815039a2010-08-17 21:27:17 +00006534 DeclarationNameInfo NameInfo = E->getNameInfo();
6535 if (NameInfo.getName()) {
6536 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6537 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00006538 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00006539 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006540
6541 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00006542 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00006543 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006544 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00006545 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00006546
6547 // Mark it referenced in the new context regardless.
6548 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00006549 SemaRef.MarkDeclRefReferenced(E);
John McCallce546572009-12-08 09:08:17 +00006550
John McCallc3007a22010-10-26 07:05:15 +00006551 return SemaRef.Owned(E);
Douglas Gregor4bd90e52009-10-23 18:54:35 +00006552 }
John McCallce546572009-12-08 09:08:17 +00006553
6554 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCallb3774b52010-08-19 23:49:38 +00006555 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00006556 TemplateArgs = &TransArgs;
6557 TransArgs.setLAngleLoc(E->getLAngleLoc());
6558 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006559 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6560 E->getNumTemplateArgs(),
6561 TransArgs))
6562 return ExprError();
John McCallce546572009-12-08 09:08:17 +00006563 }
6564
Chad Rosier1dcde962012-08-08 18:46:20 +00006565 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregorea972d32011-02-28 21:54:11 +00006566 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00006567}
Mike Stump11289f42009-09-09 15:08:12 +00006568
Douglas Gregora16548e2009-08-11 05:31:07 +00006569template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006570ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006571TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00006572 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006573}
Mike Stump11289f42009-09-09 15:08:12 +00006574
Douglas Gregora16548e2009-08-11 05:31:07 +00006575template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006576ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006577TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00006578 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006579}
Mike Stump11289f42009-09-09 15:08:12 +00006580
Douglas Gregora16548e2009-08-11 05:31:07 +00006581template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006582ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006583TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00006584 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006585}
Mike Stump11289f42009-09-09 15:08:12 +00006586
Douglas Gregora16548e2009-08-11 05:31:07 +00006587template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006588ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006589TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00006590 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006591}
Mike Stump11289f42009-09-09 15:08:12 +00006592
Douglas Gregora16548e2009-08-11 05:31:07 +00006593template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006594ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006595TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00006596 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006597}
6598
6599template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006600ExprResult
Richard Smithc67fdd42012-03-07 08:35:16 +00006601TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
Argyrios Kyrtzidis25049092013-04-09 01:17:02 +00006602 if (FunctionDecl *FD = E->getDirectCallee())
6603 SemaRef.MarkFunctionReferenced(E->getLocStart(), FD);
Richard Smithc67fdd42012-03-07 08:35:16 +00006604 return SemaRef.MaybeBindToTemporary(E);
6605}
6606
6607template<typename Derived>
6608ExprResult
Peter Collingbourne91147592011-04-15 00:35:48 +00006609TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
6610 ExprResult ControllingExpr =
6611 getDerived().TransformExpr(E->getControllingExpr());
6612 if (ControllingExpr.isInvalid())
6613 return ExprError();
6614
Chris Lattner01cf8db2011-07-20 06:58:45 +00006615 SmallVector<Expr *, 4> AssocExprs;
6616 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbourne91147592011-04-15 00:35:48 +00006617 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
6618 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
6619 if (TS) {
6620 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
6621 if (!AssocType)
6622 return ExprError();
6623 AssocTypes.push_back(AssocType);
6624 } else {
6625 AssocTypes.push_back(0);
6626 }
6627
6628 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
6629 if (AssocExpr.isInvalid())
6630 return ExprError();
6631 AssocExprs.push_back(AssocExpr.release());
6632 }
6633
6634 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
6635 E->getDefaultLoc(),
6636 E->getRParenLoc(),
6637 ControllingExpr.release(),
Dmitri Gribenko82360372013-05-10 13:06:58 +00006638 AssocTypes,
6639 AssocExprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00006640}
6641
6642template<typename Derived>
6643ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006644TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006645 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006646 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006647 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006648
Douglas Gregora16548e2009-08-11 05:31:07 +00006649 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006650 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006651
John McCallb268a282010-08-23 23:25:46 +00006652 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006653 E->getRParen());
6654}
6655
Richard Smithdb2630f2012-10-21 03:28:35 +00006656/// \brief The operand of a unary address-of operator has special rules: it's
6657/// allowed to refer to a non-static member of a class even if there's no 'this'
6658/// object available.
6659template<typename Derived>
6660ExprResult
6661TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
6662 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
6663 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true);
6664 else
6665 return getDerived().TransformExpr(E);
6666}
6667
Mike Stump11289f42009-09-09 15:08:12 +00006668template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006669ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006670TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smitheebe125f2013-05-21 23:29:46 +00006671 ExprResult SubExpr;
6672 if (E->getOpcode() == UO_AddrOf)
6673 SubExpr = TransformAddressOfOperand(E->getSubExpr());
6674 else
6675 SubExpr = TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006676 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006677 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006678
Douglas Gregora16548e2009-08-11 05:31:07 +00006679 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006680 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006681
Douglas Gregora16548e2009-08-11 05:31:07 +00006682 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
6683 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00006684 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006685}
Mike Stump11289f42009-09-09 15:08:12 +00006686
Douglas Gregora16548e2009-08-11 05:31:07 +00006687template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006688ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00006689TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
6690 // Transform the type.
6691 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
6692 if (!Type)
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 // Transform all of the components into components similar to what the
6696 // parser uses.
Chad Rosier1dcde962012-08-08 18:46:20 +00006697 // FIXME: It would be slightly more efficient in the non-dependent case to
6698 // just map FieldDecls, rather than requiring the rebuilder to look for
6699 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00006700 // template code that we don't care.
6701 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00006702 typedef Sema::OffsetOfComponent Component;
Douglas Gregor882211c2010-04-28 22:16:22 +00006703 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner01cf8db2011-07-20 06:58:45 +00006704 SmallVector<Component, 4> Components;
Douglas Gregor882211c2010-04-28 22:16:22 +00006705 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
6706 const Node &ON = E->getComponent(I);
6707 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00006708 Comp.isBrackets = true;
Abramo Bagnara6b6f0512011-03-12 09:45:03 +00006709 Comp.LocStart = ON.getSourceRange().getBegin();
6710 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor882211c2010-04-28 22:16:22 +00006711 switch (ON.getKind()) {
6712 case Node::Array: {
6713 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00006714 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00006715 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006716 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006717
Douglas Gregor882211c2010-04-28 22:16:22 +00006718 ExprChanged = ExprChanged || Index.get() != FromIndex;
6719 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00006720 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00006721 break;
6722 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006723
Douglas Gregor882211c2010-04-28 22:16:22 +00006724 case Node::Field:
6725 case Node::Identifier:
6726 Comp.isBrackets = false;
6727 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00006728 if (!Comp.U.IdentInfo)
6729 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00006730
Douglas Gregor882211c2010-04-28 22:16:22 +00006731 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006732
Douglas Gregord1702062010-04-29 00:18:15 +00006733 case Node::Base:
6734 // Will be recomputed during the rebuild.
6735 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00006736 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006737
Douglas Gregor882211c2010-04-28 22:16:22 +00006738 Components.push_back(Comp);
6739 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006740
Douglas Gregor882211c2010-04-28 22:16:22 +00006741 // If nothing changed, retain the existing expression.
6742 if (!getDerived().AlwaysRebuild() &&
6743 Type == E->getTypeSourceInfo() &&
6744 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00006745 return SemaRef.Owned(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00006746
Douglas Gregor882211c2010-04-28 22:16:22 +00006747 // Build a new offsetof expression.
6748 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
6749 Components.data(), Components.size(),
6750 E->getRParenLoc());
6751}
6752
6753template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006754ExprResult
John McCall8d69a212010-11-15 23:31:06 +00006755TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
6756 assert(getDerived().AlreadyTransformed(E->getType()) &&
6757 "opaque value expression requires transformation");
6758 return SemaRef.Owned(E);
6759}
6760
6761template<typename Derived>
6762ExprResult
John McCallfe96e0b2011-11-06 09:01:30 +00006763TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCalle9290822011-11-30 04:42:31 +00006764 // Rebuild the syntactic form. The original syntactic form has
6765 // opaque-value expressions in it, so strip those away and rebuild
6766 // the result. This is a really awful way of doing this, but the
6767 // better solution (rebuilding the semantic expressions and
6768 // rebinding OVEs as necessary) doesn't work; we'd need
6769 // TreeTransform to not strip away implicit conversions.
6770 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
6771 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCallfe96e0b2011-11-06 09:01:30 +00006772 if (result.isInvalid()) return ExprError();
6773
6774 // If that gives us a pseudo-object result back, the pseudo-object
6775 // expression must have been an lvalue-to-rvalue conversion which we
6776 // should reapply.
6777 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
6778 result = SemaRef.checkPseudoObjectRValue(result.take());
6779
6780 return result;
6781}
6782
6783template<typename Derived>
6784ExprResult
Peter Collingbournee190dee2011-03-11 19:24:49 +00006785TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
6786 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006787 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00006788 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00006789
John McCallbcd03502009-12-07 02:54:59 +00006790 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00006791 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00006792 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006793
John McCall4c98fd82009-11-04 07:28:41 +00006794 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCallc3007a22010-10-26 07:05:15 +00006795 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006796
Peter Collingbournee190dee2011-03-11 19:24:49 +00006797 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
6798 E->getKind(),
6799 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00006800 }
Mike Stump11289f42009-09-09 15:08:12 +00006801
Eli Friedmane4f22df2012-02-29 04:03:55 +00006802 // C++0x [expr.sizeof]p1:
6803 // The operand is either an expression, which is an unevaluated operand
6804 // [...]
Eli Friedman15681d62012-09-26 04:34:21 +00006805 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
6806 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00006807
Eli Friedmane4f22df2012-02-29 04:03:55 +00006808 ExprResult SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
6809 if (SubExpr.isInvalid())
6810 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006811
Eli Friedmane4f22df2012-02-29 04:03:55 +00006812 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
6813 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006814
Peter Collingbournee190dee2011-03-11 19:24:49 +00006815 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
6816 E->getOperatorLoc(),
6817 E->getKind(),
6818 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00006819}
Mike Stump11289f42009-09-09 15:08:12 +00006820
Douglas Gregora16548e2009-08-11 05:31:07 +00006821template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006822ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006823TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006824 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006825 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006826 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006827
John McCalldadc5752010-08-24 06:29:42 +00006828 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006829 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006830 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006831
6832
Douglas Gregora16548e2009-08-11 05:31:07 +00006833 if (!getDerived().AlwaysRebuild() &&
6834 LHS.get() == E->getLHS() &&
6835 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00006836 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006837
John McCallb268a282010-08-23 23:25:46 +00006838 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006839 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00006840 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006841 E->getRBracketLoc());
6842}
Mike Stump11289f42009-09-09 15:08:12 +00006843
6844template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006845ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006846TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006847 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00006848 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00006849 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006850 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006851
6852 // Transform arguments.
6853 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006854 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00006855 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00006856 &ArgChanged))
6857 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006858
Douglas Gregora16548e2009-08-11 05:31:07 +00006859 if (!getDerived().AlwaysRebuild() &&
6860 Callee.get() == E->getCallee() &&
6861 !ArgChanged)
Dmitri Gribenko76bb5cabfa2012-09-10 21:20:09 +00006862 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00006863
Douglas Gregora16548e2009-08-11 05:31:07 +00006864 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00006865 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00006866 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00006867 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006868 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00006869 E->getRParenLoc());
6870}
Mike Stump11289f42009-09-09 15:08:12 +00006871
6872template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006873ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006874TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006875 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00006876 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006877 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006878
Douglas Gregorea972d32011-02-28 21:54:11 +00006879 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorf405d7e2009-08-31 23:41:50 +00006880 if (E->hasQualifier()) {
Douglas Gregorea972d32011-02-28 21:54:11 +00006881 QualifierLoc
6882 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00006883
Douglas Gregorea972d32011-02-28 21:54:11 +00006884 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00006885 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00006886 }
Abramo Bagnara7945c982012-01-27 09:46:47 +00006887 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00006888
Eli Friedman2cfcef62009-12-04 06:40:45 +00006889 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006890 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
6891 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006892 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00006893 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006894
John McCall16df1e52010-03-30 21:47:33 +00006895 NamedDecl *FoundDecl = E->getFoundDecl();
6896 if (FoundDecl == E->getMemberDecl()) {
6897 FoundDecl = Member;
6898 } else {
6899 FoundDecl = cast_or_null<NamedDecl>(
6900 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
6901 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00006902 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00006903 }
6904
Douglas Gregora16548e2009-08-11 05:31:07 +00006905 if (!getDerived().AlwaysRebuild() &&
6906 Base.get() == E->getBase() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00006907 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00006908 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00006909 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00006910 !E->hasExplicitTemplateArgs()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006911
Anders Carlsson9c45ad72009-12-22 05:24:09 +00006912 // Mark it referenced in the new context regardless.
6913 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00006914 SemaRef.MarkMemberReferenced(E);
6915
John McCallc3007a22010-10-26 07:05:15 +00006916 return SemaRef.Owned(E);
Anders Carlsson9c45ad72009-12-22 05:24:09 +00006917 }
Douglas Gregora16548e2009-08-11 05:31:07 +00006918
John McCall6b51f282009-11-23 01:53:49 +00006919 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00006920 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00006921 TransArgs.setLAngleLoc(E->getLAngleLoc());
6922 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006923 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6924 E->getNumTemplateArgs(),
6925 TransArgs))
6926 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00006927 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006928
Douglas Gregora16548e2009-08-11 05:31:07 +00006929 // FIXME: Bogus source location for the operator
Alp Tokerb6cc5922014-05-03 03:45:55 +00006930 SourceLocation FakeOperatorLoc =
6931 SemaRef.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00006932
John McCall38836f02010-01-15 08:34:02 +00006933 // FIXME: to do this check properly, we will need to preserve the
6934 // first-qualifier-in-scope here, just in case we had a dependent
6935 // base (and therefore couldn't do the check) and a
6936 // nested-name-qualifier (and therefore could do the lookup).
6937 NamedDecl *FirstQualifierInScope = 0;
6938
John McCallb268a282010-08-23 23:25:46 +00006939 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00006940 E->isArrow(),
Douglas Gregorea972d32011-02-28 21:54:11 +00006941 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00006942 TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006943 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00006944 Member,
John McCall16df1e52010-03-30 21:47:33 +00006945 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00006946 (E->hasExplicitTemplateArgs()
John McCall6b51f282009-11-23 01:53:49 +00006947 ? &TransArgs : 0),
John McCall38836f02010-01-15 08:34:02 +00006948 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00006949}
Mike Stump11289f42009-09-09 15:08:12 +00006950
Douglas Gregora16548e2009-08-11 05:31:07 +00006951template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006952ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006953TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00006954 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006955 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006956 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006957
John McCalldadc5752010-08-24 06:29:42 +00006958 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006959 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006960 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006961
Douglas Gregora16548e2009-08-11 05:31:07 +00006962 if (!getDerived().AlwaysRebuild() &&
6963 LHS.get() == E->getLHS() &&
6964 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00006965 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006966
Lang Hames5de91cc2012-10-02 04:45:10 +00006967 Sema::FPContractStateRAII FPContractState(getSema());
6968 getSema().FPFeatures.fp_contract = E->isFPContractable();
6969
Douglas Gregora16548e2009-08-11 05:31:07 +00006970 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00006971 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006972}
6973
Mike Stump11289f42009-09-09 15:08:12 +00006974template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006975ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006976TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00006977 CompoundAssignOperator *E) {
6978 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006979}
Mike Stump11289f42009-09-09 15:08:12 +00006980
Douglas Gregora16548e2009-08-11 05:31:07 +00006981template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00006982ExprResult TreeTransform<Derived>::
6983TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
6984 // Just rebuild the common and RHS expressions and see whether we
6985 // get any changes.
6986
6987 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
6988 if (commonExpr.isInvalid())
6989 return ExprError();
6990
6991 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
6992 if (rhs.isInvalid())
6993 return ExprError();
6994
6995 if (!getDerived().AlwaysRebuild() &&
6996 commonExpr.get() == e->getCommon() &&
6997 rhs.get() == e->getFalseExpr())
6998 return SemaRef.Owned(e);
6999
7000 return getDerived().RebuildConditionalOperator(commonExpr.take(),
7001 e->getQuestionLoc(),
7002 0,
7003 e->getColonLoc(),
7004 rhs.get());
7005}
7006
7007template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007008ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007009TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00007010 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00007011 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007012 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007013
John McCalldadc5752010-08-24 06:29:42 +00007014 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007015 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007016 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007017
John McCalldadc5752010-08-24 06:29:42 +00007018 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007019 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007020 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007021
Douglas Gregora16548e2009-08-11 05:31:07 +00007022 if (!getDerived().AlwaysRebuild() &&
7023 Cond.get() == E->getCond() &&
7024 LHS.get() == E->getLHS() &&
7025 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00007026 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007027
John McCallb268a282010-08-23 23:25:46 +00007028 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00007029 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00007030 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00007031 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00007032 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007033}
Mike Stump11289f42009-09-09 15:08:12 +00007034
7035template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007036ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007037TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00007038 // Implicit casts are eliminated during transformation, since they
7039 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00007040 return getDerived().TransformExpr(E->getSubExprAsWritten());
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>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007046 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7047 if (!Type)
7048 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007049
John McCalldadc5752010-08-24 06:29:42 +00007050 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00007051 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007052 if (SubExpr.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() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007056 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007057 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00007058 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007059
John McCall97513962010-01-15 18:39:57 +00007060 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007061 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00007062 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007063 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007064}
Mike Stump11289f42009-09-09 15:08:12 +00007065
Douglas Gregora16548e2009-08-11 05:31:07 +00007066template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007067ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007068TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00007069 TypeSourceInfo *OldT = E->getTypeSourceInfo();
7070 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
7071 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00007072 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007073
John McCalldadc5752010-08-24 06:29:42 +00007074 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00007075 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007076 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007077
Douglas Gregora16548e2009-08-11 05:31:07 +00007078 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00007079 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007080 Init.get() == E->getInitializer())
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007081 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007082
John McCall5d7aa7f2010-01-19 22:33:45 +00007083 // Note: the expression type doesn't necessarily match the
7084 // type-as-written, but that's okay, because it should always be
7085 // derivable from the initializer.
7086
John McCalle15bbff2010-01-18 19:35:47 +00007087 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00007088 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00007089 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007090}
Mike Stump11289f42009-09-09 15:08:12 +00007091
Douglas Gregora16548e2009-08-11 05:31:07 +00007092template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007093ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007094TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007095 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00007096 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007097 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007098
Douglas Gregora16548e2009-08-11 05:31:07 +00007099 if (!getDerived().AlwaysRebuild() &&
7100 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007101 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007102
Douglas Gregora16548e2009-08-11 05:31:07 +00007103 // FIXME: Bad source location
Alp Tokerb6cc5922014-05-03 03:45:55 +00007104 SourceLocation FakeOperatorLoc =
7105 SemaRef.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00007106 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00007107 E->getAccessorLoc(),
7108 E->getAccessor());
7109}
Mike Stump11289f42009-09-09 15:08:12 +00007110
Douglas Gregora16548e2009-08-11 05:31:07 +00007111template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007112ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007113TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007114 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00007115
Benjamin Kramerf0623432012-08-23 22:51:59 +00007116 SmallVector<Expr*, 4> Inits;
Chad Rosier1dcde962012-08-08 18:46:20 +00007117 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00007118 Inits, &InitChanged))
7119 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007120
Douglas Gregora16548e2009-08-11 05:31:07 +00007121 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCallc3007a22010-10-26 07:05:15 +00007122 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007123
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007124 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00007125 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00007126}
Mike Stump11289f42009-09-09 15:08:12 +00007127
Douglas Gregora16548e2009-08-11 05:31:07 +00007128template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007129ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007130TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007131 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00007132
Douglas Gregorebe10102009-08-20 07:17:43 +00007133 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00007134 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00007135 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007136 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007137
Douglas Gregorebe10102009-08-20 07:17:43 +00007138 // transform the designators.
Benjamin Kramerf0623432012-08-23 22:51:59 +00007139 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregora16548e2009-08-11 05:31:07 +00007140 bool ExprChanged = false;
7141 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
7142 DEnd = E->designators_end();
7143 D != DEnd; ++D) {
7144 if (D->isFieldDesignator()) {
7145 Desig.AddDesignator(Designator::getField(D->getFieldName(),
7146 D->getDotLoc(),
7147 D->getFieldLoc()));
7148 continue;
7149 }
Mike Stump11289f42009-09-09 15:08:12 +00007150
Douglas Gregora16548e2009-08-11 05:31:07 +00007151 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00007152 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00007153 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007154 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007155
7156 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007157 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00007158
Douglas Gregora16548e2009-08-11 05:31:07 +00007159 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
7160 ArrayExprs.push_back(Index.release());
7161 continue;
7162 }
Mike Stump11289f42009-09-09 15:08:12 +00007163
Douglas Gregora16548e2009-08-11 05:31:07 +00007164 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00007165 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00007166 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
7167 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007168 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007169
John McCalldadc5752010-08-24 06:29:42 +00007170 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00007171 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007172 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007173
7174 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007175 End.get(),
7176 D->getLBracketLoc(),
7177 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00007178
Douglas Gregora16548e2009-08-11 05:31:07 +00007179 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
7180 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00007181
Douglas Gregora16548e2009-08-11 05:31:07 +00007182 ArrayExprs.push_back(Start.release());
7183 ArrayExprs.push_back(End.release());
7184 }
Mike Stump11289f42009-09-09 15:08:12 +00007185
Douglas Gregora16548e2009-08-11 05:31:07 +00007186 if (!getDerived().AlwaysRebuild() &&
7187 Init.get() == E->getInit() &&
7188 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00007189 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007190
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007191 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00007192 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00007193 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007194}
Mike Stump11289f42009-09-09 15:08:12 +00007195
Douglas Gregora16548e2009-08-11 05:31:07 +00007196template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007197ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007198TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007199 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00007200 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier1dcde962012-08-08 18:46:20 +00007201
Douglas Gregor3da3c062009-10-28 00:29:27 +00007202 // FIXME: Will we ever have proper type location here? Will we actually
7203 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00007204 QualType T = getDerived().TransformType(E->getType());
7205 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00007206 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007207
Douglas Gregora16548e2009-08-11 05:31:07 +00007208 if (!getDerived().AlwaysRebuild() &&
7209 T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00007210 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007211
Douglas Gregora16548e2009-08-11 05:31:07 +00007212 return getDerived().RebuildImplicitValueInitExpr(T);
7213}
Mike Stump11289f42009-09-09 15:08:12 +00007214
Douglas Gregora16548e2009-08-11 05:31:07 +00007215template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007216ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007217TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00007218 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
7219 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007220 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007221
John McCalldadc5752010-08-24 06:29:42 +00007222 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007223 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007224 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007225
Douglas Gregora16548e2009-08-11 05:31:07 +00007226 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00007227 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007228 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00007229 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007230
John McCallb268a282010-08-23 23:25:46 +00007231 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00007232 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007233}
7234
7235template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007236ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007237TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007238 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007239 SmallVector<Expr*, 4> Inits;
Douglas Gregora3efea12011-01-03 19:04:46 +00007240 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
7241 &ArgumentChanged))
7242 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007243
Douglas Gregora16548e2009-08-11 05:31:07 +00007244 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007245 Inits,
Douglas Gregora16548e2009-08-11 05:31:07 +00007246 E->getRParenLoc());
7247}
Mike Stump11289f42009-09-09 15:08:12 +00007248
Douglas Gregora16548e2009-08-11 05:31:07 +00007249/// \brief Transform an address-of-label expression.
7250///
7251/// By default, the transformation of an address-of-label expression always
7252/// rebuilds the expression, so that the label identifier can be resolved to
7253/// the corresponding label statement by semantic analysis.
7254template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007255ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007256TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +00007257 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
7258 E->getLabel());
7259 if (!LD)
7260 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007261
Douglas Gregora16548e2009-08-11 05:31:07 +00007262 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00007263 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +00007264}
Mike Stump11289f42009-09-09 15:08:12 +00007265
7266template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00007267ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007268TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalled7b2782012-04-06 18:20:53 +00007269 SemaRef.ActOnStartStmtExpr();
John McCalldadc5752010-08-24 06:29:42 +00007270 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00007271 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCalled7b2782012-04-06 18:20:53 +00007272 if (SubStmt.isInvalid()) {
7273 SemaRef.ActOnStmtExprError();
John McCallfaf5fb42010-08-26 23:41:50 +00007274 return ExprError();
John McCalled7b2782012-04-06 18:20:53 +00007275 }
Mike Stump11289f42009-09-09 15:08:12 +00007276
Douglas Gregora16548e2009-08-11 05:31:07 +00007277 if (!getDerived().AlwaysRebuild() &&
John McCalled7b2782012-04-06 18:20:53 +00007278 SubStmt.get() == E->getSubStmt()) {
7279 // Calling this an 'error' is unintuitive, but it does the right thing.
7280 SemaRef.ActOnStmtExprError();
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007281 return SemaRef.MaybeBindToTemporary(E);
John McCalled7b2782012-04-06 18:20:53 +00007282 }
Mike Stump11289f42009-09-09 15:08:12 +00007283
7284 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007285 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007286 E->getRParenLoc());
7287}
Mike Stump11289f42009-09-09 15:08:12 +00007288
Douglas Gregora16548e2009-08-11 05:31:07 +00007289template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007290ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007291TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007292 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00007293 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007294 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007295
John McCalldadc5752010-08-24 06:29:42 +00007296 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007297 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007298 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007299
John McCalldadc5752010-08-24 06:29:42 +00007300 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007301 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007302 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007303
Douglas Gregora16548e2009-08-11 05:31:07 +00007304 if (!getDerived().AlwaysRebuild() &&
7305 Cond.get() == E->getCond() &&
7306 LHS.get() == E->getLHS() &&
7307 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00007308 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007309
Douglas Gregora16548e2009-08-11 05:31:07 +00007310 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00007311 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007312 E->getRParenLoc());
7313}
Mike Stump11289f42009-09-09 15:08:12 +00007314
Douglas Gregora16548e2009-08-11 05:31:07 +00007315template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007316ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007317TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007318 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007319}
7320
7321template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007322ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007323TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007324 switch (E->getOperator()) {
7325 case OO_New:
7326 case OO_Delete:
7327 case OO_Array_New:
7328 case OO_Array_Delete:
7329 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier1dcde962012-08-08 18:46:20 +00007330
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007331 case OO_Call: {
7332 // This is a call to an object's operator().
7333 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
7334
7335 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00007336 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007337 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007338 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007339
7340 // FIXME: Poor location information
Alp Tokerb6cc5922014-05-03 03:45:55 +00007341 SourceLocation FakeLParenLoc = SemaRef.getLocForEndOfToken(
7342 static_cast<Expr *>(Object.get())->getLocEnd());
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007343
7344 // Transform the call arguments.
Benjamin Kramerf0623432012-08-23 22:51:59 +00007345 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00007346 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregora3efea12011-01-03 19:04:46 +00007347 Args))
7348 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007349
John McCallb268a282010-08-23 23:25:46 +00007350 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007351 Args,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007352 E->getLocEnd());
7353 }
7354
7355#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
7356 case OO_##Name:
7357#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
7358#include "clang/Basic/OperatorKinds.def"
7359 case OO_Subscript:
7360 // Handled below.
7361 break;
7362
7363 case OO_Conditional:
7364 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007365
7366 case OO_None:
7367 case NUM_OVERLOADED_OPERATORS:
7368 llvm_unreachable("not an overloaded operator?");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007369 }
7370
John McCalldadc5752010-08-24 06:29:42 +00007371 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00007372 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007373 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007374
Richard Smithdb2630f2012-10-21 03:28:35 +00007375 ExprResult First;
7376 if (E->getOperator() == OO_Amp)
7377 First = getDerived().TransformAddressOfOperand(E->getArg(0));
7378 else
7379 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00007380 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007381 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007382
John McCalldadc5752010-08-24 06:29:42 +00007383 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00007384 if (E->getNumArgs() == 2) {
7385 Second = getDerived().TransformExpr(E->getArg(1));
7386 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007387 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007388 }
Mike Stump11289f42009-09-09 15:08:12 +00007389
Douglas Gregora16548e2009-08-11 05:31:07 +00007390 if (!getDerived().AlwaysRebuild() &&
7391 Callee.get() == E->getCallee() &&
7392 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00007393 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007394 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00007395
Lang Hames5de91cc2012-10-02 04:45:10 +00007396 Sema::FPContractStateRAII FPContractState(getSema());
7397 getSema().FPFeatures.fp_contract = E->isFPContractable();
7398
Douglas Gregora16548e2009-08-11 05:31:07 +00007399 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
7400 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00007401 Callee.get(),
7402 First.get(),
7403 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007404}
Mike Stump11289f42009-09-09 15:08:12 +00007405
Douglas Gregora16548e2009-08-11 05:31:07 +00007406template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007407ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007408TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
7409 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007410}
Mike Stump11289f42009-09-09 15:08:12 +00007411
Douglas Gregora16548e2009-08-11 05:31:07 +00007412template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007413ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +00007414TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
7415 // Transform the callee.
7416 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
7417 if (Callee.isInvalid())
7418 return ExprError();
7419
7420 // Transform exec config.
7421 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
7422 if (EC.isInvalid())
7423 return ExprError();
7424
7425 // Transform arguments.
7426 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007427 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00007428 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00007429 &ArgChanged))
7430 return ExprError();
7431
7432 if (!getDerived().AlwaysRebuild() &&
7433 Callee.get() == E->getCallee() &&
7434 !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007435 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbourne41f85462011-02-09 21:07:24 +00007436
7437 // FIXME: Wrong source location information for the '('.
7438 SourceLocation FakeLParenLoc
7439 = ((Expr *)Callee.get())->getSourceRange().getBegin();
7440 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007441 Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00007442 E->getRParenLoc(), EC.get());
7443}
7444
7445template<typename Derived>
7446ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007447TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007448 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7449 if (!Type)
7450 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007451
John McCalldadc5752010-08-24 06:29:42 +00007452 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00007453 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007454 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007455 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007456
Douglas Gregora16548e2009-08-11 05:31:07 +00007457 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007458 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007459 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00007460 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007461 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00007462 E->getStmtClass(),
Fariborz Jahanianf0738712013-02-22 22:02:53 +00007463 E->getAngleBrackets().getBegin(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007464 Type,
Fariborz Jahanianf0738712013-02-22 22:02:53 +00007465 E->getAngleBrackets().getEnd(),
7466 // FIXME. this should be '(' location
7467 E->getAngleBrackets().getEnd(),
John McCallb268a282010-08-23 23:25:46 +00007468 SubExpr.get(),
Abramo Bagnara9fb43862012-10-15 21:08:58 +00007469 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007470}
Mike Stump11289f42009-09-09 15:08:12 +00007471
Douglas Gregora16548e2009-08-11 05:31:07 +00007472template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007473ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007474TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
7475 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007476}
Mike Stump11289f42009-09-09 15:08:12 +00007477
7478template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007479ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007480TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
7481 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00007482}
7483
Douglas Gregora16548e2009-08-11 05:31:07 +00007484template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007485ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007486TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007487 CXXReinterpretCastExpr *E) {
7488 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007489}
Mike Stump11289f42009-09-09 15:08:12 +00007490
Douglas Gregora16548e2009-08-11 05:31:07 +00007491template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007492ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007493TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
7494 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007495}
Mike Stump11289f42009-09-09 15:08:12 +00007496
Douglas Gregora16548e2009-08-11 05:31:07 +00007497template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007498ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007499TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007500 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007501 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7502 if (!Type)
7503 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007504
John McCalldadc5752010-08-24 06:29:42 +00007505 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00007506 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007507 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007508 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007509
Douglas Gregora16548e2009-08-11 05:31:07 +00007510 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007511 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007512 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00007513 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007514
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007515 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Eli Friedman89fe0d52013-08-15 22:02:56 +00007516 E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007517 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007518 E->getRParenLoc());
7519}
Mike Stump11289f42009-09-09 15:08:12 +00007520
Douglas Gregora16548e2009-08-11 05:31:07 +00007521template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007522ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007523TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007524 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00007525 TypeSourceInfo *TInfo
7526 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7527 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007528 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007529
Douglas Gregora16548e2009-08-11 05:31:07 +00007530 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00007531 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00007532 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007533
Douglas Gregor9da64192010-04-26 22:37:10 +00007534 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7535 E->getLocStart(),
7536 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00007537 E->getLocEnd());
7538 }
Mike Stump11289f42009-09-09 15:08:12 +00007539
Eli Friedman456f0182012-01-20 01:26:23 +00007540 // We don't know whether the subexpression is potentially evaluated until
7541 // after we perform semantic analysis. We speculatively assume it is
7542 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregora16548e2009-08-11 05:31:07 +00007543 // potentially evaluated.
Eli Friedman15681d62012-09-26 04:34:21 +00007544 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
7545 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00007546
John McCalldadc5752010-08-24 06:29:42 +00007547 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00007548 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007549 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007550
Douglas Gregora16548e2009-08-11 05:31:07 +00007551 if (!getDerived().AlwaysRebuild() &&
7552 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00007553 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007554
Douglas Gregor9da64192010-04-26 22:37:10 +00007555 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7556 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00007557 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007558 E->getLocEnd());
7559}
7560
7561template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007562ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00007563TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
7564 if (E->isTypeOperand()) {
7565 TypeSourceInfo *TInfo
7566 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7567 if (!TInfo)
7568 return ExprError();
7569
7570 if (!getDerived().AlwaysRebuild() &&
7571 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00007572 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00007573
Douglas Gregor69735112011-03-06 17:40:41 +00007574 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet9f4f2072010-09-08 12:20:18 +00007575 E->getLocStart(),
7576 TInfo,
7577 E->getLocEnd());
7578 }
7579
Francois Pichet9f4f2072010-09-08 12:20:18 +00007580 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7581
7582 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
7583 if (SubExpr.isInvalid())
7584 return ExprError();
7585
7586 if (!getDerived().AlwaysRebuild() &&
7587 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00007588 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00007589
7590 return getDerived().RebuildCXXUuidofExpr(E->getType(),
7591 E->getLocStart(),
7592 SubExpr.get(),
7593 E->getLocEnd());
7594}
7595
7596template<typename Derived>
7597ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007598TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007599 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007600}
Mike Stump11289f42009-09-09 15:08:12 +00007601
Douglas Gregora16548e2009-08-11 05:31:07 +00007602template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007603ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007604TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007605 CXXNullPtrLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007606 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007607}
Mike Stump11289f42009-09-09 15:08:12 +00007608
Douglas Gregora16548e2009-08-11 05:31:07 +00007609template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007610ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007611TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Richard Smithc3d2ebb2013-06-07 02:33:37 +00007612 QualType T = getSema().getCurrentThisType();
Mike Stump11289f42009-09-09 15:08:12 +00007613
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00007614 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
7615 // Make sure that we capture 'this'.
7616 getSema().CheckCXXThisCapture(E->getLocStart());
John McCallc3007a22010-10-26 07:05:15 +00007617 return SemaRef.Owned(E);
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00007618 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007619
Douglas Gregorb15af892010-01-07 23:12:05 +00007620 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00007621}
Mike Stump11289f42009-09-09 15:08:12 +00007622
Douglas Gregora16548e2009-08-11 05:31:07 +00007623template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007624ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007625TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007626 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007627 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007628 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007629
Douglas Gregora16548e2009-08-11 05:31:07 +00007630 if (!getDerived().AlwaysRebuild() &&
7631 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00007632 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007633
Douglas Gregor53e191ed2011-07-06 22:04:06 +00007634 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
7635 E->isThrownVariableInScope());
Douglas Gregora16548e2009-08-11 05:31:07 +00007636}
Mike Stump11289f42009-09-09 15:08:12 +00007637
Douglas Gregora16548e2009-08-11 05:31:07 +00007638template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007639ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007640TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00007641 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007642 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
7643 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007644 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00007645 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007646
Chandler Carruth794da4c2010-02-08 06:42:49 +00007647 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007648 Param == E->getParam())
John McCallc3007a22010-10-26 07:05:15 +00007649 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007650
Douglas Gregor033f6752009-12-23 23:03:06 +00007651 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00007652}
Mike Stump11289f42009-09-09 15:08:12 +00007653
Douglas Gregora16548e2009-08-11 05:31:07 +00007654template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007655ExprResult
Richard Smith852c9db2013-04-20 22:23:05 +00007656TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
7657 FieldDecl *Field
7658 = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(),
7659 E->getField()));
7660 if (!Field)
7661 return ExprError();
7662
7663 if (!getDerived().AlwaysRebuild() && Field == E->getField())
7664 return SemaRef.Owned(E);
7665
7666 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
7667}
7668
7669template<typename Derived>
7670ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00007671TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
7672 CXXScalarValueInitExpr *E) {
7673 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7674 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007675 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007676
Douglas Gregora16548e2009-08-11 05:31:07 +00007677 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00007678 T == E->getTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00007679 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007680
Chad Rosier1dcde962012-08-08 18:46:20 +00007681 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregor2b88c112010-09-08 00:15:04 +00007682 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00007683 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007684}
Mike Stump11289f42009-09-09 15:08:12 +00007685
Douglas Gregora16548e2009-08-11 05:31:07 +00007686template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007687ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007688TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007689 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00007690 TypeSourceInfo *AllocTypeInfo
7691 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
7692 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007693 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007694
Douglas Gregora16548e2009-08-11 05:31:07 +00007695 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00007696 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00007697 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007698 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007699
Douglas Gregora16548e2009-08-11 05:31:07 +00007700 // Transform the placement arguments (if any).
7701 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007702 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier1dcde962012-08-08 18:46:20 +00007703 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregora3efea12011-01-03 19:04:46 +00007704 E->getNumPlacementArgs(), true,
7705 PlacementArgs, &ArgumentChanged))
Sebastian Redl6047f072012-02-16 12:22:20 +00007706 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007707
Sebastian Redl6047f072012-02-16 12:22:20 +00007708 // Transform the initializer (if any).
7709 Expr *OldInit = E->getInitializer();
7710 ExprResult NewInit;
7711 if (OldInit)
7712 NewInit = getDerived().TransformExpr(OldInit);
7713 if (NewInit.isInvalid())
7714 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007715
Sebastian Redl6047f072012-02-16 12:22:20 +00007716 // Transform new operator and delete operator.
Douglas Gregord2d9da02010-02-26 00:38:10 +00007717 FunctionDecl *OperatorNew = 0;
7718 if (E->getOperatorNew()) {
7719 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007720 getDerived().TransformDecl(E->getLocStart(),
7721 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00007722 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00007723 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00007724 }
7725
7726 FunctionDecl *OperatorDelete = 0;
7727 if (E->getOperatorDelete()) {
7728 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007729 getDerived().TransformDecl(E->getLocStart(),
7730 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00007731 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00007732 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00007733 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007734
Douglas Gregora16548e2009-08-11 05:31:07 +00007735 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00007736 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007737 ArraySize.get() == E->getArraySize() &&
Sebastian Redl6047f072012-02-16 12:22:20 +00007738 NewInit.get() == OldInit &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00007739 OperatorNew == E->getOperatorNew() &&
7740 OperatorDelete == E->getOperatorDelete() &&
7741 !ArgumentChanged) {
7742 // Mark any declarations we need as referenced.
7743 // FIXME: instantiation-specific.
Douglas Gregord2d9da02010-02-26 00:38:10 +00007744 if (OperatorNew)
Eli Friedmanfa0df832012-02-02 03:46:19 +00007745 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregord2d9da02010-02-26 00:38:10 +00007746 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00007747 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00007748
Sebastian Redl6047f072012-02-16 12:22:20 +00007749 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor72912fb2011-07-26 15:11:03 +00007750 QualType ElementType
7751 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
7752 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
7753 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
7754 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedmanfa0df832012-02-02 03:46:19 +00007755 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor72912fb2011-07-26 15:11:03 +00007756 }
7757 }
7758 }
Sebastian Redl6047f072012-02-16 12:22:20 +00007759
John McCallc3007a22010-10-26 07:05:15 +00007760 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00007761 }
Mike Stump11289f42009-09-09 15:08:12 +00007762
Douglas Gregor0744ef62010-09-07 21:49:58 +00007763 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00007764 if (!ArraySize.get()) {
7765 // If no array size was specified, but the new expression was
7766 // instantiated with an array type (e.g., "new T" where T is
7767 // instantiated with "int[4]"), extract the outer bound from the
7768 // array type as our array size. We do this with constant and
7769 // dependently-sized array types.
7770 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
7771 if (!ArrayT) {
7772 // Do nothing
7773 } else if (const ConstantArrayType *ConsArrayT
7774 = dyn_cast<ConstantArrayType>(ArrayT)) {
Chad Rosier1dcde962012-08-08 18:46:20 +00007775 ArraySize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00007776 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
Chad Rosier1dcde962012-08-08 18:46:20 +00007777 ConsArrayT->getSize(),
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00007778 SemaRef.Context.getSizeType(),
7779 /*FIXME:*/E->getLocStart()));
Douglas Gregor2e9c7952009-12-22 17:13:37 +00007780 AllocType = ConsArrayT->getElementType();
7781 } else if (const DependentSizedArrayType *DepArrayT
7782 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
7783 if (DepArrayT->getSizeExpr()) {
John McCallc3007a22010-10-26 07:05:15 +00007784 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00007785 AllocType = DepArrayT->getElementType();
7786 }
7787 }
7788 }
Sebastian Redl6047f072012-02-16 12:22:20 +00007789
Douglas Gregora16548e2009-08-11 05:31:07 +00007790 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
7791 E->isGlobalNew(),
7792 /*FIXME:*/E->getLocStart(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007793 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00007794 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00007795 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007796 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00007797 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00007798 ArraySize.get(),
Sebastian Redl6047f072012-02-16 12:22:20 +00007799 E->getDirectInitRange(),
7800 NewInit.take());
Douglas Gregora16548e2009-08-11 05:31:07 +00007801}
Mike Stump11289f42009-09-09 15:08:12 +00007802
Douglas Gregora16548e2009-08-11 05:31:07 +00007803template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007804ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007805TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007806 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00007807 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007808 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007809
Douglas Gregord2d9da02010-02-26 00:38:10 +00007810 // Transform the delete operator, if known.
7811 FunctionDecl *OperatorDelete = 0;
7812 if (E->getOperatorDelete()) {
7813 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007814 getDerived().TransformDecl(E->getLocStart(),
7815 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00007816 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00007817 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00007818 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007819
Douglas Gregora16548e2009-08-11 05:31:07 +00007820 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00007821 Operand.get() == E->getArgument() &&
7822 OperatorDelete == E->getOperatorDelete()) {
7823 // Mark any declarations we need as referenced.
7824 // FIXME: instantiation-specific.
7825 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00007826 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00007827
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00007828 if (!E->getArgument()->isTypeDependent()) {
7829 QualType Destroyed = SemaRef.Context.getBaseElementType(
7830 E->getDestroyedType());
7831 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
7832 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +00007833 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedmanfa0df832012-02-02 03:46:19 +00007834 SemaRef.LookupDestructor(Record));
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00007835 }
7836 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007837
John McCallc3007a22010-10-26 07:05:15 +00007838 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00007839 }
Mike Stump11289f42009-09-09 15:08:12 +00007840
Douglas Gregora16548e2009-08-11 05:31:07 +00007841 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
7842 E->isGlobalDelete(),
7843 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00007844 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007845}
Mike Stump11289f42009-09-09 15:08:12 +00007846
Douglas Gregora16548e2009-08-11 05:31:07 +00007847template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007848ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00007849TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007850 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007851 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00007852 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007853 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007854
John McCallba7bf592010-08-24 05:47:05 +00007855 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00007856 bool MayBePseudoDestructor = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00007857 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00007858 E->getOperatorLoc(),
7859 E->isArrow()? tok::arrow : tok::period,
7860 ObjectTypePtr,
7861 MayBePseudoDestructor);
7862 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007863 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007864
John McCallba7bf592010-08-24 05:47:05 +00007865 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +00007866 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
7867 if (QualifierLoc) {
7868 QualifierLoc
7869 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
7870 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +00007871 return ExprError();
7872 }
Douglas Gregora6ce6082011-02-25 18:19:59 +00007873 CXXScopeSpec SS;
7874 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00007875
Douglas Gregor678f90d2010-02-25 01:56:36 +00007876 PseudoDestructorTypeStorage Destroyed;
7877 if (E->getDestroyedTypeInfo()) {
7878 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00007879 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregor579c15f2011-03-02 18:32:08 +00007880 ObjectType, 0, SS);
Douglas Gregor678f90d2010-02-25 01:56:36 +00007881 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007882 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00007883 Destroyed = DestroyedTypeInfo;
Douglas Gregorf39a8dd2011-11-09 02:19:47 +00007884 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregor678f90d2010-02-25 01:56:36 +00007885 // We aren't likely to be able to resolve the identifier down to a type
7886 // now anyway, so just retain the identifier.
7887 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
7888 E->getDestroyedTypeLoc());
7889 } else {
7890 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +00007891 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00007892 *E->getDestroyedTypeIdentifier(),
7893 E->getDestroyedTypeLoc(),
7894 /*Scope=*/0,
7895 SS, ObjectTypePtr,
7896 false);
7897 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007898 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007899
Douglas Gregor678f90d2010-02-25 01:56:36 +00007900 Destroyed
7901 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
7902 E->getDestroyedTypeLoc());
7903 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007904
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007905 TypeSourceInfo *ScopeTypeInfo = 0;
7906 if (E->getScopeTypeInfo()) {
Douglas Gregora88c55b2013-03-08 21:25:01 +00007907 CXXScopeSpec EmptySS;
7908 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
7909 E->getScopeTypeInfo(), ObjectType, 0, EmptySS);
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007910 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007911 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00007912 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007913
John McCallb268a282010-08-23 23:25:46 +00007914 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00007915 E->getOperatorLoc(),
7916 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +00007917 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007918 ScopeTypeInfo,
7919 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00007920 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00007921 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00007922}
Mike Stump11289f42009-09-09 15:08:12 +00007923
Douglas Gregorad8a3362009-09-04 17:36:40 +00007924template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007925ExprResult
John McCalld14a8642009-11-21 08:51:07 +00007926TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007927 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00007928 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
7929 Sema::LookupOrdinaryName);
7930
7931 // Transform all the decls.
7932 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
7933 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007934 NamedDecl *InstD = static_cast<NamedDecl*>(
7935 getDerived().TransformDecl(Old->getNameLoc(),
7936 *I));
John McCall84d87672009-12-10 09:41:52 +00007937 if (!InstD) {
7938 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7939 // This can happen because of dependent hiding.
7940 if (isa<UsingShadowDecl>(*I))
7941 continue;
Serge Pavlov82605302013-09-04 04:50:29 +00007942 else {
7943 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00007944 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00007945 }
John McCall84d87672009-12-10 09:41:52 +00007946 }
John McCalle66edc12009-11-24 19:00:30 +00007947
7948 // Expand using declarations.
7949 if (isa<UsingDecl>(InstD)) {
7950 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +00007951 for (auto *I : UD->shadows())
7952 R.addDecl(I);
John McCalle66edc12009-11-24 19:00:30 +00007953 continue;
7954 }
7955
7956 R.addDecl(InstD);
7957 }
7958
7959 // Resolve a kind, but don't do any further analysis. If it's
7960 // ambiguous, the callee needs to deal with it.
7961 R.resolveKind();
7962
7963 // Rebuild the nested-name qualifier, if present.
7964 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00007965 if (Old->getQualifierLoc()) {
7966 NestedNameSpecifierLoc QualifierLoc
7967 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7968 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007969 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007970
Douglas Gregor0da1d432011-02-28 20:01:57 +00007971 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00007972 }
7973
Douglas Gregor9262f472010-04-27 18:19:34 +00007974 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00007975 CXXRecordDecl *NamingClass
7976 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
7977 Old->getNameLoc(),
7978 Old->getNamingClass()));
Serge Pavlov82605302013-09-04 04:50:29 +00007979 if (!NamingClass) {
7980 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00007981 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00007982 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007983
Douglas Gregorda7be082010-04-27 16:10:10 +00007984 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00007985 }
7986
Abramo Bagnara7945c982012-01-27 09:46:47 +00007987 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
7988
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00007989 // If we have neither explicit template arguments, nor the template keyword,
7990 // it's a normal declaration name.
7991 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
John McCalle66edc12009-11-24 19:00:30 +00007992 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
7993
7994 // If we have template arguments, rebuild them, then rebuild the
7995 // templateid expression.
7996 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola3dd531d2012-08-28 04:13:54 +00007997 if (Old->hasExplicitTemplateArgs() &&
7998 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregor62e06f22010-12-20 17:31:10 +00007999 Old->getNumTemplateArgs(),
Serge Pavlov82605302013-09-04 04:50:29 +00008000 TransArgs)) {
8001 R.clear();
Douglas Gregor62e06f22010-12-20 17:31:10 +00008002 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00008003 }
John McCalle66edc12009-11-24 19:00:30 +00008004
Abramo Bagnara7945c982012-01-27 09:46:47 +00008005 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00008006 Old->requiresADL(), &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00008007}
Mike Stump11289f42009-09-09 15:08:12 +00008008
Douglas Gregora16548e2009-08-11 05:31:07 +00008009template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008010ExprResult
Douglas Gregor29c42f22012-02-24 07:38:34 +00008011TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
8012 bool ArgChanged = false;
Dmitri Gribenkof8579502013-01-12 19:30:44 +00008013 SmallVector<TypeSourceInfo *, 4> Args;
Douglas Gregor29c42f22012-02-24 07:38:34 +00008014 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
8015 TypeSourceInfo *From = E->getArg(I);
8016 TypeLoc FromTL = From->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00008017 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
Douglas Gregor29c42f22012-02-24 07:38:34 +00008018 TypeLocBuilder TLB;
8019 TLB.reserve(FromTL.getFullDataSize());
8020 QualType To = getDerived().TransformType(TLB, FromTL);
8021 if (To.isNull())
8022 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008023
Douglas Gregor29c42f22012-02-24 07:38:34 +00008024 if (To == From->getType())
8025 Args.push_back(From);
8026 else {
8027 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8028 ArgChanged = true;
8029 }
8030 continue;
8031 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008032
Douglas Gregor29c42f22012-02-24 07:38:34 +00008033 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00008034
Douglas Gregor29c42f22012-02-24 07:38:34 +00008035 // We have a pack expansion. Instantiate it.
David Blaikie6adc78e2013-02-18 22:06:02 +00008036 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
Douglas Gregor29c42f22012-02-24 07:38:34 +00008037 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
8038 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
8039 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00008040
Douglas Gregor29c42f22012-02-24 07:38:34 +00008041 // Determine whether the set of unexpanded parameter packs can and should
8042 // be expanded.
8043 bool Expand = true;
8044 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00008045 Optional<unsigned> OrigNumExpansions =
8046 ExpansionTL.getTypePtr()->getNumExpansions();
8047 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor29c42f22012-02-24 07:38:34 +00008048 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
8049 PatternTL.getSourceRange(),
8050 Unexpanded,
8051 Expand, RetainExpansion,
8052 NumExpansions))
8053 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008054
Douglas Gregor29c42f22012-02-24 07:38:34 +00008055 if (!Expand) {
8056 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00008057 // transformation on the pack expansion, producing another pack
Douglas Gregor29c42f22012-02-24 07:38:34 +00008058 // expansion.
8059 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier1dcde962012-08-08 18:46:20 +00008060
Douglas Gregor29c42f22012-02-24 07:38:34 +00008061 TypeLocBuilder TLB;
8062 TLB.reserve(From->getTypeLoc().getFullDataSize());
8063
8064 QualType To = getDerived().TransformType(TLB, PatternTL);
8065 if (To.isNull())
8066 return ExprError();
8067
Chad Rosier1dcde962012-08-08 18:46:20 +00008068 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00008069 PatternTL.getSourceRange(),
8070 ExpansionTL.getEllipsisLoc(),
8071 NumExpansions);
8072 if (To.isNull())
8073 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008074
Douglas Gregor29c42f22012-02-24 07:38:34 +00008075 PackExpansionTypeLoc ToExpansionTL
8076 = TLB.push<PackExpansionTypeLoc>(To);
8077 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8078 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8079 continue;
8080 }
8081
8082 // Expand the pack expansion by substituting for each argument in the
8083 // pack(s).
8084 for (unsigned I = 0; I != *NumExpansions; ++I) {
8085 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
8086 TypeLocBuilder TLB;
8087 TLB.reserve(PatternTL.getFullDataSize());
8088 QualType To = getDerived().TransformType(TLB, PatternTL);
8089 if (To.isNull())
8090 return ExprError();
8091
Eli Friedman5e05c4a2013-07-19 21:49:32 +00008092 if (To->containsUnexpandedParameterPack()) {
8093 To = getDerived().RebuildPackExpansionType(To,
8094 PatternTL.getSourceRange(),
8095 ExpansionTL.getEllipsisLoc(),
8096 NumExpansions);
8097 if (To.isNull())
8098 return ExprError();
8099
8100 PackExpansionTypeLoc ToExpansionTL
8101 = TLB.push<PackExpansionTypeLoc>(To);
8102 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8103 }
8104
Douglas Gregor29c42f22012-02-24 07:38:34 +00008105 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8106 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008107
Douglas Gregor29c42f22012-02-24 07:38:34 +00008108 if (!RetainExpansion)
8109 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00008110
Douglas Gregor29c42f22012-02-24 07:38:34 +00008111 // If we're supposed to retain a pack expansion, do so by temporarily
8112 // forgetting the partially-substituted parameter pack.
8113 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
8114
8115 TypeLocBuilder TLB;
8116 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00008117
Douglas Gregor29c42f22012-02-24 07:38:34 +00008118 QualType To = getDerived().TransformType(TLB, PatternTL);
8119 if (To.isNull())
8120 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008121
8122 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00008123 PatternTL.getSourceRange(),
8124 ExpansionTL.getEllipsisLoc(),
8125 NumExpansions);
8126 if (To.isNull())
8127 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008128
Douglas Gregor29c42f22012-02-24 07:38:34 +00008129 PackExpansionTypeLoc ToExpansionTL
8130 = TLB.push<PackExpansionTypeLoc>(To);
8131 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8132 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8133 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008134
Douglas Gregor29c42f22012-02-24 07:38:34 +00008135 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8136 return SemaRef.Owned(E);
8137
8138 return getDerived().RebuildTypeTrait(E->getTrait(),
8139 E->getLocStart(),
8140 Args,
8141 E->getLocEnd());
8142}
8143
8144template<typename Derived>
8145ExprResult
John Wiegley6242b6a2011-04-28 00:16:57 +00008146TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
8147 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
8148 if (!T)
8149 return ExprError();
8150
8151 if (!getDerived().AlwaysRebuild() &&
8152 T == E->getQueriedTypeSourceInfo())
8153 return SemaRef.Owned(E);
8154
8155 ExprResult SubExpr;
8156 {
8157 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8158 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
8159 if (SubExpr.isInvalid())
8160 return ExprError();
8161
8162 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
8163 return SemaRef.Owned(E);
8164 }
8165
8166 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
8167 E->getLocStart(),
8168 T,
8169 SubExpr.get(),
8170 E->getLocEnd());
8171}
8172
8173template<typename Derived>
8174ExprResult
John Wiegleyf9f65842011-04-25 06:54:41 +00008175TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
8176 ExprResult SubExpr;
8177 {
8178 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8179 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
8180 if (SubExpr.isInvalid())
8181 return ExprError();
8182
8183 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
8184 return SemaRef.Owned(E);
8185 }
8186
8187 return getDerived().RebuildExpressionTrait(
8188 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
8189}
8190
8191template<typename Derived>
8192ExprResult
John McCall8cd78132009-11-19 22:55:06 +00008193TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008194 DependentScopeDeclRefExpr *E) {
Richard Smithdb2630f2012-10-21 03:28:35 +00008195 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand*/false);
8196}
8197
8198template<typename Derived>
8199ExprResult
8200TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
8201 DependentScopeDeclRefExpr *E,
8202 bool IsAddressOfOperand) {
Reid Kleckner916ac4d2013-10-15 18:38:02 +00008203 assert(E->getQualifierLoc());
Douglas Gregor3a43fd62011-02-25 20:49:16 +00008204 NestedNameSpecifierLoc QualifierLoc
8205 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
8206 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008207 return ExprError();
Abramo Bagnara7945c982012-01-27 09:46:47 +00008208 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00008209
John McCall31f82722010-11-12 08:19:04 +00008210 // TODO: If this is a conversion-function-id, verify that the
8211 // destination type name (if present) resolves the same way after
8212 // instantiation as it did in the local scope.
8213
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008214 DeclarationNameInfo NameInfo
8215 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
8216 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00008217 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008218
John McCalle66edc12009-11-24 19:00:30 +00008219 if (!E->hasExplicitTemplateArgs()) {
8220 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3a43fd62011-02-25 20:49:16 +00008221 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008222 // Note: it is sufficient to compare the Name component of NameInfo:
8223 // if name has not changed, DNLoc has not changed either.
8224 NameInfo.getName() == E->getDeclName())
John McCallc3007a22010-10-26 07:05:15 +00008225 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00008226
Douglas Gregor3a43fd62011-02-25 20:49:16 +00008227 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008228 TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008229 NameInfo,
Richard Smithdb2630f2012-10-21 03:28:35 +00008230 /*TemplateArgs*/ 0,
8231 IsAddressOfOperand);
Douglas Gregord019ff62009-10-22 17:20:55 +00008232 }
John McCall6b51f282009-11-23 01:53:49 +00008233
8234 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008235 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8236 E->getNumTemplateArgs(),
8237 TransArgs))
8238 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008239
Douglas Gregor3a43fd62011-02-25 20:49:16 +00008240 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008241 TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008242 NameInfo,
Richard Smithdb2630f2012-10-21 03:28:35 +00008243 &TransArgs,
8244 IsAddressOfOperand);
Douglas Gregora16548e2009-08-11 05:31:07 +00008245}
8246
8247template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008248ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008249TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithd59b8322012-12-19 01:39:02 +00008250 // CXXConstructExprs other than for list-initialization and
8251 // CXXTemporaryObjectExpr are always implicit, so when we have
8252 // a 1-argument construction we just transform that argument.
Richard Smithdd2ca572012-11-26 08:32:48 +00008253 if ((E->getNumArgs() == 1 ||
8254 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithd59b8322012-12-19 01:39:02 +00008255 (!getDerived().DropCallArgument(E->getArg(0))) &&
8256 !E->isListInitialization())
Douglas Gregordb56b912010-02-03 03:01:57 +00008257 return getDerived().TransformExpr(E->getArg(0));
8258
Douglas Gregora16548e2009-08-11 05:31:07 +00008259 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
8260
8261 QualType T = getDerived().TransformType(E->getType());
8262 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00008263 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008264
8265 CXXConstructorDecl *Constructor
8266 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008267 getDerived().TransformDecl(E->getLocStart(),
8268 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008269 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00008270 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008271
Douglas Gregora16548e2009-08-11 05:31:07 +00008272 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008273 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00008274 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00008275 &ArgumentChanged))
8276 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008277
Douglas Gregora16548e2009-08-11 05:31:07 +00008278 if (!getDerived().AlwaysRebuild() &&
8279 T == E->getType() &&
8280 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00008281 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00008282 // Mark the constructor as referenced.
8283 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00008284 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00008285 return SemaRef.Owned(E);
Douglas Gregorde550352010-02-26 00:01:57 +00008286 }
Mike Stump11289f42009-09-09 15:08:12 +00008287
Douglas Gregordb121ba2009-12-14 16:27:04 +00008288 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
8289 Constructor, E->isElidable(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008290 Args,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00008291 E->hadMultipleCandidates(),
Richard Smithd59b8322012-12-19 01:39:02 +00008292 E->isListInitialization(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00008293 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00008294 E->getConstructionKind(),
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00008295 E->getParenOrBraceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00008296}
Mike Stump11289f42009-09-09 15:08:12 +00008297
Douglas Gregora16548e2009-08-11 05:31:07 +00008298/// \brief Transform a C++ temporary-binding expression.
8299///
Douglas Gregor363b1512009-12-24 18:51:59 +00008300/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
8301/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00008302template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008303ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008304TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00008305 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008306}
Mike Stump11289f42009-09-09 15:08:12 +00008307
John McCall5d413782010-12-06 08:20:24 +00008308/// \brief Transform a C++ expression that contains cleanups that should
8309/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +00008310///
John McCall5d413782010-12-06 08:20:24 +00008311/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +00008312/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00008313template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008314ExprResult
John McCall5d413782010-12-06 08:20:24 +00008315TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00008316 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008317}
Mike Stump11289f42009-09-09 15:08:12 +00008318
Douglas Gregora16548e2009-08-11 05:31:07 +00008319template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008320ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008321TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00008322 CXXTemporaryObjectExpr *E) {
8323 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8324 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00008325 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008326
Douglas Gregora16548e2009-08-11 05:31:07 +00008327 CXXConstructorDecl *Constructor
8328 = cast_or_null<CXXConstructorDecl>(
Chad Rosier1dcde962012-08-08 18:46:20 +00008329 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008330 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008331 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00008332 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008333
Douglas Gregora16548e2009-08-11 05:31:07 +00008334 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008335 SmallVector<Expr*, 8> Args;
Douglas Gregora16548e2009-08-11 05:31:07 +00008336 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +00008337 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00008338 &ArgumentChanged))
8339 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008340
Douglas Gregora16548e2009-08-11 05:31:07 +00008341 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00008342 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008343 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00008344 !ArgumentChanged) {
8345 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00008346 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00008347 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00008348 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008349
Richard Smithd59b8322012-12-19 01:39:02 +00008350 // FIXME: Pass in E->isListInitialization().
Douglas Gregor2b88c112010-09-08 00:15:04 +00008351 return getDerived().RebuildCXXTemporaryObjectExpr(T,
8352 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008353 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00008354 E->getLocEnd());
8355}
Mike Stump11289f42009-09-09 15:08:12 +00008356
Douglas Gregora16548e2009-08-11 05:31:07 +00008357template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008358ExprResult
Douglas Gregore31e6062012-02-07 10:09:13 +00008359TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008360
8361 // Transform any init-capture expressions before entering the scope of the
8362 // lambda body, because they are not semantically within that scope.
8363 SmallVector<InitCaptureInfoTy, 8> InitCaptureExprsAndTypes;
8364 InitCaptureExprsAndTypes.resize(E->explicit_capture_end() -
8365 E->explicit_capture_begin());
8366
8367 for (LambdaExpr::capture_iterator C = E->capture_begin(),
8368 CEnd = E->capture_end();
8369 C != CEnd; ++C) {
8370 if (!C->isInitCapture())
8371 continue;
8372 EnterExpressionEvaluationContext EEEC(getSema(),
8373 Sema::PotentiallyEvaluated);
8374 ExprResult NewExprInitResult = getDerived().TransformInitializer(
8375 C->getCapturedVar()->getInit(),
8376 C->getCapturedVar()->getInitStyle() == VarDecl::CallInit);
8377
8378 if (NewExprInitResult.isInvalid())
8379 return ExprError();
8380 Expr *NewExprInit = NewExprInitResult.get();
8381
8382 VarDecl *OldVD = C->getCapturedVar();
8383 QualType NewInitCaptureType =
8384 getSema().performLambdaInitCaptureInitialization(C->getLocation(),
8385 OldVD->getType()->isReferenceType(), OldVD->getIdentifier(),
8386 NewExprInit);
8387 NewExprInitResult = NewExprInit;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008388 InitCaptureExprsAndTypes[C - E->capture_begin()] =
8389 std::make_pair(NewExprInitResult, NewInitCaptureType);
8390
8391 }
8392
Faisal Vali524ca282013-11-12 01:40:44 +00008393 LambdaScopeInfo *LSI = getSema().PushLambdaScope();
Faisal Vali2cba1332013-10-23 06:44:28 +00008394 // Transform the template parameters, and add them to the current
8395 // instantiation scope. The null case is handled correctly.
8396 LSI->GLTemplateParameterList = getDerived().TransformTemplateParameterList(
8397 E->getTemplateParameterList());
8398
8399 // Check to see if the TypeSourceInfo of the call operator needs to
8400 // be transformed, and if so do the transformation in the
8401 // CurrentInstantiationScope.
8402
8403 TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo();
8404 FunctionProtoTypeLoc OldCallOpFPTL =
8405 OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>();
8406 TypeSourceInfo *NewCallOpTSI = 0;
8407
8408 const bool CallOpWasAlreadyTransformed =
8409 getDerived().AlreadyTransformed(OldCallOpTSI->getType());
8410
8411 // Use the Old Call Operator's TypeSourceInfo if it is already transformed.
8412 if (CallOpWasAlreadyTransformed)
8413 NewCallOpTSI = OldCallOpTSI;
8414 else {
8415 // Transform the TypeSourceInfo of the Original Lambda's Call Operator.
8416 // The transformation MUST be done in the CurrentInstantiationScope since
8417 // it introduces a mapping of the original to the newly created
8418 // transformed parameters.
8419
8420 TypeLocBuilder NewCallOpTLBuilder;
8421 QualType NewCallOpType = TransformFunctionProtoType(NewCallOpTLBuilder,
8422 OldCallOpFPTL,
8423 0, 0);
8424 NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context,
8425 NewCallOpType);
Faisal Vali2b391ab2013-09-26 19:54:12 +00008426 }
Faisal Vali2cba1332013-10-23 06:44:28 +00008427 // Extract the ParmVarDecls from the NewCallOpTSI and add them to
8428 // the vector below - this will be used to synthesize the
8429 // NewCallOperator. Additionally, add the parameters of the untransformed
8430 // lambda call operator to the CurrentInstantiationScope.
8431 SmallVector<ParmVarDecl *, 4> Params;
8432 {
8433 FunctionProtoTypeLoc NewCallOpFPTL =
8434 NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>();
8435 ParmVarDecl **NewParamDeclArray = NewCallOpFPTL.getParmArray();
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00008436 const unsigned NewNumArgs = NewCallOpFPTL.getNumParams();
Faisal Vali2cba1332013-10-23 06:44:28 +00008437
8438 for (unsigned I = 0; I < NewNumArgs; ++I) {
8439 // If this call operator's type does not require transformation,
8440 // the parameters do not get added to the current instantiation scope,
8441 // - so ADD them! This allows the following to compile when the enclosing
8442 // template is specialized and the entire lambda expression has to be
8443 // transformed.
8444 // template<class T> void foo(T t) {
8445 // auto L = [](auto a) {
8446 // auto M = [](char b) { <-- note: non-generic lambda
8447 // auto N = [](auto c) {
8448 // int x = sizeof(a);
8449 // x = sizeof(b); <-- specifically this line
8450 // x = sizeof(c);
8451 // };
8452 // };
8453 // };
8454 // }
8455 // foo('a')
8456 if (CallOpWasAlreadyTransformed)
8457 getDerived().transformedLocalDecl(NewParamDeclArray[I],
8458 NewParamDeclArray[I]);
8459 // Add to Params array, so these parameters can be used to create
8460 // the newly transformed call operator.
8461 Params.push_back(NewParamDeclArray[I]);
8462 }
8463 }
8464
8465 if (!NewCallOpTSI)
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008466 return ExprError();
8467
Eli Friedmand564afb2012-09-19 01:18:11 +00008468 // Create the local class that will describe the lambda.
8469 CXXRecordDecl *Class
8470 = getSema().createLambdaClosureType(E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +00008471 NewCallOpTSI,
Faisal Valic1a6dc42013-10-23 16:10:50 +00008472 /*KnownDependent=*/false,
8473 E->getCaptureDefault());
8474
Eli Friedmand564afb2012-09-19 01:18:11 +00008475 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
8476
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008477 // Build the call operator.
Faisal Vali2cba1332013-10-23 06:44:28 +00008478 CXXMethodDecl *NewCallOperator
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008479 = getSema().startLambdaDefinition(Class, E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +00008480 NewCallOpTSI,
Douglas Gregoradb376e2012-02-14 22:28:59 +00008481 E->getCallOperator()->getLocEnd(),
Richard Smith505df232012-07-22 23:45:10 +00008482 Params);
Faisal Vali2cba1332013-10-23 06:44:28 +00008483 LSI->CallOperator = NewCallOperator;
Rafael Espindola4b35f272013-10-04 14:28:51 +00008484
Faisal Vali2cba1332013-10-23 06:44:28 +00008485 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
8486
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008487 return getDerived().TransformLambdaScope(E, NewCallOperator,
8488 InitCaptureExprsAndTypes);
Richard Smith2589b9802012-07-25 03:56:55 +00008489}
8490
8491template<typename Derived>
8492ExprResult
8493TreeTransform<Derived>::TransformLambdaScope(LambdaExpr *E,
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008494 CXXMethodDecl *CallOperator,
8495 ArrayRef<InitCaptureInfoTy> InitCaptureExprsAndTypes) {
Richard Smithba71c082013-05-16 06:20:58 +00008496 bool Invalid = false;
8497
Douglas Gregorb4328232012-02-14 00:00:48 +00008498 // Introduce the context of the call operator.
Richard Smith7ff2bcb2014-01-24 01:54:52 +00008499 Sema::ContextRAII SavedContext(getSema(), CallOperator,
8500 /*NewThisContext*/false);
Douglas Gregorb4328232012-02-14 00:00:48 +00008501
Faisal Vali2b391ab2013-09-26 19:54:12 +00008502 LambdaScopeInfo *const LSI = getSema().getCurLambda();
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008503 // Enter the scope of the lambda.
Faisal Vali2b391ab2013-09-26 19:54:12 +00008504 getSema().buildLambdaScope(LSI, CallOperator, E->getIntroducerRange(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008505 E->getCaptureDefault(),
James Dennettddd36ff2013-08-09 23:08:25 +00008506 E->getCaptureDefaultLoc(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008507 E->hasExplicitParameters(),
8508 E->hasExplicitResultType(),
8509 E->isMutable());
Chad Rosier1dcde962012-08-08 18:46:20 +00008510
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008511 // Transform captures.
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008512 bool FinishedExplicitCaptures = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00008513 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008514 CEnd = E->capture_end();
8515 C != CEnd; ++C) {
8516 // When we hit the first implicit capture, tell Sema that we've finished
8517 // the list of explicit captures.
8518 if (!FinishedExplicitCaptures && C->isImplicit()) {
8519 getSema().finishLambdaExplicitCaptures(LSI);
8520 FinishedExplicitCaptures = true;
8521 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008522
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008523 // Capturing 'this' is trivial.
8524 if (C->capturesThis()) {
8525 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
8526 continue;
8527 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008528
Richard Smithba71c082013-05-16 06:20:58 +00008529 // Rebuild init-captures, including the implied field declaration.
8530 if (C->isInitCapture()) {
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008531
8532 InitCaptureInfoTy InitExprTypePair =
8533 InitCaptureExprsAndTypes[C - E->capture_begin()];
8534 ExprResult Init = InitExprTypePair.first;
8535 QualType InitQualType = InitExprTypePair.second;
8536 if (Init.isInvalid() || InitQualType.isNull()) {
Richard Smithba71c082013-05-16 06:20:58 +00008537 Invalid = true;
8538 continue;
8539 }
Richard Smithbb13c9a2013-09-28 04:02:39 +00008540 VarDecl *OldVD = C->getCapturedVar();
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008541 VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl(
8542 OldVD->getLocation(), InitExprTypePair.second,
8543 OldVD->getIdentifier(), Init.get());
Richard Smithbb13c9a2013-09-28 04:02:39 +00008544 if (!NewVD)
Richard Smithba71c082013-05-16 06:20:58 +00008545 Invalid = true;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008546 else {
Richard Smithbb13c9a2013-09-28 04:02:39 +00008547 getDerived().transformedLocalDecl(OldVD, NewVD);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008548 }
Richard Smithbb13c9a2013-09-28 04:02:39 +00008549 getSema().buildInitCaptureField(LSI, NewVD);
Richard Smithba71c082013-05-16 06:20:58 +00008550 continue;
8551 }
8552
8553 assert(C->capturesVariable() && "unexpected kind of lambda capture");
8554
Douglas Gregor3e308b12012-02-14 19:27:52 +00008555 // Determine the capture kind for Sema.
8556 Sema::TryCaptureKind Kind
8557 = C->isImplicit()? Sema::TryCapture_Implicit
8558 : C->getCaptureKind() == LCK_ByCopy
8559 ? Sema::TryCapture_ExplicitByVal
8560 : Sema::TryCapture_ExplicitByRef;
8561 SourceLocation EllipsisLoc;
8562 if (C->isPackExpansion()) {
8563 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
8564 bool ShouldExpand = false;
8565 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00008566 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +00008567 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
8568 C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +00008569 Unexpanded,
8570 ShouldExpand, RetainExpansion,
Richard Smithba71c082013-05-16 06:20:58 +00008571 NumExpansions)) {
8572 Invalid = true;
8573 continue;
8574 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008575
Douglas Gregor3e308b12012-02-14 19:27:52 +00008576 if (ShouldExpand) {
8577 // The transform has determined that we should perform an expansion;
8578 // transform and capture each of the arguments.
8579 // expansion of the pattern. Do so.
8580 VarDecl *Pack = C->getCapturedVar();
8581 for (unsigned I = 0; I != *NumExpansions; ++I) {
8582 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8583 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +00008584 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +00008585 Pack));
8586 if (!CapturedVar) {
8587 Invalid = true;
8588 continue;
8589 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008590
Douglas Gregor3e308b12012-02-14 19:27:52 +00008591 // Capture the transformed variable.
Chad Rosier1dcde962012-08-08 18:46:20 +00008592 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
8593 }
Douglas Gregor3e308b12012-02-14 19:27:52 +00008594 continue;
8595 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008596
Douglas Gregor3e308b12012-02-14 19:27:52 +00008597 EllipsisLoc = C->getEllipsisLoc();
8598 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008599
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008600 // Transform the captured variable.
8601 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +00008602 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008603 C->getCapturedVar()));
8604 if (!CapturedVar) {
8605 Invalid = true;
8606 continue;
8607 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008608
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008609 // Capture the transformed variable.
Douglas Gregorfdf598e2012-02-18 09:37:24 +00008610 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008611 }
8612 if (!FinishedExplicitCaptures)
8613 getSema().finishLambdaExplicitCaptures(LSI);
8614
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008615
8616 // Enter a new evaluation context to insulate the lambda from any
8617 // cleanups from the enclosing full-expression.
Chad Rosier1dcde962012-08-08 18:46:20 +00008618 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008619
8620 if (Invalid) {
Chad Rosier1dcde962012-08-08 18:46:20 +00008621 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008622 /*IsInstantiation=*/true);
8623 return ExprError();
8624 }
8625
8626 // Instantiate the body of the lambda expression.
Douglas Gregorb4328232012-02-14 00:00:48 +00008627 StmtResult Body = getDerived().TransformStmt(E->getBody());
8628 if (Body.isInvalid()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00008629 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
Douglas Gregorb4328232012-02-14 00:00:48 +00008630 /*IsInstantiation=*/true);
Chad Rosier1dcde962012-08-08 18:46:20 +00008631 return ExprError();
Douglas Gregorb4328232012-02-14 00:00:48 +00008632 }
Douglas Gregor7fcbd902012-02-21 00:37:24 +00008633
Chad Rosier1dcde962012-08-08 18:46:20 +00008634 return getSema().ActOnLambdaExpr(E->getLocStart(), Body.take(),
Douglas Gregorb61e8092012-04-04 17:40:10 +00008635 /*CurScope=*/0, /*IsInstantiation=*/true);
Douglas Gregore31e6062012-02-07 10:09:13 +00008636}
8637
8638template<typename Derived>
8639ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008640TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008641 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00008642 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8643 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00008644 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008645
Douglas Gregora16548e2009-08-11 05:31:07 +00008646 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008647 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +00008648 Args.reserve(E->arg_size());
Chad Rosier1dcde962012-08-08 18:46:20 +00008649 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00008650 &ArgumentChanged))
8651 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008652
Douglas Gregora16548e2009-08-11 05:31:07 +00008653 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00008654 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008655 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00008656 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00008657
Douglas Gregora16548e2009-08-11 05:31:07 +00008658 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +00008659 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +00008660 E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008661 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00008662 E->getRParenLoc());
8663}
Mike Stump11289f42009-09-09 15:08:12 +00008664
Douglas Gregora16548e2009-08-11 05:31:07 +00008665template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008666ExprResult
John McCall8cd78132009-11-19 22:55:06 +00008667TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008668 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008669 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00008670 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00008671 Expr *OldBase;
8672 QualType BaseType;
8673 QualType ObjectType;
8674 if (!E->isImplicitAccess()) {
8675 OldBase = E->getBase();
8676 Base = getDerived().TransformExpr(OldBase);
8677 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008678 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008679
John McCall2d74de92009-12-01 22:10:20 +00008680 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +00008681 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +00008682 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00008683 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00008684 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00008685 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00008686 ObjectTy,
8687 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00008688 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008689 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00008690
John McCallba7bf592010-08-24 05:47:05 +00008691 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +00008692 BaseType = ((Expr*) Base.get())->getType();
8693 } else {
8694 OldBase = 0;
8695 BaseType = getDerived().TransformType(E->getBaseType());
8696 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
8697 }
Mike Stump11289f42009-09-09 15:08:12 +00008698
Douglas Gregora5cb6da2009-10-20 05:58:46 +00008699 // Transform the first part of the nested-name-specifier that qualifies
8700 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00008701 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00008702 = getDerived().TransformFirstQualifierInScope(
Douglas Gregore16af532011-02-28 18:50:33 +00008703 E->getFirstQualifierFoundInScope(),
8704 E->getQualifierLoc().getBeginLoc());
Mike Stump11289f42009-09-09 15:08:12 +00008705
Douglas Gregore16af532011-02-28 18:50:33 +00008706 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00008707 if (E->getQualifier()) {
Douglas Gregore16af532011-02-28 18:50:33 +00008708 QualifierLoc
8709 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
8710 ObjectType,
8711 FirstQualifierInScope);
8712 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008713 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +00008714 }
Mike Stump11289f42009-09-09 15:08:12 +00008715
Abramo Bagnara7945c982012-01-27 09:46:47 +00008716 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
8717
John McCall31f82722010-11-12 08:19:04 +00008718 // TODO: If this is a conversion-function-id, verify that the
8719 // destination type name (if present) resolves the same way after
8720 // instantiation as it did in the local scope.
8721
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008722 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +00008723 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008724 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00008725 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008726
John McCall2d74de92009-12-01 22:10:20 +00008727 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00008728 // This is a reference to a member without an explicitly-specified
8729 // template argument list. Optimize for this common case.
8730 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00008731 Base.get() == OldBase &&
8732 BaseType == E->getBaseType() &&
Douglas Gregore16af532011-02-28 18:50:33 +00008733 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008734 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00008735 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCallc3007a22010-10-26 07:05:15 +00008736 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00008737
John McCallb268a282010-08-23 23:25:46 +00008738 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00008739 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00008740 E->isArrow(),
8741 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00008742 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008743 TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00008744 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008745 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00008746 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00008747 }
8748
John McCall6b51f282009-11-23 01:53:49 +00008749 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008750 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8751 E->getNumTemplateArgs(),
8752 TransArgs))
8753 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008754
John McCallb268a282010-08-23 23:25:46 +00008755 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00008756 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00008757 E->isArrow(),
8758 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00008759 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008760 TemplateKWLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +00008761 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008762 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00008763 &TransArgs);
8764}
8765
8766template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008767ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008768TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00008769 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00008770 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00008771 QualType BaseType;
8772 if (!Old->isImplicitAccess()) {
8773 Base = getDerived().TransformExpr(Old->getBase());
8774 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008775 return ExprError();
Richard Smithcab9a7d2011-10-26 19:06:56 +00008776 Base = getSema().PerformMemberExprBaseConversion(Base.take(),
8777 Old->isArrow());
8778 if (Base.isInvalid())
8779 return ExprError();
8780 BaseType = Base.get()->getType();
John McCall2d74de92009-12-01 22:10:20 +00008781 } else {
8782 BaseType = getDerived().TransformType(Old->getBaseType());
8783 }
John McCall10eae182009-11-30 22:42:35 +00008784
Douglas Gregor0da1d432011-02-28 20:01:57 +00008785 NestedNameSpecifierLoc QualifierLoc;
8786 if (Old->getQualifierLoc()) {
8787 QualifierLoc
8788 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
8789 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008790 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00008791 }
8792
Abramo Bagnara7945c982012-01-27 09:46:47 +00008793 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
8794
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008795 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +00008796 Sema::LookupOrdinaryName);
8797
8798 // Transform all the decls.
8799 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
8800 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008801 NamedDecl *InstD = static_cast<NamedDecl*>(
8802 getDerived().TransformDecl(Old->getMemberLoc(),
8803 *I));
John McCall84d87672009-12-10 09:41:52 +00008804 if (!InstD) {
8805 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
8806 // This can happen because of dependent hiding.
8807 if (isa<UsingShadowDecl>(*I))
8808 continue;
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00008809 else {
8810 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00008811 return ExprError();
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00008812 }
John McCall84d87672009-12-10 09:41:52 +00008813 }
John McCall10eae182009-11-30 22:42:35 +00008814
8815 // Expand using declarations.
8816 if (isa<UsingDecl>(InstD)) {
8817 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +00008818 for (auto *I : UD->shadows())
8819 R.addDecl(I);
John McCall10eae182009-11-30 22:42:35 +00008820 continue;
8821 }
8822
8823 R.addDecl(InstD);
8824 }
8825
8826 R.resolveKind();
8827
Douglas Gregor9262f472010-04-27 18:19:34 +00008828 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00008829 if (Old->getNamingClass()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00008830 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00008831 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00008832 Old->getMemberLoc(),
8833 Old->getNamingClass()));
8834 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00008835 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008836
Douglas Gregorda7be082010-04-27 16:10:10 +00008837 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00008838 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008839
John McCall10eae182009-11-30 22:42:35 +00008840 TemplateArgumentListInfo TransArgs;
8841 if (Old->hasExplicitTemplateArgs()) {
8842 TransArgs.setLAngleLoc(Old->getLAngleLoc());
8843 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008844 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
8845 Old->getNumTemplateArgs(),
8846 TransArgs))
8847 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00008848 }
John McCall38836f02010-01-15 08:34:02 +00008849
8850 // FIXME: to do this check properly, we will need to preserve the
8851 // first-qualifier-in-scope here, just in case we had a dependent
8852 // base (and therefore couldn't do the check) and a
8853 // nested-name-qualifier (and therefore could do the lookup).
8854 NamedDecl *FirstQualifierInScope = 0;
Chad Rosier1dcde962012-08-08 18:46:20 +00008855
John McCallb268a282010-08-23 23:25:46 +00008856 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00008857 BaseType,
John McCall10eae182009-11-30 22:42:35 +00008858 Old->getOperatorLoc(),
8859 Old->isArrow(),
Douglas Gregor0da1d432011-02-28 20:01:57 +00008860 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008861 TemplateKWLoc,
John McCall38836f02010-01-15 08:34:02 +00008862 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00008863 R,
8864 (Old->hasExplicitTemplateArgs()
8865 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00008866}
8867
8868template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008869ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +00008870TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Alexis Hunt414e3e32011-05-31 19:54:49 +00008871 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00008872 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
8873 if (SubExpr.isInvalid())
8874 return ExprError();
8875
8876 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCallc3007a22010-10-26 07:05:15 +00008877 return SemaRef.Owned(E);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00008878
8879 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
8880}
8881
8882template<typename Derived>
8883ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +00008884TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +00008885 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
8886 if (Pattern.isInvalid())
8887 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008888
Douglas Gregor0f836ea2011-01-13 00:19:55 +00008889 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
8890 return SemaRef.Owned(E);
8891
Douglas Gregorb8840002011-01-14 21:20:45 +00008892 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
8893 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +00008894}
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008895
8896template<typename Derived>
8897ExprResult
8898TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
8899 // If E is not value-dependent, then nothing will change when we transform it.
8900 // Note: This is an instantiation-centric view.
8901 if (!E->isValueDependent())
8902 return SemaRef.Owned(E);
8903
8904 // Note: None of the implementations of TryExpandParameterPacks can ever
8905 // produce a diagnostic when given only a single unexpanded parameter pack,
Chad Rosier1dcde962012-08-08 18:46:20 +00008906 // so
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008907 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
8908 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00008909 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00008910 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +00008911 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikieb9c168a2011-09-22 02:34:54 +00008912 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00008913 ShouldExpand, RetainExpansion,
8914 NumExpansions))
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008915 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008916
Douglas Gregorab96bcf2011-10-10 18:59:29 +00008917 if (RetainExpansion)
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008918 return SemaRef.Owned(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00008919
Douglas Gregorab96bcf2011-10-10 18:59:29 +00008920 NamedDecl *Pack = E->getPack();
8921 if (!ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00008922 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
Douglas Gregorab96bcf2011-10-10 18:59:29 +00008923 Pack));
8924 if (!Pack)
8925 return ExprError();
8926 }
8927
Chad Rosier1dcde962012-08-08 18:46:20 +00008928
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008929 // We now know the length of the parameter pack, so build a new expression
8930 // that stores that length.
Chad Rosier1dcde962012-08-08 18:46:20 +00008931 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
8932 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregorab96bcf2011-10-10 18:59:29 +00008933 NumExpansions);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008934}
8935
Douglas Gregore8e9dd62011-01-03 17:17:50 +00008936template<typename Derived>
8937ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +00008938TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
8939 SubstNonTypeTemplateParmPackExpr *E) {
8940 // Default behavior is to do nothing with this transformation.
8941 return SemaRef.Owned(E);
8942}
8943
8944template<typename Derived>
8945ExprResult
John McCall7c454bb2011-07-15 05:09:51 +00008946TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
8947 SubstNonTypeTemplateParmExpr *E) {
8948 // Default behavior is to do nothing with this transformation.
8949 return SemaRef.Owned(E);
8950}
8951
8952template<typename Derived>
8953ExprResult
Richard Smithb15fe3a2012-09-12 00:56:43 +00008954TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
8955 // Default behavior is to do nothing with this transformation.
8956 return SemaRef.Owned(E);
8957}
8958
8959template<typename Derived>
8960ExprResult
Douglas Gregorfe314812011-06-21 17:03:29 +00008961TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
8962 MaterializeTemporaryExpr *E) {
8963 return getDerived().TransformExpr(E->GetTemporaryExpr());
8964}
Chad Rosier1dcde962012-08-08 18:46:20 +00008965
Douglas Gregorfe314812011-06-21 17:03:29 +00008966template<typename Derived>
8967ExprResult
Richard Smithcc1b96d2013-06-12 22:31:48 +00008968TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
8969 CXXStdInitializerListExpr *E) {
8970 return getDerived().TransformExpr(E->getSubExpr());
8971}
8972
8973template<typename Derived>
8974ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008975TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00008976 return SemaRef.MaybeBindToTemporary(E);
8977}
8978
8979template<typename Derived>
8980ExprResult
8981TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Jordy Rose8986c5992012-03-12 17:53:02 +00008982 return SemaRef.Owned(E);
Ted Kremeneke65b0862012-03-06 20:05:56 +00008983}
8984
8985template<typename Derived>
8986ExprResult
Patrick Beard0caa3942012-04-19 00:25:12 +00008987TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
8988 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
8989 if (SubExpr.isInvalid())
8990 return ExprError();
8991
8992 if (!getDerived().AlwaysRebuild() &&
8993 SubExpr.get() == E->getSubExpr())
8994 return SemaRef.Owned(E);
8995
8996 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremeneke65b0862012-03-06 20:05:56 +00008997}
8998
8999template<typename Derived>
9000ExprResult
9001TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
9002 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +00009003 SmallVector<Expr *, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009004 bool ArgChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00009005 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremeneke65b0862012-03-06 20:05:56 +00009006 /*IsCall=*/false, Elements, &ArgChanged))
9007 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009008
Ted Kremeneke65b0862012-03-06 20:05:56 +00009009 if (!getDerived().AlwaysRebuild() && !ArgChanged)
9010 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009011
Ted Kremeneke65b0862012-03-06 20:05:56 +00009012 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
9013 Elements.data(),
9014 Elements.size());
9015}
9016
9017template<typename Derived>
9018ExprResult
9019TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier1dcde962012-08-08 18:46:20 +00009020 ObjCDictionaryLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00009021 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +00009022 SmallVector<ObjCDictionaryElement, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009023 bool ArgChanged = false;
9024 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
9025 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier1dcde962012-08-08 18:46:20 +00009026
Ted Kremeneke65b0862012-03-06 20:05:56 +00009027 if (OrigElement.isPackExpansion()) {
9028 // This key/value element is a pack expansion.
9029 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
9030 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
9031 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
9032 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
9033
9034 // Determine whether the set of unexpanded parameter packs can
9035 // and should be expanded.
9036 bool Expand = true;
9037 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00009038 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
9039 Optional<unsigned> NumExpansions = OrigNumExpansions;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009040 SourceRange PatternRange(OrigElement.Key->getLocStart(),
9041 OrigElement.Value->getLocEnd());
9042 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
9043 PatternRange,
9044 Unexpanded,
9045 Expand, RetainExpansion,
9046 NumExpansions))
9047 return ExprError();
9048
9049 if (!Expand) {
9050 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00009051 // transformation on the pack expansion, producing another pack
Ted Kremeneke65b0862012-03-06 20:05:56 +00009052 // expansion.
9053 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
9054 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
9055 if (Key.isInvalid())
9056 return ExprError();
9057
9058 if (Key.get() != OrigElement.Key)
9059 ArgChanged = true;
9060
9061 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
9062 if (Value.isInvalid())
9063 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009064
Ted Kremeneke65b0862012-03-06 20:05:56 +00009065 if (Value.get() != OrigElement.Value)
9066 ArgChanged = true;
9067
Chad Rosier1dcde962012-08-08 18:46:20 +00009068 ObjCDictionaryElement Expansion = {
Ted Kremeneke65b0862012-03-06 20:05:56 +00009069 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
9070 };
9071 Elements.push_back(Expansion);
9072 continue;
9073 }
9074
9075 // Record right away that the argument was changed. This needs
9076 // to happen even if the array expands to nothing.
9077 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009078
Ted Kremeneke65b0862012-03-06 20:05:56 +00009079 // The transform has determined that we should perform an elementwise
9080 // expansion of the pattern. Do so.
9081 for (unsigned I = 0; I != *NumExpansions; ++I) {
9082 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
9083 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
9084 if (Key.isInvalid())
9085 return ExprError();
9086
9087 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
9088 if (Value.isInvalid())
9089 return ExprError();
9090
Chad Rosier1dcde962012-08-08 18:46:20 +00009091 ObjCDictionaryElement Element = {
Ted Kremeneke65b0862012-03-06 20:05:56 +00009092 Key.get(), Value.get(), SourceLocation(), NumExpansions
9093 };
9094
9095 // If any unexpanded parameter packs remain, we still have a
9096 // pack expansion.
9097 if (Key.get()->containsUnexpandedParameterPack() ||
9098 Value.get()->containsUnexpandedParameterPack())
9099 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier1dcde962012-08-08 18:46:20 +00009100
Ted Kremeneke65b0862012-03-06 20:05:56 +00009101 Elements.push_back(Element);
9102 }
9103
9104 // We've finished with this pack expansion.
9105 continue;
9106 }
9107
9108 // Transform and check key.
9109 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
9110 if (Key.isInvalid())
9111 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009112
Ted Kremeneke65b0862012-03-06 20:05:56 +00009113 if (Key.get() != OrigElement.Key)
9114 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009115
Ted Kremeneke65b0862012-03-06 20:05:56 +00009116 // Transform and check value.
9117 ExprResult Value
9118 = getDerived().TransformExpr(OrigElement.Value);
9119 if (Value.isInvalid())
9120 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009121
Ted Kremeneke65b0862012-03-06 20:05:56 +00009122 if (Value.get() != OrigElement.Value)
9123 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009124
9125 ObjCDictionaryElement Element = {
David Blaikie7a30dc52013-02-21 01:47:18 +00009126 Key.get(), Value.get(), SourceLocation(), None
Ted Kremeneke65b0862012-03-06 20:05:56 +00009127 };
9128 Elements.push_back(Element);
9129 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009130
Ted Kremeneke65b0862012-03-06 20:05:56 +00009131 if (!getDerived().AlwaysRebuild() && !ArgChanged)
9132 return SemaRef.MaybeBindToTemporary(E);
9133
9134 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
9135 Elements.data(),
9136 Elements.size());
Douglas Gregora16548e2009-08-11 05:31:07 +00009137}
9138
Mike Stump11289f42009-09-09 15:08:12 +00009139template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009140ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009141TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00009142 TypeSourceInfo *EncodedTypeInfo
9143 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
9144 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009145 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009146
Douglas Gregora16548e2009-08-11 05:31:07 +00009147 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00009148 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00009149 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009150
9151 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00009152 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00009153 E->getRParenLoc());
9154}
Mike Stump11289f42009-09-09 15:08:12 +00009155
Douglas Gregora16548e2009-08-11 05:31:07 +00009156template<typename Derived>
John McCall31168b02011-06-15 23:02:42 +00009157ExprResult TreeTransform<Derived>::
9158TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
John McCallbc489892013-04-11 02:14:26 +00009159 // This is a kind of implicit conversion, and it needs to get dropped
9160 // and recomputed for the same general reasons that ImplicitCastExprs
9161 // do, as well a more specific one: this expression is only valid when
9162 // it appears *immediately* as an argument expression.
9163 return getDerived().TransformExpr(E->getSubExpr());
John McCall31168b02011-06-15 23:02:42 +00009164}
9165
9166template<typename Derived>
9167ExprResult TreeTransform<Derived>::
9168TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier1dcde962012-08-08 18:46:20 +00009169 TypeSourceInfo *TSInfo
John McCall31168b02011-06-15 23:02:42 +00009170 = getDerived().TransformType(E->getTypeInfoAsWritten());
9171 if (!TSInfo)
9172 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009173
John McCall31168b02011-06-15 23:02:42 +00009174 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier1dcde962012-08-08 18:46:20 +00009175 if (Result.isInvalid())
John McCall31168b02011-06-15 23:02:42 +00009176 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009177
John McCall31168b02011-06-15 23:02:42 +00009178 if (!getDerived().AlwaysRebuild() &&
9179 TSInfo == E->getTypeInfoAsWritten() &&
9180 Result.get() == E->getSubExpr())
9181 return SemaRef.Owned(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009182
John McCall31168b02011-06-15 23:02:42 +00009183 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier1dcde962012-08-08 18:46:20 +00009184 E->getBridgeKeywordLoc(), TSInfo,
John McCall31168b02011-06-15 23:02:42 +00009185 Result.get());
9186}
9187
9188template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009189ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009190TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009191 // Transform arguments.
9192 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009193 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +00009194 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +00009195 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009196 &ArgChanged))
9197 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009198
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009199 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
9200 // Class message: transform the receiver type.
9201 TypeSourceInfo *ReceiverTypeInfo
9202 = getDerived().TransformType(E->getClassReceiverTypeInfo());
9203 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009204 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009205
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009206 // If nothing changed, just retain the existing message send.
9207 if (!getDerived().AlwaysRebuild() &&
9208 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009209 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009210
9211 // Build a new class message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009212 SmallVector<SourceLocation, 16> SelLocs;
9213 E->getSelectorLocs(SelLocs);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009214 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
9215 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009216 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009217 E->getMethodDecl(),
9218 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009219 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009220 E->getRightLoc());
9221 }
9222
9223 // Instance message: transform the receiver
9224 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
9225 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +00009226 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009227 = getDerived().TransformExpr(E->getInstanceReceiver());
9228 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009229 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009230
9231 // If nothing changed, just retain the existing message send.
9232 if (!getDerived().AlwaysRebuild() &&
9233 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009234 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009235
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009236 // Build a new instance message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009237 SmallVector<SourceLocation, 16> SelLocs;
9238 E->getSelectorLocs(SelLocs);
John McCallb268a282010-08-23 23:25:46 +00009239 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009240 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009241 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009242 E->getMethodDecl(),
9243 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009244 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009245 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00009246}
9247
Mike Stump11289f42009-09-09 15:08:12 +00009248template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009249ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009250TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00009251 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009252}
9253
Mike Stump11289f42009-09-09 15:08:12 +00009254template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009255ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009256TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00009257 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009258}
9259
Mike Stump11289f42009-09-09 15:08:12 +00009260template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009261ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009262TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00009263 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00009264 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00009265 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009266 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +00009267
9268 // We don't need to transform the ivar; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +00009269
Douglas Gregord51d90d2010-04-26 20:11:03 +00009270 // If nothing changed, just retain the existing expression.
9271 if (!getDerived().AlwaysRebuild() &&
9272 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00009273 return SemaRef.Owned(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009274
John McCallb268a282010-08-23 23:25:46 +00009275 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00009276 E->getLocation(),
9277 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +00009278}
9279
Mike Stump11289f42009-09-09 15:08:12 +00009280template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009281ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009282TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +00009283 // 'super' and types never change. Property never changes. Just
9284 // retain the existing expression.
9285 if (!E->isObjectReceiver())
John McCallc3007a22010-10-26 07:05:15 +00009286 return SemaRef.Owned(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009287
Douglas Gregor9faee212010-04-26 20:47:02 +00009288 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00009289 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +00009290 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009291 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009292
Douglas Gregor9faee212010-04-26 20:47:02 +00009293 // We don't need to transform the property; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +00009294
Douglas Gregor9faee212010-04-26 20:47:02 +00009295 // If nothing changed, just retain the existing expression.
9296 if (!getDerived().AlwaysRebuild() &&
9297 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00009298 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009299
John McCallb7bd14f2010-12-02 01:19:52 +00009300 if (E->isExplicitProperty())
9301 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
9302 E->getExplicitProperty(),
9303 E->getLocation());
9304
9305 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall526ab472011-10-25 17:37:35 +00009306 SemaRef.Context.PseudoObjectTy,
John McCallb7bd14f2010-12-02 01:19:52 +00009307 E->getImplicitPropertyGetter(),
9308 E->getImplicitPropertySetter(),
9309 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00009310}
9311
Mike Stump11289f42009-09-09 15:08:12 +00009312template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009313ExprResult
Ted Kremeneke65b0862012-03-06 20:05:56 +00009314TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
9315 // Transform the base expression.
9316 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
9317 if (Base.isInvalid())
9318 return ExprError();
9319
9320 // Transform the key expression.
9321 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
9322 if (Key.isInvalid())
9323 return ExprError();
9324
9325 // If nothing changed, just retain the existing expression.
9326 if (!getDerived().AlwaysRebuild() &&
9327 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
9328 return SemaRef.Owned(E);
9329
Chad Rosier1dcde962012-08-08 18:46:20 +00009330 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremeneke65b0862012-03-06 20:05:56 +00009331 Base.get(), Key.get(),
9332 E->getAtIndexMethodDecl(),
9333 E->setAtIndexMethodDecl());
9334}
9335
9336template<typename Derived>
9337ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009338TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00009339 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00009340 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00009341 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009342 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009343
Douglas Gregord51d90d2010-04-26 20:11:03 +00009344 // If nothing changed, just retain the existing expression.
9345 if (!getDerived().AlwaysRebuild() &&
9346 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00009347 return SemaRef.Owned(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009348
John McCallb268a282010-08-23 23:25:46 +00009349 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00009350 E->getOpLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00009351 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +00009352}
9353
Mike Stump11289f42009-09-09 15:08:12 +00009354template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009355ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009356TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009357 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009358 SmallVector<Expr*, 8> SubExprs;
Douglas Gregora3efea12011-01-03 19:04:46 +00009359 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier1dcde962012-08-08 18:46:20 +00009360 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00009361 SubExprs, &ArgumentChanged))
9362 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009363
Douglas Gregora16548e2009-08-11 05:31:07 +00009364 if (!getDerived().AlwaysRebuild() &&
9365 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00009366 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00009367
Douglas Gregora16548e2009-08-11 05:31:07 +00009368 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009369 SubExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00009370 E->getRParenLoc());
9371}
9372
Mike Stump11289f42009-09-09 15:08:12 +00009373template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009374ExprResult
Hal Finkelc4d7c822013-09-18 03:29:45 +00009375TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) {
9376 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
9377 if (SrcExpr.isInvalid())
9378 return ExprError();
9379
9380 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
9381 if (!Type)
9382 return ExprError();
9383
9384 if (!getDerived().AlwaysRebuild() &&
9385 Type == E->getTypeSourceInfo() &&
9386 SrcExpr.get() == E->getSrcExpr())
9387 return SemaRef.Owned(E);
9388
9389 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
9390 SrcExpr.get(), Type,
9391 E->getRParenLoc());
9392}
9393
9394template<typename Derived>
9395ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009396TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +00009397 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier1dcde962012-08-08 18:46:20 +00009398
John McCall490112f2011-02-04 18:33:18 +00009399 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
9400 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
9401
9402 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahaniandd5eb9d2011-12-03 17:47:53 +00009403 blockScope->TheDecl->setBlockMissingReturnType(
9404 oldBlock->blockMissingReturnType());
Chad Rosier1dcde962012-08-08 18:46:20 +00009405
Chris Lattner01cf8db2011-07-20 06:58:45 +00009406 SmallVector<ParmVarDecl*, 4> params;
9407 SmallVector<QualType, 4> paramTypes;
Chad Rosier1dcde962012-08-08 18:46:20 +00009408
Fariborz Jahanian1babe772010-07-09 18:44:02 +00009409 // Parameter substitution.
John McCall490112f2011-02-04 18:33:18 +00009410 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
9411 oldBlock->param_begin(),
9412 oldBlock->param_size(),
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +00009413 0, paramTypes, &params)) {
9414 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009415 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +00009416 }
John McCall490112f2011-02-04 18:33:18 +00009417
Jordan Rosea0a86be2013-03-08 22:25:36 +00009418 const FunctionProtoType *exprFunctionType = E->getFunctionType();
Eli Friedman34b49062012-01-26 03:00:14 +00009419 QualType exprResultType =
Alp Toker314cc812014-01-25 16:55:45 +00009420 getDerived().TransformType(exprFunctionType->getReturnType());
Douglas Gregor476e3022011-01-19 21:32:01 +00009421
Jordan Rose5c382722013-03-08 21:51:21 +00009422 QualType functionType =
9423 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +00009424 exprFunctionType->getExtProtoInfo());
John McCall490112f2011-02-04 18:33:18 +00009425 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +00009426
9427 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +00009428 if (!params.empty())
David Blaikie9c70e042011-09-21 18:16:56 +00009429 blockScope->TheDecl->setParams(params);
Eli Friedman34b49062012-01-26 03:00:14 +00009430
9431 if (!oldBlock->blockMissingReturnType()) {
9432 blockScope->HasImplicitReturnType = false;
9433 blockScope->ReturnType = exprResultType;
9434 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009435
John McCall3882ace2011-01-05 12:14:39 +00009436 // Transform the body
John McCall490112f2011-02-04 18:33:18 +00009437 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +00009438 if (body.isInvalid()) {
9439 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
John McCall3882ace2011-01-05 12:14:39 +00009440 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +00009441 }
John McCall3882ace2011-01-05 12:14:39 +00009442
John McCall490112f2011-02-04 18:33:18 +00009443#ifndef NDEBUG
9444 // In builds with assertions, make sure that we captured everything we
9445 // captured before.
Douglas Gregor4385d8b2011-05-20 15:32:55 +00009446 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
Aaron Ballman9371dd22014-03-14 18:34:04 +00009447 for (const auto &I : oldBlock->captures()) {
9448 VarDecl *oldCapture = I.getVariable();
John McCall490112f2011-02-04 18:33:18 +00009449
Douglas Gregor4385d8b2011-05-20 15:32:55 +00009450 // Ignore parameter packs.
9451 if (isa<ParmVarDecl>(oldCapture) &&
9452 cast<ParmVarDecl>(oldCapture)->isParameterPack())
9453 continue;
John McCall490112f2011-02-04 18:33:18 +00009454
Douglas Gregor4385d8b2011-05-20 15:32:55 +00009455 VarDecl *newCapture =
9456 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
9457 oldCapture));
9458 assert(blockScope->CaptureMap.count(newCapture));
9459 }
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00009460 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCall490112f2011-02-04 18:33:18 +00009461 }
9462#endif
9463
9464 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
9465 /*Scope=*/0);
Douglas Gregora16548e2009-08-11 05:31:07 +00009466}
9467
Mike Stump11289f42009-09-09 15:08:12 +00009468template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009469ExprResult
Tanya Lattner55808c12011-06-04 00:47:47 +00009470TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikie83d382b2011-09-23 05:06:16 +00009471 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner55808c12011-06-04 00:47:47 +00009472}
Eli Friedmandf14b3a2011-10-11 02:20:01 +00009473
9474template<typename Derived>
9475ExprResult
9476TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedman8d3e43f2011-10-14 22:48:56 +00009477 QualType RetTy = getDerived().TransformType(E->getType());
9478 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009479 SmallVector<Expr*, 8> SubExprs;
Eli Friedman8d3e43f2011-10-14 22:48:56 +00009480 SubExprs.reserve(E->getNumSubExprs());
9481 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
9482 SubExprs, &ArgumentChanged))
9483 return ExprError();
9484
9485 if (!getDerived().AlwaysRebuild() &&
9486 !ArgumentChanged)
9487 return SemaRef.Owned(E);
9488
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009489 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedman8d3e43f2011-10-14 22:48:56 +00009490 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedmandf14b3a2011-10-11 02:20:01 +00009491}
Chad Rosier1dcde962012-08-08 18:46:20 +00009492
Douglas Gregora16548e2009-08-11 05:31:07 +00009493//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00009494// Type reconstruction
9495//===----------------------------------------------------------------------===//
9496
Mike Stump11289f42009-09-09 15:08:12 +00009497template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00009498QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
9499 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00009500 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009501 getDerived().getBaseEntity());
9502}
9503
Mike Stump11289f42009-09-09 15:08:12 +00009504template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00009505QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
9506 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00009507 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009508 getDerived().getBaseEntity());
9509}
9510
Mike Stump11289f42009-09-09 15:08:12 +00009511template<typename Derived>
9512QualType
John McCall70dd5f62009-10-30 00:06:24 +00009513TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
9514 bool WrittenAsLValue,
9515 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00009516 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +00009517 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00009518}
9519
9520template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009521QualType
John McCall70dd5f62009-10-30 00:06:24 +00009522TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
9523 QualType ClassType,
9524 SourceLocation Sigil) {
Reid Kleckner0503a872013-12-05 01:23:43 +00009525 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil,
9526 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00009527}
9528
9529template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009530QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00009531TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
9532 ArrayType::ArraySizeModifier SizeMod,
9533 const llvm::APInt *Size,
9534 Expr *SizeExpr,
9535 unsigned IndexTypeQuals,
9536 SourceRange BracketsRange) {
9537 if (SizeExpr || !Size)
9538 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
9539 IndexTypeQuals, BracketsRange,
9540 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00009541
9542 QualType Types[] = {
9543 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
9544 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
9545 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00009546 };
Craig Toppere5ce8312013-07-15 03:38:40 +00009547 const unsigned NumTypes = llvm::array_lengthof(Types);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009548 QualType SizeType;
9549 for (unsigned I = 0; I != NumTypes; ++I)
9550 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
9551 SizeType = Types[I];
9552 break;
9553 }
Mike Stump11289f42009-09-09 15:08:12 +00009554
Eli Friedman9562f392012-01-25 23:20:27 +00009555 // Note that we can return a VariableArrayType here in the case where
9556 // the element type was a dependent VariableArrayType.
9557 IntegerLiteral *ArraySize
9558 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
9559 /*FIXME*/BracketsRange.getBegin());
9560 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009561 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00009562 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00009563}
Mike Stump11289f42009-09-09 15:08:12 +00009564
Douglas Gregord6ff3322009-08-04 16:50:30 +00009565template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009566QualType
9567TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009568 ArrayType::ArraySizeModifier SizeMod,
9569 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00009570 unsigned IndexTypeQuals,
9571 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00009572 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00009573 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009574}
9575
9576template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009577QualType
Mike Stump11289f42009-09-09 15:08:12 +00009578TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009579 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00009580 unsigned IndexTypeQuals,
9581 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00009582 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00009583 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009584}
Mike Stump11289f42009-09-09 15:08:12 +00009585
Douglas Gregord6ff3322009-08-04 16:50:30 +00009586template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009587QualType
9588TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009589 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00009590 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009591 unsigned IndexTypeQuals,
9592 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00009593 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00009594 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009595 IndexTypeQuals, BracketsRange);
9596}
9597
9598template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009599QualType
9600TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009601 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00009602 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009603 unsigned IndexTypeQuals,
9604 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00009605 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00009606 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009607 IndexTypeQuals, BracketsRange);
9608}
9609
9610template<typename Derived>
9611QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +00009612 unsigned NumElements,
9613 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00009614 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +00009615 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009616}
Mike Stump11289f42009-09-09 15:08:12 +00009617
Douglas Gregord6ff3322009-08-04 16:50:30 +00009618template<typename Derived>
9619QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
9620 unsigned NumElements,
9621 SourceLocation AttributeLoc) {
9622 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
9623 NumElements, true);
9624 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00009625 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
9626 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +00009627 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009628}
Mike Stump11289f42009-09-09 15:08:12 +00009629
Douglas Gregord6ff3322009-08-04 16:50:30 +00009630template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009631QualType
9632TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +00009633 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009634 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +00009635 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009636}
Mike Stump11289f42009-09-09 15:08:12 +00009637
Douglas Gregord6ff3322009-08-04 16:50:30 +00009638template<typename Derived>
Jordan Rose5c382722013-03-08 21:51:21 +00009639QualType TreeTransform<Derived>::RebuildFunctionProtoType(
9640 QualType T,
9641 llvm::MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +00009642 const FunctionProtoType::ExtProtoInfo &EPI) {
9643 return SemaRef.BuildFunctionType(T, ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009644 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +00009645 getDerived().getBaseEntity(),
Jordan Rosea0a86be2013-03-08 22:25:36 +00009646 EPI);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009647}
Mike Stump11289f42009-09-09 15:08:12 +00009648
Douglas Gregord6ff3322009-08-04 16:50:30 +00009649template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00009650QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
9651 return SemaRef.Context.getFunctionNoProtoType(T);
9652}
9653
9654template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00009655QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
9656 assert(D && "no decl found");
9657 if (D->isInvalidDecl()) return QualType();
9658
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009659 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +00009660 TypeDecl *Ty;
9661 if (isa<UsingDecl>(D)) {
9662 UsingDecl *Using = cast<UsingDecl>(D);
Enea Zaffanellae05a3cf2013-07-22 10:54:09 +00009663 assert(Using->hasTypename() &&
John McCallb96ec562009-12-04 22:46:56 +00009664 "UnresolvedUsingTypenameDecl transformed to non-typename using");
9665
9666 // A valid resolved using typename decl points to exactly one type decl.
9667 assert(++Using->shadow_begin() == Using->shadow_end());
9668 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +00009669
John McCallb96ec562009-12-04 22:46:56 +00009670 } else {
9671 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
9672 "UnresolvedUsingTypenameDecl transformed to non-using decl");
9673 Ty = cast<UnresolvedUsingTypenameDecl>(D);
9674 }
9675
9676 return SemaRef.Context.getTypeDeclType(Ty);
9677}
9678
9679template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00009680QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
9681 SourceLocation Loc) {
9682 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009683}
9684
9685template<typename Derived>
9686QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
9687 return SemaRef.Context.getTypeOfType(Underlying);
9688}
9689
9690template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00009691QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
9692 SourceLocation Loc) {
9693 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009694}
9695
9696template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00009697QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
9698 UnaryTransformType::UTTKind UKind,
9699 SourceLocation Loc) {
9700 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
9701}
9702
9703template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00009704QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00009705 TemplateName Template,
9706 SourceLocation TemplateNameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +00009707 TemplateArgumentListInfo &TemplateArgs) {
John McCall6b51f282009-11-23 01:53:49 +00009708 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009709}
Mike Stump11289f42009-09-09 15:08:12 +00009710
Douglas Gregor1135c352009-08-06 05:28:30 +00009711template<typename Derived>
Eli Friedman0dfb8892011-10-06 23:00:33 +00009712QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
9713 SourceLocation KWLoc) {
9714 return SemaRef.BuildAtomicType(ValueType, KWLoc);
9715}
9716
9717template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009718TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00009719TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +00009720 bool TemplateKW,
9721 TemplateDecl *Template) {
Douglas Gregor9db53502011-03-02 18:07:45 +00009722 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00009723 Template);
9724}
9725
9726template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009727TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00009728TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
9729 const IdentifierInfo &Name,
9730 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +00009731 QualType ObjectType,
9732 NamedDecl *FirstQualifierInScope) {
Douglas Gregor9db53502011-03-02 18:07:45 +00009733 UnqualifiedId TemplateName;
9734 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregorbb119652010-06-16 23:00:59 +00009735 Sema::TemplateTy Template;
Abramo Bagnara7945c982012-01-27 09:46:47 +00009736 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregorbb119652010-06-16 23:00:59 +00009737 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009738 SS, TemplateKWLoc, TemplateName,
John McCallba7bf592010-08-24 05:47:05 +00009739 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00009740 /*EnteringContext=*/false,
9741 Template);
John McCall31f82722010-11-12 08:19:04 +00009742 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +00009743}
Mike Stump11289f42009-09-09 15:08:12 +00009744
Douglas Gregora16548e2009-08-11 05:31:07 +00009745template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00009746TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00009747TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +00009748 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +00009749 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +00009750 QualType ObjectType) {
Douglas Gregor71395fa2009-11-04 00:56:37 +00009751 UnqualifiedId Name;
Douglas Gregor9db53502011-03-02 18:07:45 +00009752 // FIXME: Bogus location information.
Abramo Bagnara7945c982012-01-27 09:46:47 +00009753 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregor9db53502011-03-02 18:07:45 +00009754 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnara7945c982012-01-27 09:46:47 +00009755 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregorbb119652010-06-16 23:00:59 +00009756 Sema::TemplateTy Template;
9757 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009758 SS, TemplateKWLoc, Name,
John McCallba7bf592010-08-24 05:47:05 +00009759 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00009760 /*EnteringContext=*/false,
9761 Template);
Serge Pavlov9ddb76e2013-08-27 13:15:56 +00009762 return Template.get();
Douglas Gregor71395fa2009-11-04 00:56:37 +00009763}
Chad Rosier1dcde962012-08-08 18:46:20 +00009764
Douglas Gregor71395fa2009-11-04 00:56:37 +00009765template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009766ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009767TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
9768 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00009769 Expr *OrigCallee,
9770 Expr *First,
9771 Expr *Second) {
9772 Expr *Callee = OrigCallee->IgnoreParenCasts();
9773 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00009774
Douglas Gregora16548e2009-08-11 05:31:07 +00009775 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00009776 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +00009777 if (!First->getType()->isOverloadableType() &&
9778 !Second->getType()->isOverloadableType())
9779 return getSema().CreateBuiltinArraySubscriptExpr(First,
9780 Callee->getLocStart(),
9781 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00009782 } else if (Op == OO_Arrow) {
9783 // -> is never a builtin operation.
John McCallb268a282010-08-23 23:25:46 +00009784 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
9785 } else if (Second == 0 || isPostIncDec) {
9786 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009787 // The argument is not of overloadable type, so try to create a
9788 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +00009789 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00009790 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00009791
John McCallb268a282010-08-23 23:25:46 +00009792 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00009793 }
9794 } else {
John McCallb268a282010-08-23 23:25:46 +00009795 if (!First->getType()->isOverloadableType() &&
9796 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009797 // Neither of the arguments is an overloadable type, so try to
9798 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +00009799 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00009800 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00009801 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +00009802 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009803 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009804
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009805 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00009806 }
9807 }
Mike Stump11289f42009-09-09 15:08:12 +00009808
9809 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00009810 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00009811 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00009812
John McCallb268a282010-08-23 23:25:46 +00009813 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +00009814 assert(ULE->requiresADL());
Richard Smith100b24a2014-04-17 01:52:14 +00009815 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00009816 } else {
Richard Smith58db83d2012-11-28 21:47:39 +00009817 // If we've resolved this to a particular non-member function, just call
9818 // that function. If we resolved it to a member function,
9819 // CreateOverloaded* will find that function for us.
9820 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
9821 if (!isa<CXXMethodDecl>(ND))
9822 Functions.addDecl(ND);
John McCalld14a8642009-11-21 08:51:07 +00009823 }
Mike Stump11289f42009-09-09 15:08:12 +00009824
Douglas Gregora16548e2009-08-11 05:31:07 +00009825 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +00009826 Expr *Args[2] = { First, Second };
9827 unsigned NumArgs = 1 + (Second != 0);
Mike Stump11289f42009-09-09 15:08:12 +00009828
Douglas Gregora16548e2009-08-11 05:31:07 +00009829 // Create the overloaded operator invocation for unary operators.
9830 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +00009831 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00009832 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +00009833 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00009834 }
Mike Stump11289f42009-09-09 15:08:12 +00009835
Douglas Gregore9d62932011-07-15 16:25:15 +00009836 if (Op == OO_Subscript) {
9837 SourceLocation LBrace;
9838 SourceLocation RBrace;
9839
9840 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
9841 DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
9842 LBrace = SourceLocation::getFromRawEncoding(
9843 NameLoc.CXXOperatorName.BeginOpNameLoc);
9844 RBrace = SourceLocation::getFromRawEncoding(
9845 NameLoc.CXXOperatorName.EndOpNameLoc);
9846 } else {
9847 LBrace = Callee->getLocStart();
9848 RBrace = OpLoc;
9849 }
9850
9851 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
9852 First, Second);
9853 }
Sebastian Redladba46e2009-10-29 20:17:01 +00009854
Douglas Gregora16548e2009-08-11 05:31:07 +00009855 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +00009856 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00009857 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00009858 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
9859 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009860 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009861
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009862 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00009863}
Mike Stump11289f42009-09-09 15:08:12 +00009864
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009865template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00009866ExprResult
John McCallb268a282010-08-23 23:25:46 +00009867TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009868 SourceLocation OperatorLoc,
9869 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +00009870 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009871 TypeSourceInfo *ScopeType,
9872 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00009873 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00009874 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +00009875 QualType BaseType = Base->getType();
9876 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009877 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier1dcde962012-08-08 18:46:20 +00009878 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +00009879 !BaseType->getAs<PointerType>()->getPointeeType()
9880 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009881 // This pseudo-destructor expression is still a pseudo-destructor.
John McCallb268a282010-08-23 23:25:46 +00009882 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009883 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00009884 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00009885 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009886 /*FIXME?*/true);
9887 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009888
Douglas Gregor678f90d2010-02-25 01:56:36 +00009889 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009890 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
9891 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
9892 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
9893 NameInfo.setNamedTypeInfo(DestroyedType);
9894
Richard Smith8e4a3862012-05-15 06:15:11 +00009895 // The scope type is now known to be a valid nested name specifier
9896 // component. Tack it on to the end of the nested name specifier.
9897 if (ScopeType)
9898 SS.Extend(SemaRef.Context, SourceLocation(),
9899 ScopeType->getTypeLoc(), CCLoc);
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009900
Abramo Bagnara7945c982012-01-27 09:46:47 +00009901 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCallb268a282010-08-23 23:25:46 +00009902 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009903 OperatorLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009904 SS, TemplateKWLoc,
9905 /*FIXME: FirstQualifier*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009906 NameInfo,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009907 /*TemplateArgs*/ 0);
9908}
9909
Tareq A. Siraj24110cc2013-04-16 18:53:08 +00009910template<typename Derived>
9911StmtResult
9912TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
Wei Pan17fbf6e2013-05-04 03:59:06 +00009913 SourceLocation Loc = S->getLocStart();
9914 unsigned NumParams = S->getCapturedDecl()->getNumParams();
9915 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/0,
9916 S->getCapturedRegionKind(), NumParams);
9917 StmtResult Body = getDerived().TransformStmt(S->getCapturedStmt());
9918
9919 if (Body.isInvalid()) {
9920 getSema().ActOnCapturedRegionError();
9921 return StmtError();
9922 }
9923
9924 return getSema().ActOnCapturedRegionEnd(Body.take());
Tareq A. Siraj24110cc2013-04-16 18:53:08 +00009925}
9926
Douglas Gregord6ff3322009-08-04 16:50:30 +00009927} // end namespace clang
9928
9929#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H