blob: ac5a678eeb1e9f9518e75eb04d9126845818796c [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"
Douglas Gregora16548e2009-08-11 05:31:07 +000028#include "clang/Lex/Preprocessor.h"
Chandler Carruth3a022472012-12-04 09:13:33 +000029#include "clang/Sema/Designator.h"
30#include "clang/Sema/Lookup.h"
31#include "clang/Sema/Ownership.h"
32#include "clang/Sema/ParsedTemplate.h"
33#include "clang/Sema/ScopeInfo.h"
34#include "clang/Sema/SemaDiagnostic.h"
35#include "clang/Sema/SemaInternal.h"
David Blaikieb9c168a2011-09-22 02:34:54 +000036#include "llvm/ADT/ArrayRef.h"
John McCall550e0c22009-10-21 00:40:46 +000037#include "llvm/Support/ErrorHandling.h"
Douglas Gregord6ff3322009-08-04 16:50:30 +000038#include <algorithm>
39
40namespace clang {
John McCallaab3e412010-08-25 08:40:02 +000041using namespace sema;
Mike Stump11289f42009-09-09 15:08:12 +000042
Douglas Gregord6ff3322009-08-04 16:50:30 +000043/// \brief A semantic tree transformation that allows one to transform one
44/// abstract syntax tree into another.
45///
Mike Stump11289f42009-09-09 15:08:12 +000046/// A new tree transformation is defined by creating a new subclass \c X of
47/// \c TreeTransform<X> and then overriding certain operations to provide
48/// behavior specific to that transformation. For example, template
Douglas Gregord6ff3322009-08-04 16:50:30 +000049/// instantiation is implemented as a tree transformation where the
50/// transformation of TemplateTypeParmType nodes involves substituting the
51/// template arguments for their corresponding template parameters; a similar
52/// transformation is performed for non-type template parameters and
53/// template template parameters.
54///
55/// This tree-transformation template uses static polymorphism to allow
Mike Stump11289f42009-09-09 15:08:12 +000056/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregord6ff3322009-08-04 16:50:30 +000057/// override any of the transformation or rebuild operators by providing an
58/// operation with the same signature as the default implementation. The
59/// overridding function should not be virtual.
60///
61/// Semantic tree transformations are split into two stages, either of which
62/// can be replaced by a subclass. The "transform" step transforms an AST node
63/// or the parts of an AST node using the various transformation functions,
64/// then passes the pieces on to the "rebuild" step, which constructs a new AST
65/// node of the appropriate kind from the pieces. The default transformation
66/// routines recursively transform the operands to composite AST nodes (e.g.,
67/// the pointee type of a PointerType node) and, if any of those operand nodes
68/// were changed by the transformation, invokes the rebuild operation to create
69/// a new AST node.
70///
Mike Stump11289f42009-09-09 15:08:12 +000071/// Subclasses can customize the transformation at various levels. The
Douglas Gregore922c772009-08-04 22:27:00 +000072/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregorfd35cde2011-03-02 18:50:38 +000073/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(),
Douglas Gregord6ff3322009-08-04 16:50:30 +000074/// TransformTemplateName(), or TransformTemplateArgument() with entirely
75/// new implementations.
76///
77/// For more fine-grained transformations, subclasses can replace any of the
78/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
Douglas Gregorebe10102009-08-20 07:17:43 +000079/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregord6ff3322009-08-04 16:50:30 +000080/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump11289f42009-09-09 15:08:12 +000081/// to substitute template arguments for their corresponding template
Douglas Gregord6ff3322009-08-04 16:50:30 +000082/// parameters. Additionally, subclasses can override the \c RebuildXXX
83/// functions to control how AST nodes are rebuilt when their operands change.
84/// By default, \c TreeTransform will invoke semantic analysis to rebuild
85/// AST nodes. However, certain other tree transformations (e.g, cloning) may
86/// be able to use more efficient rebuild steps.
87///
88/// There are a handful of other functions that can be overridden, allowing one
Mike Stump11289f42009-09-09 15:08:12 +000089/// to avoid traversing nodes that don't need any transformation
Douglas Gregord6ff3322009-08-04 16:50:30 +000090/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
91/// operands have not changed (\c AlwaysRebuild()), and customize the
92/// default locations and entity names used for type-checking
93/// (\c getBaseLocation(), \c getBaseEntity()).
Douglas Gregord6ff3322009-08-04 16:50:30 +000094template<typename Derived>
95class TreeTransform {
Douglas Gregora8bac7f2011-01-10 07:32:04 +000096 /// \brief Private RAII object that helps us forget and then re-remember
97 /// the template argument corresponding to a partially-substituted parameter
98 /// pack.
99 class ForgetPartiallySubstitutedPackRAII {
100 Derived &Self;
101 TemplateArgument Old;
Chad Rosier1dcde962012-08-08 18:46:20 +0000102
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000103 public:
104 ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) {
105 Old = Self.ForgetPartiallySubstitutedPack();
106 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000107
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000108 ~ForgetPartiallySubstitutedPackRAII() {
109 Self.RememberPartiallySubstitutedPack(Old);
110 }
111 };
Chad Rosier1dcde962012-08-08 18:46:20 +0000112
Douglas Gregord6ff3322009-08-04 16:50:30 +0000113protected:
114 Sema &SemaRef;
Chad Rosier1dcde962012-08-08 18:46:20 +0000115
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000116 /// \brief The set of local declarations that have been transformed, for
117 /// cases where we are forced to build new declarations within the transformer
118 /// rather than in the subclass (e.g., lambda closure types).
119 llvm::DenseMap<Decl *, Decl *> TransformedLocalDecls;
Chad Rosier1dcde962012-08-08 18:46:20 +0000120
Mike Stump11289f42009-09-09 15:08:12 +0000121public:
Douglas Gregord6ff3322009-08-04 16:50:30 +0000122 /// \brief Initializes a new tree transformer.
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000123 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump11289f42009-09-09 15:08:12 +0000124
Douglas Gregord6ff3322009-08-04 16:50:30 +0000125 /// \brief Retrieves a reference to the derived class.
126 Derived &getDerived() { return static_cast<Derived&>(*this); }
127
128 /// \brief Retrieves a reference to the derived class.
Mike Stump11289f42009-09-09 15:08:12 +0000129 const Derived &getDerived() const {
130 return static_cast<const Derived&>(*this);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000131 }
132
John McCalldadc5752010-08-24 06:29:42 +0000133 static inline ExprResult Owned(Expr *E) { return E; }
134 static inline StmtResult Owned(Stmt *S) { return S; }
John McCallb268a282010-08-23 23:25:46 +0000135
Douglas Gregord6ff3322009-08-04 16:50:30 +0000136 /// \brief Retrieves a reference to the semantic analysis object used for
137 /// this tree transform.
138 Sema &getSema() const { return SemaRef; }
Mike Stump11289f42009-09-09 15:08:12 +0000139
Douglas Gregord6ff3322009-08-04 16:50:30 +0000140 /// \brief Whether the transformation should always rebuild AST nodes, even
141 /// if none of the children have changed.
142 ///
143 /// Subclasses may override this function to specify when the transformation
144 /// should rebuild all AST nodes.
Richard Smith2aa81a72013-11-07 20:07:17 +0000145 ///
146 /// We must always rebuild all AST nodes when performing variadic template
147 /// pack expansion, in order to avoid violating the AST invariant that each
148 /// statement node appears at most once in its containing declaration.
149 bool AlwaysRebuild() { return SemaRef.ArgumentPackSubstitutionIndex != -1; }
Mike Stump11289f42009-09-09 15:08:12 +0000150
Douglas Gregord6ff3322009-08-04 16:50:30 +0000151 /// \brief Returns the location of the entity being transformed, if that
152 /// information was not available elsewhere in the AST.
153 ///
Mike Stump11289f42009-09-09 15:08:12 +0000154 /// By default, returns no source-location information. Subclasses can
Douglas Gregord6ff3322009-08-04 16:50:30 +0000155 /// provide an alternative implementation that provides better location
156 /// information.
157 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump11289f42009-09-09 15:08:12 +0000158
Douglas Gregord6ff3322009-08-04 16:50:30 +0000159 /// \brief Returns the name of the entity being transformed, if that
160 /// information was not available elsewhere in the AST.
161 ///
162 /// By default, returns an empty name. Subclasses can provide an alternative
163 /// implementation with a more precise name.
164 DeclarationName getBaseEntity() { return DeclarationName(); }
165
Douglas Gregora16548e2009-08-11 05:31:07 +0000166 /// \brief Sets the "base" location and entity when that
167 /// information is known based on another transformation.
168 ///
169 /// By default, the source location and entity are ignored. Subclasses can
170 /// override this function to provide a customized implementation.
171 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump11289f42009-09-09 15:08:12 +0000172
Douglas Gregora16548e2009-08-11 05:31:07 +0000173 /// \brief RAII object that temporarily sets the base location and entity
174 /// used for reporting diagnostics in types.
175 class TemporaryBase {
176 TreeTransform &Self;
177 SourceLocation OldLocation;
178 DeclarationName OldEntity;
Mike Stump11289f42009-09-09 15:08:12 +0000179
Douglas Gregora16548e2009-08-11 05:31:07 +0000180 public:
181 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump11289f42009-09-09 15:08:12 +0000182 DeclarationName Entity) : Self(Self) {
Douglas Gregora16548e2009-08-11 05:31:07 +0000183 OldLocation = Self.getDerived().getBaseLocation();
184 OldEntity = Self.getDerived().getBaseEntity();
Chad Rosier1dcde962012-08-08 18:46:20 +0000185
Douglas Gregora518d5b2011-01-25 17:51:48 +0000186 if (Location.isValid())
187 Self.getDerived().setBase(Location, Entity);
Douglas Gregora16548e2009-08-11 05:31:07 +0000188 }
Mike Stump11289f42009-09-09 15:08:12 +0000189
Douglas Gregora16548e2009-08-11 05:31:07 +0000190 ~TemporaryBase() {
191 Self.getDerived().setBase(OldLocation, OldEntity);
192 }
193 };
Mike Stump11289f42009-09-09 15:08:12 +0000194
195 /// \brief Determine whether the given type \p T has already been
Douglas Gregord6ff3322009-08-04 16:50:30 +0000196 /// transformed.
197 ///
198 /// Subclasses can provide an alternative implementation of this routine
Mike Stump11289f42009-09-09 15:08:12 +0000199 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregord6ff3322009-08-04 16:50:30 +0000200 /// not change. For example, template instantiation need not traverse
201 /// non-dependent types.
202 bool AlreadyTransformed(QualType T) {
203 return T.isNull();
204 }
205
Douglas Gregord196a582009-12-14 19:27:10 +0000206 /// \brief Determine whether the given call argument should be dropped, e.g.,
207 /// because it is a default argument.
208 ///
209 /// Subclasses can provide an alternative implementation of this routine to
210 /// determine which kinds of call arguments get dropped. By default,
211 /// CXXDefaultArgument nodes are dropped (prior to transformation).
212 bool DropCallArgument(Expr *E) {
213 return E->isDefaultArgument();
214 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000215
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000216 /// \brief Determine whether we should expand a pack expansion with the
217 /// given set of parameter packs into separate arguments by repeatedly
218 /// transforming the pattern.
219 ///
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000220 /// By default, the transformer never tries to expand pack expansions.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000221 /// Subclasses can override this routine to provide different behavior.
222 ///
223 /// \param EllipsisLoc The location of the ellipsis that identifies the
224 /// pack expansion.
225 ///
226 /// \param PatternRange The source range that covers the entire pattern of
227 /// the pack expansion.
228 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000229 /// \param Unexpanded The set of unexpanded parameter packs within the
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000230 /// pattern.
231 ///
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000232 /// \param ShouldExpand Will be set to \c true if the transformer should
233 /// expand the corresponding pack expansions into separate arguments. When
234 /// set, \c NumExpansions must also be set.
235 ///
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000236 /// \param RetainExpansion Whether the caller should add an unexpanded
237 /// pack expansion after all of the expanded arguments. This is used
238 /// when extending explicitly-specified template argument packs per
239 /// C++0x [temp.arg.explicit]p9.
240 ///
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000241 /// \param NumExpansions The number of separate arguments that will be in
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000242 /// the expanded form of the corresponding pack expansion. This is both an
243 /// input and an output parameter, which can be set by the caller if the
244 /// number of expansions is known a priori (e.g., due to a prior substitution)
245 /// and will be set by the callee when the number of expansions is known.
246 /// The callee must set this value when \c ShouldExpand is \c true; it may
247 /// set this value in other cases.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000248 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000249 /// \returns true if an error occurred (e.g., because the parameter packs
250 /// are to be instantiated with arguments of different lengths), false
251 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000252 /// must be set.
253 bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
254 SourceRange PatternRange,
Dmitri Gribenkof8579502013-01-12 19:30:44 +0000255 ArrayRef<UnexpandedParameterPack> Unexpanded,
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000256 bool &ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000257 bool &RetainExpansion,
David Blaikie05785d12013-02-20 22:23:23 +0000258 Optional<unsigned> &NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000259 ShouldExpand = false;
260 return false;
261 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000262
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000263 /// \brief "Forget" about the partially-substituted pack template argument,
264 /// when performing an instantiation that must preserve the parameter pack
265 /// use.
266 ///
267 /// This routine is meant to be overridden by the template instantiator.
268 TemplateArgument ForgetPartiallySubstitutedPack() {
269 return TemplateArgument();
270 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000271
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000272 /// \brief "Remember" the partially-substituted pack template argument
273 /// after performing an instantiation that must preserve the parameter pack
274 /// use.
275 ///
276 /// This routine is meant to be overridden by the template instantiator.
277 void RememberPartiallySubstitutedPack(TemplateArgument Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000278
Douglas Gregorf3010112011-01-07 16:43:16 +0000279 /// \brief Note to the derived class when a function parameter pack is
280 /// being expanded.
281 void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000282
Douglas Gregord6ff3322009-08-04 16:50:30 +0000283 /// \brief Transforms the given type into another type.
284 ///
John McCall550e0c22009-10-21 00:40:46 +0000285 /// By default, this routine transforms a type by creating a
John McCallbcd03502009-12-07 02:54:59 +0000286 /// TypeSourceInfo for it and delegating to the appropriate
John McCall550e0c22009-10-21 00:40:46 +0000287 /// function. This is expensive, but we don't mind, because
288 /// this method is deprecated anyway; all users should be
John McCallbcd03502009-12-07 02:54:59 +0000289 /// switched to storing TypeSourceInfos.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000290 ///
291 /// \returns the transformed type.
John McCall31f82722010-11-12 08:19:04 +0000292 QualType TransformType(QualType T);
Mike Stump11289f42009-09-09 15:08:12 +0000293
John McCall550e0c22009-10-21 00:40:46 +0000294 /// \brief Transforms the given type-with-location into a new
295 /// type-with-location.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000296 ///
John McCall550e0c22009-10-21 00:40:46 +0000297 /// By default, this routine transforms a type by delegating to the
298 /// appropriate TransformXXXType to build a new type. Subclasses
299 /// may override this function (to take over all type
300 /// transformations) or some set of the TransformXXXType functions
301 /// to alter the transformation.
John McCall31f82722010-11-12 08:19:04 +0000302 TypeSourceInfo *TransformType(TypeSourceInfo *DI);
John McCall550e0c22009-10-21 00:40:46 +0000303
304 /// \brief Transform the given type-with-location into a new
305 /// type, collecting location information in the given builder
306 /// as necessary.
307 ///
John McCall31f82722010-11-12 08:19:04 +0000308 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
Mike Stump11289f42009-09-09 15:08:12 +0000309
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000310 /// \brief Transform the given statement.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000311 ///
Mike Stump11289f42009-09-09 15:08:12 +0000312 /// By default, this routine transforms a statement by delegating to the
Douglas Gregorebe10102009-08-20 07:17:43 +0000313 /// appropriate TransformXXXStmt function to transform a specific kind of
314 /// statement or the TransformExpr() function to transform an expression.
315 /// Subclasses may override this function to transform statements using some
316 /// other mechanism.
317 ///
318 /// \returns the transformed statement.
John McCalldadc5752010-08-24 06:29:42 +0000319 StmtResult TransformStmt(Stmt *S);
Mike Stump11289f42009-09-09 15:08:12 +0000320
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000321 /// \brief Transform the given statement.
322 ///
323 /// By default, this routine transforms a statement by delegating to the
324 /// appropriate TransformOMPXXXClause function to transform a specific kind
325 /// of clause. Subclasses may override this function to transform statements
326 /// using some other mechanism.
327 ///
328 /// \returns the transformed OpenMP clause.
329 OMPClause *TransformOMPClause(OMPClause *S);
330
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000331 /// \brief Transform the given expression.
332 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000333 /// By default, this routine transforms an expression by delegating to the
334 /// appropriate TransformXXXExpr function to build a new expression.
335 /// Subclasses may override this function to transform expressions using some
336 /// other mechanism.
337 ///
338 /// \returns the transformed expression.
John McCalldadc5752010-08-24 06:29:42 +0000339 ExprResult TransformExpr(Expr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000340
Richard Smithd59b8322012-12-19 01:39:02 +0000341 /// \brief Transform the given initializer.
342 ///
343 /// By default, this routine transforms an initializer by stripping off the
344 /// semantic nodes added by initialization, then passing the result to
345 /// TransformExpr or TransformExprs.
346 ///
347 /// \returns the transformed initializer.
348 ExprResult TransformInitializer(Expr *Init, bool CXXDirectInit);
349
Douglas Gregora3efea12011-01-03 19:04:46 +0000350 /// \brief Transform the given list of expressions.
351 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000352 /// This routine transforms a list of expressions by invoking
353 /// \c TransformExpr() for each subexpression. However, it also provides
Douglas Gregora3efea12011-01-03 19:04:46 +0000354 /// support for variadic templates by expanding any pack expansions (if the
355 /// derived class permits such expansion) along the way. When pack expansions
356 /// are present, the number of outputs may not equal the number of inputs.
357 ///
358 /// \param Inputs The set of expressions to be transformed.
359 ///
360 /// \param NumInputs The number of expressions in \c Inputs.
361 ///
362 /// \param IsCall If \c true, then this transform is being performed on
Chad Rosier1dcde962012-08-08 18:46:20 +0000363 /// function-call arguments, and any arguments that should be dropped, will
Douglas Gregora3efea12011-01-03 19:04:46 +0000364 /// be.
365 ///
366 /// \param Outputs The transformed input expressions will be added to this
367 /// vector.
368 ///
369 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
370 /// due to transformation.
371 ///
372 /// \returns true if an error occurred, false otherwise.
373 bool TransformExprs(Expr **Inputs, unsigned NumInputs, bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +0000374 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregora3efea12011-01-03 19:04:46 +0000375 bool *ArgChanged = 0);
Chad Rosier1dcde962012-08-08 18:46:20 +0000376
Douglas Gregord6ff3322009-08-04 16:50:30 +0000377 /// \brief Transform the given declaration, which is referenced from a type
378 /// or expression.
379 ///
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000380 /// By default, acts as the identity function on declarations, unless the
381 /// transformer has had to transform the declaration itself. Subclasses
Douglas Gregor1135c352009-08-06 05:28:30 +0000382 /// may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000383 Decl *TransformDecl(SourceLocation Loc, Decl *D) {
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000384 llvm::DenseMap<Decl *, Decl *>::iterator Known
385 = TransformedLocalDecls.find(D);
386 if (Known != TransformedLocalDecls.end())
387 return Known->second;
Chad Rosier1dcde962012-08-08 18:46:20 +0000388
389 return D;
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000390 }
Douglas Gregorebe10102009-08-20 07:17:43 +0000391
Chad Rosier1dcde962012-08-08 18:46:20 +0000392 /// \brief Transform the attributes associated with the given declaration and
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000393 /// place them on the new declaration.
394 ///
395 /// By default, this operation does nothing. Subclasses may override this
396 /// behavior to transform attributes.
397 void transformAttrs(Decl *Old, Decl *New) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000398
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000399 /// \brief Note that a local declaration has been transformed by this
400 /// transformer.
401 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000402 /// Local declarations are typically transformed via a call to
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000403 /// TransformDefinition. However, in some cases (e.g., lambda expressions),
404 /// the transformer itself has to transform the declarations. This routine
405 /// can be overridden by a subclass that keeps track of such mappings.
406 void transformedLocalDecl(Decl *Old, Decl *New) {
407 TransformedLocalDecls[Old] = New;
408 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000409
Douglas Gregorebe10102009-08-20 07:17:43 +0000410 /// \brief Transform the definition of the given declaration.
411 ///
Mike Stump11289f42009-09-09 15:08:12 +0000412 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregorebe10102009-08-20 07:17:43 +0000413 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000414 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
415 return getDerived().TransformDecl(Loc, D);
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000416 }
Mike Stump11289f42009-09-09 15:08:12 +0000417
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000418 /// \brief Transform the given declaration, which was the first part of a
419 /// nested-name-specifier in a member access expression.
420 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000421 /// This specific declaration transformation only applies to the first
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000422 /// identifier in a nested-name-specifier of a member access expression, e.g.,
423 /// the \c T in \c x->T::member
424 ///
425 /// By default, invokes TransformDecl() to transform the declaration.
426 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000427 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
428 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000429 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000430
Douglas Gregor14454802011-02-25 02:25:35 +0000431 /// \brief Transform the given nested-name-specifier with source-location
432 /// information.
433 ///
434 /// By default, transforms all of the types and declarations within the
435 /// nested-name-specifier. Subclasses may override this function to provide
436 /// alternate behavior.
437 NestedNameSpecifierLoc TransformNestedNameSpecifierLoc(
438 NestedNameSpecifierLoc NNS,
439 QualType ObjectType = QualType(),
440 NamedDecl *FirstQualifierInScope = 0);
441
Douglas Gregorf816bd72009-09-03 22:13:48 +0000442 /// \brief Transform the given declaration name.
443 ///
444 /// By default, transforms the types of conversion function, constructor,
445 /// and destructor names and then (if needed) rebuilds the declaration name.
446 /// Identifiers and selectors are returned unmodified. Sublcasses may
447 /// override this function to provide alternate behavior.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000448 DeclarationNameInfo
John McCall31f82722010-11-12 08:19:04 +0000449 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump11289f42009-09-09 15:08:12 +0000450
Douglas Gregord6ff3322009-08-04 16:50:30 +0000451 /// \brief Transform the given template name.
Mike Stump11289f42009-09-09 15:08:12 +0000452 ///
Douglas Gregor9db53502011-03-02 18:07:45 +0000453 /// \param SS The nested-name-specifier that qualifies the template
454 /// name. This nested-name-specifier must already have been transformed.
455 ///
456 /// \param Name The template name to transform.
457 ///
458 /// \param NameLoc The source location of the template name.
459 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000460 /// \param ObjectType If we're translating a template name within a member
Douglas Gregor9db53502011-03-02 18:07:45 +0000461 /// access expression, this is the type of the object whose member template
462 /// is being referenced.
463 ///
464 /// \param FirstQualifierInScope If the first part of a nested-name-specifier
465 /// also refers to a name within the current (lexical) scope, this is the
466 /// declaration it refers to.
467 ///
468 /// By default, transforms the template name by transforming the declarations
469 /// and nested-name-specifiers that occur within the template name.
470 /// Subclasses may override this function to provide alternate behavior.
471 TemplateName TransformTemplateName(CXXScopeSpec &SS,
472 TemplateName Name,
Abramo Bagnara7945c982012-01-27 09:46:47 +0000473 SourceLocation NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +0000474 QualType ObjectType = QualType(),
475 NamedDecl *FirstQualifierInScope = 0);
476
Douglas Gregord6ff3322009-08-04 16:50:30 +0000477 /// \brief Transform the given template argument.
478 ///
Mike Stump11289f42009-09-09 15:08:12 +0000479 /// By default, this operation transforms the type, expression, or
480 /// declaration stored within the template argument and constructs a
Douglas Gregore922c772009-08-04 22:27:00 +0000481 /// new template argument from the transformed result. Subclasses may
482 /// override this function to provide alternate behavior.
John McCall0ad16662009-10-29 08:12:44 +0000483 ///
484 /// Returns true if there was an error.
485 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
486 TemplateArgumentLoc &Output);
487
Douglas Gregor62e06f22010-12-20 17:31:10 +0000488 /// \brief Transform the given set of template arguments.
489 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000490 /// By default, this operation transforms all of the template arguments
Douglas Gregor62e06f22010-12-20 17:31:10 +0000491 /// in the input set using \c TransformTemplateArgument(), and appends
492 /// the transformed arguments to the output list.
493 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000494 /// Note that this overload of \c TransformTemplateArguments() is merely
495 /// a convenience function. Subclasses that wish to override this behavior
496 /// should override the iterator-based member template version.
497 ///
Douglas Gregor62e06f22010-12-20 17:31:10 +0000498 /// \param Inputs The set of template arguments to be transformed.
499 ///
500 /// \param NumInputs The number of template arguments in \p Inputs.
501 ///
502 /// \param Outputs The set of transformed template arguments output by this
503 /// routine.
504 ///
505 /// Returns true if an error occurred.
506 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
507 unsigned NumInputs,
Douglas Gregorfe921a72010-12-20 23:36:19 +0000508 TemplateArgumentListInfo &Outputs) {
509 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs);
510 }
Douglas Gregor42cafa82010-12-20 17:42:22 +0000511
512 /// \brief Transform the given set of template arguments.
513 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000514 /// By default, this operation transforms all of the template arguments
Douglas Gregor42cafa82010-12-20 17:42:22 +0000515 /// in the input set using \c TransformTemplateArgument(), and appends
Chad Rosier1dcde962012-08-08 18:46:20 +0000516 /// the transformed arguments to the output list.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000517 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000518 /// \param First An iterator to the first template argument.
519 ///
520 /// \param Last An iterator one step past the last template argument.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000521 ///
522 /// \param Outputs The set of transformed template arguments output by this
523 /// routine.
524 ///
525 /// Returns true if an error occurred.
Douglas Gregorfe921a72010-12-20 23:36:19 +0000526 template<typename InputIterator>
527 bool TransformTemplateArguments(InputIterator First,
528 InputIterator Last,
529 TemplateArgumentListInfo &Outputs);
Douglas Gregor42cafa82010-12-20 17:42:22 +0000530
John McCall0ad16662009-10-29 08:12:44 +0000531 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
532 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
533 TemplateArgumentLoc &ArgLoc);
534
John McCallbcd03502009-12-07 02:54:59 +0000535 /// \brief Fakes up a TypeSourceInfo for a type.
536 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
537 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall0ad16662009-10-29 08:12:44 +0000538 getDerived().getBaseLocation());
539 }
Mike Stump11289f42009-09-09 15:08:12 +0000540
John McCall550e0c22009-10-21 00:40:46 +0000541#define ABSTRACT_TYPELOC(CLASS, PARENT)
542#define TYPELOC(CLASS, PARENT) \
John McCall31f82722010-11-12 08:19:04 +0000543 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCall550e0c22009-10-21 00:40:46 +0000544#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +0000545
Douglas Gregor3024f072012-04-16 07:05:22 +0000546 QualType TransformFunctionProtoType(TypeLocBuilder &TLB,
547 FunctionProtoTypeLoc TL,
548 CXXRecordDecl *ThisContext,
549 unsigned ThisTypeQuals);
550
David Majnemerfad8f482013-10-15 09:33:02 +0000551 StmtResult TransformSEHHandler(Stmt *Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +0000552
Chad Rosier1dcde962012-08-08 18:46:20 +0000553 QualType
John McCall31f82722010-11-12 08:19:04 +0000554 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
555 TemplateSpecializationTypeLoc TL,
556 TemplateName Template);
557
Chad Rosier1dcde962012-08-08 18:46:20 +0000558 QualType
John McCall31f82722010-11-12 08:19:04 +0000559 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
560 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +0000561 TemplateName Template,
562 CXXScopeSpec &SS);
Douglas Gregor5a064722011-02-28 17:23:35 +0000563
Chad Rosier1dcde962012-08-08 18:46:20 +0000564 QualType
Douglas Gregor5a064722011-02-28 17:23:35 +0000565 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
Douglas Gregora7a795b2011-03-01 20:11:18 +0000566 DependentTemplateSpecializationTypeLoc TL,
567 NestedNameSpecifierLoc QualifierLoc);
568
John McCall58f10c32010-03-11 09:03:00 +0000569 /// \brief Transforms the parameters of a function type into the
570 /// given vectors.
571 ///
572 /// The result vectors should be kept in sync; null entries in the
573 /// variables vector are acceptable.
574 ///
575 /// Return true on error.
Douglas Gregordd472162011-01-07 00:20:55 +0000576 bool TransformFunctionTypeParams(SourceLocation Loc,
577 ParmVarDecl **Params, unsigned NumParams,
578 const QualType *ParamTypes,
Chris Lattner01cf8db2011-07-20 06:58:45 +0000579 SmallVectorImpl<QualType> &PTypes,
580 SmallVectorImpl<ParmVarDecl*> *PVars);
John McCall58f10c32010-03-11 09:03:00 +0000581
582 /// \brief Transforms a single function-type parameter. Return null
583 /// on error.
John McCall8fb0d9d2011-05-01 22:35:37 +0000584 ///
585 /// \param indexAdjustment - A number to add to the parameter's
586 /// scope index; can be negative
Douglas Gregor715e4612011-01-14 22:40:04 +0000587 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +0000588 int indexAdjustment,
David Blaikie05785d12013-02-20 22:23:23 +0000589 Optional<unsigned> NumExpansions,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +0000590 bool ExpectParameterPack);
John McCall58f10c32010-03-11 09:03:00 +0000591
John McCall31f82722010-11-12 08:19:04 +0000592 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall0ad16662009-10-29 08:12:44 +0000593
John McCalldadc5752010-08-24 06:29:42 +0000594 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
595 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +0000596
597 typedef std::pair<ExprResult, QualType> InitCaptureInfoTy;
Richard Smith2589b9802012-07-25 03:56:55 +0000598 /// \brief Transform the captures and body of a lambda expression.
Faisal Vali5fb7c3c2013-12-05 01:40:41 +0000599 ExprResult TransformLambdaScope(LambdaExpr *E, CXXMethodDecl *CallOperator,
600 ArrayRef<InitCaptureInfoTy> InitCaptureExprsAndTypes);
Richard Smith2589b9802012-07-25 03:56:55 +0000601
Faisal Vali2cba1332013-10-23 06:44:28 +0000602 TemplateParameterList *TransformTemplateParameterList(
603 TemplateParameterList *TPL) {
604 return TPL;
605 }
606
Richard Smithdb2630f2012-10-21 03:28:35 +0000607 ExprResult TransformAddressOfOperand(Expr *E);
608 ExprResult TransformDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E,
609 bool IsAddressOfOperand);
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000610 StmtResult TransformOMPExecutableDirective(OMPExecutableDirective *S);
Richard Smithdb2630f2012-10-21 03:28:35 +0000611
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000612// FIXME: We use LLVM_ATTRIBUTE_NOINLINE because inlining causes a ridiculous
613// amount of stack usage with clang.
Douglas Gregorebe10102009-08-20 07:17:43 +0000614#define STMT(Node, Parent) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000615 LLVM_ATTRIBUTE_NOINLINE \
John McCalldadc5752010-08-24 06:29:42 +0000616 StmtResult Transform##Node(Node *S);
Douglas Gregora16548e2009-08-11 05:31:07 +0000617#define EXPR(Node, Parent) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000618 LLVM_ATTRIBUTE_NOINLINE \
John McCalldadc5752010-08-24 06:29:42 +0000619 ExprResult Transform##Node(Node *E);
Alexis Huntabb2ac82010-05-18 06:22:21 +0000620#define ABSTRACT_STMT(Stmt)
Alexis Hunt656bb312010-05-05 15:24:00 +0000621#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +0000622
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000623#define OPENMP_CLAUSE(Name, Class) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000624 LLVM_ATTRIBUTE_NOINLINE \
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000625 OMPClause *Transform ## Class(Class *S);
626#include "clang/Basic/OpenMPKinds.def"
627
Douglas Gregord6ff3322009-08-04 16:50:30 +0000628 /// \brief Build a new pointer type given its pointee type.
629 ///
630 /// By default, performs semantic analysis when building the pointer type.
631 /// Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000632 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000633
634 /// \brief Build a new block pointer type given its pointee type.
635 ///
Mike Stump11289f42009-09-09 15:08:12 +0000636 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000637 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000638 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000639
John McCall70dd5f62009-10-30 00:06:24 +0000640 /// \brief Build a new reference type given the type it references.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000641 ///
John McCall70dd5f62009-10-30 00:06:24 +0000642 /// By default, performs semantic analysis when building the
643 /// reference type. Subclasses may override this routine to provide
644 /// different behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000645 ///
John McCall70dd5f62009-10-30 00:06:24 +0000646 /// \param LValue whether the type was written with an lvalue sigil
647 /// or an rvalue sigil.
648 QualType RebuildReferenceType(QualType ReferentType,
649 bool LValue,
650 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000651
Douglas Gregord6ff3322009-08-04 16:50:30 +0000652 /// \brief Build a new member pointer type given the pointee type and the
653 /// class type it refers into.
654 ///
655 /// By default, performs semantic analysis when building the member pointer
656 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000657 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
658 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000659
Douglas Gregord6ff3322009-08-04 16:50:30 +0000660 /// \brief Build a new array type given the element type, size
661 /// modifier, size of the array (if known), size expression, and index type
662 /// qualifiers.
663 ///
664 /// By default, performs semantic analysis when building the array type.
665 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000666 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-08-04 16:50:30 +0000667 QualType RebuildArrayType(QualType ElementType,
668 ArrayType::ArraySizeModifier SizeMod,
669 const llvm::APInt *Size,
670 Expr *SizeExpr,
671 unsigned IndexTypeQuals,
672 SourceRange BracketsRange);
Mike Stump11289f42009-09-09 15:08:12 +0000673
Douglas Gregord6ff3322009-08-04 16:50:30 +0000674 /// \brief Build a new constant array type given the element type, size
675 /// modifier, (known) size of the array, and index type qualifiers.
676 ///
677 /// By default, performs semantic analysis when building the array type.
678 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000679 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000680 ArrayType::ArraySizeModifier SizeMod,
681 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +0000682 unsigned IndexTypeQuals,
683 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000684
Douglas Gregord6ff3322009-08-04 16:50:30 +0000685 /// \brief Build a new incomplete array type given the element type, size
686 /// modifier, and index type qualifiers.
687 ///
688 /// By default, performs semantic analysis when building the array type.
689 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000690 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000691 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +0000692 unsigned IndexTypeQuals,
693 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000694
Mike Stump11289f42009-09-09 15:08:12 +0000695 /// \brief Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000696 /// size modifier, size expression, and index type qualifiers.
697 ///
698 /// By default, performs semantic analysis when building the array type.
699 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000700 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000701 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000702 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000703 unsigned IndexTypeQuals,
704 SourceRange BracketsRange);
705
Mike Stump11289f42009-09-09 15:08:12 +0000706 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000707 /// size modifier, size expression, and index type qualifiers.
708 ///
709 /// By default, performs semantic analysis when building the array type.
710 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000711 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000712 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000713 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000714 unsigned IndexTypeQuals,
715 SourceRange BracketsRange);
716
717 /// \brief Build a new vector type given the element type and
718 /// number of elements.
719 ///
720 /// By default, performs semantic analysis when building the vector type.
721 /// Subclasses may override this routine to provide different behavior.
John Thompson22334602010-02-05 00:12:22 +0000722 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsonaeb56442010-11-10 21:56:12 +0000723 VectorType::VectorKind VecKind);
Mike Stump11289f42009-09-09 15:08:12 +0000724
Douglas Gregord6ff3322009-08-04 16:50:30 +0000725 /// \brief Build a new extended vector type given the element type and
726 /// number of elements.
727 ///
728 /// By default, performs semantic analysis when building the vector type.
729 /// Subclasses may override this routine to provide different behavior.
730 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
731 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000732
733 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000734 /// given the element type and number of elements.
735 ///
736 /// By default, performs semantic analysis when building the vector type.
737 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000738 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +0000739 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000740 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000741
Douglas Gregord6ff3322009-08-04 16:50:30 +0000742 /// \brief Build a new function type.
743 ///
744 /// By default, performs semantic analysis when building the function type.
745 /// Subclasses may override this routine to provide different behavior.
746 QualType RebuildFunctionProtoType(QualType T,
Jordan Rose5c382722013-03-08 21:51:21 +0000747 llvm::MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +0000748 const FunctionProtoType::ExtProtoInfo &EPI);
Mike Stump11289f42009-09-09 15:08:12 +0000749
John McCall550e0c22009-10-21 00:40:46 +0000750 /// \brief Build a new unprototyped function type.
751 QualType RebuildFunctionNoProtoType(QualType ResultType);
752
John McCallb96ec562009-12-04 22:46:56 +0000753 /// \brief Rebuild an unresolved typename type, given the decl that
754 /// the UnresolvedUsingTypenameDecl was transformed to.
755 QualType RebuildUnresolvedUsingType(Decl *D);
756
Douglas Gregord6ff3322009-08-04 16:50:30 +0000757 /// \brief Build a new typedef type.
Richard Smithdda56e42011-04-15 14:24:37 +0000758 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
Douglas Gregord6ff3322009-08-04 16:50:30 +0000759 return SemaRef.Context.getTypeDeclType(Typedef);
760 }
761
762 /// \brief Build a new class/struct/union type.
763 QualType RebuildRecordType(RecordDecl *Record) {
764 return SemaRef.Context.getTypeDeclType(Record);
765 }
766
767 /// \brief Build a new Enum type.
768 QualType RebuildEnumType(EnumDecl *Enum) {
769 return SemaRef.Context.getTypeDeclType(Enum);
770 }
John McCallfcc33b02009-09-05 00:15:47 +0000771
Mike Stump11289f42009-09-09 15:08:12 +0000772 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000773 ///
774 /// By default, performs semantic analysis when building the typeof type.
775 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000776 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000777
Mike Stump11289f42009-09-09 15:08:12 +0000778 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000779 ///
780 /// By default, builds a new TypeOfType with the given underlying type.
781 QualType RebuildTypeOfType(QualType Underlying);
782
Alexis Hunte852b102011-05-24 22:41:36 +0000783 /// \brief Build a new unary transform type.
784 QualType RebuildUnaryTransformType(QualType BaseType,
785 UnaryTransformType::UTTKind UKind,
786 SourceLocation Loc);
787
Richard Smith74aeef52013-04-26 16:15:35 +0000788 /// \brief Build a new C++11 decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000789 ///
790 /// By default, performs semantic analysis when building the decltype type.
791 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000792 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump11289f42009-09-09 15:08:12 +0000793
Richard Smith74aeef52013-04-26 16:15:35 +0000794 /// \brief Build a new C++11 auto type.
Richard Smith30482bc2011-02-20 03:19:35 +0000795 ///
796 /// By default, builds a new AutoType with the given deduced type.
Richard Smith74aeef52013-04-26 16:15:35 +0000797 QualType RebuildAutoType(QualType Deduced, bool IsDecltypeAuto) {
Richard Smith27d807c2013-04-30 13:56:41 +0000798 // Note, IsDependent is always false here: we implicitly convert an 'auto'
799 // which has been deduced to a dependent type into an undeduced 'auto', so
800 // that we'll retry deduction after the transformation.
Faisal Vali2b391ab2013-09-26 19:54:12 +0000801 return SemaRef.Context.getAutoType(Deduced, IsDecltypeAuto,
802 /*IsDependent*/ false);
Richard Smith30482bc2011-02-20 03:19:35 +0000803 }
804
Douglas Gregord6ff3322009-08-04 16:50:30 +0000805 /// \brief Build a new template specialization type.
806 ///
807 /// By default, performs semantic analysis when building the template
808 /// specialization type. Subclasses may override this routine to provide
809 /// different behavior.
810 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000811 SourceLocation TemplateLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000812 TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000813
Abramo Bagnara924a8f32010-12-10 16:29:40 +0000814 /// \brief Build a new parenthesized type.
815 ///
816 /// By default, builds a new ParenType type from the inner type.
817 /// Subclasses may override this routine to provide different behavior.
818 QualType RebuildParenType(QualType InnerType) {
819 return SemaRef.Context.getParenType(InnerType);
820 }
821
Douglas Gregord6ff3322009-08-04 16:50:30 +0000822 /// \brief Build a new qualified name type.
823 ///
Abramo Bagnara6150c882010-05-11 21:36:43 +0000824 /// By default, builds a new ElaboratedType type from the keyword,
825 /// the nested-name-specifier and the named type.
826 /// Subclasses may override this routine to provide different behavior.
John McCall954b5de2010-11-04 19:04:38 +0000827 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
828 ElaboratedTypeKeyword Keyword,
Douglas Gregor844cb502011-03-01 18:12:44 +0000829 NestedNameSpecifierLoc QualifierLoc,
830 QualType Named) {
Chad Rosier1dcde962012-08-08 18:46:20 +0000831 return SemaRef.Context.getElaboratedType(Keyword,
832 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor844cb502011-03-01 18:12:44 +0000833 Named);
Mike Stump11289f42009-09-09 15:08:12 +0000834 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000835
836 /// \brief Build a new typename type that refers to a template-id.
837 ///
Abramo Bagnarad7548482010-05-19 21:37:53 +0000838 /// By default, builds a new DependentNameType type from the
839 /// nested-name-specifier and the given type. Subclasses may override
840 /// this routine to provide different behavior.
John McCallc392f372010-06-11 00:33:02 +0000841 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregora7a795b2011-03-01 20:11:18 +0000842 ElaboratedTypeKeyword Keyword,
843 NestedNameSpecifierLoc QualifierLoc,
844 const IdentifierInfo *Name,
845 SourceLocation NameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000846 TemplateArgumentListInfo &Args) {
Douglas Gregora7a795b2011-03-01 20:11:18 +0000847 // Rebuild the template name.
848 // TODO: avoid TemplateName abstraction
Douglas Gregor9db53502011-03-02 18:07:45 +0000849 CXXScopeSpec SS;
850 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +0000851 TemplateName InstName
Douglas Gregor9db53502011-03-02 18:07:45 +0000852 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(), 0);
Chad Rosier1dcde962012-08-08 18:46:20 +0000853
Douglas Gregora7a795b2011-03-01 20:11:18 +0000854 if (InstName.isNull())
855 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +0000856
Douglas Gregora7a795b2011-03-01 20:11:18 +0000857 // If it's still dependent, make a dependent specialization.
858 if (InstName.getAsDependentTemplateName())
Chad Rosier1dcde962012-08-08 18:46:20 +0000859 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
860 QualifierLoc.getNestedNameSpecifier(),
861 Name,
Douglas Gregora7a795b2011-03-01 20:11:18 +0000862 Args);
Chad Rosier1dcde962012-08-08 18:46:20 +0000863
Douglas Gregora7a795b2011-03-01 20:11:18 +0000864 // Otherwise, make an elaborated type wrapping a non-dependent
865 // specialization.
866 QualType T =
867 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
868 if (T.isNull()) return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +0000869
Douglas Gregora7a795b2011-03-01 20:11:18 +0000870 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == 0)
871 return T;
Chad Rosier1dcde962012-08-08 18:46:20 +0000872
873 return SemaRef.Context.getElaboratedType(Keyword,
874 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregora7a795b2011-03-01 20:11:18 +0000875 T);
876 }
877
Douglas Gregord6ff3322009-08-04 16:50:30 +0000878 /// \brief Build a new typename type that refers to an identifier.
879 ///
880 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarad7548482010-05-19 21:37:53 +0000881 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000882 /// different behavior.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000883 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000884 SourceLocation KeywordLoc,
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000885 NestedNameSpecifierLoc QualifierLoc,
886 const IdentifierInfo *Id,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000887 SourceLocation IdLoc) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000888 CXXScopeSpec SS;
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000889 SS.Adopt(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +0000890
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000891 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000892 // If the name is still dependent, just build a new dependent name type.
893 if (!SemaRef.computeDeclContext(SS))
Chad Rosier1dcde962012-08-08 18:46:20 +0000894 return SemaRef.Context.getDependentNameType(Keyword,
895 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000896 Id);
Douglas Gregore677daf2010-03-31 22:19:08 +0000897 }
898
Abramo Bagnara6150c882010-05-11 21:36:43 +0000899 if (Keyword == ETK_None || Keyword == ETK_Typename)
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000900 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
Douglas Gregor9cbc22b2011-02-28 22:42:13 +0000901 *Id, IdLoc);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000902
903 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
904
Abramo Bagnarad7548482010-05-19 21:37:53 +0000905 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregore677daf2010-03-31 22:19:08 +0000906 // into a non-dependent elaborated-type-specifier. Find the tag we're
907 // referring to.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000908 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregore677daf2010-03-31 22:19:08 +0000909 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
910 if (!DC)
911 return QualType();
912
John McCallbf8c5192010-05-27 06:40:31 +0000913 if (SemaRef.RequireCompleteDeclContext(SS, DC))
914 return QualType();
915
Douglas Gregore677daf2010-03-31 22:19:08 +0000916 TagDecl *Tag = 0;
917 SemaRef.LookupQualifiedName(Result, DC);
918 switch (Result.getResultKind()) {
919 case LookupResult::NotFound:
920 case LookupResult::NotFoundInCurrentInstantiation:
921 break;
Chad Rosier1dcde962012-08-08 18:46:20 +0000922
Douglas Gregore677daf2010-03-31 22:19:08 +0000923 case LookupResult::Found:
924 Tag = Result.getAsSingle<TagDecl>();
925 break;
Chad Rosier1dcde962012-08-08 18:46:20 +0000926
Douglas Gregore677daf2010-03-31 22:19:08 +0000927 case LookupResult::FoundOverloaded:
928 case LookupResult::FoundUnresolvedValue:
929 llvm_unreachable("Tag lookup cannot find non-tags");
Chad Rosier1dcde962012-08-08 18:46:20 +0000930
Douglas Gregore677daf2010-03-31 22:19:08 +0000931 case LookupResult::Ambiguous:
932 // Let the LookupResult structure handle ambiguities.
933 return QualType();
934 }
935
936 if (!Tag) {
Nick Lewycky0c438082011-01-24 19:01:04 +0000937 // Check where the name exists but isn't a tag type and use that to emit
938 // better diagnostics.
939 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
940 SemaRef.LookupQualifiedName(Result, DC);
941 switch (Result.getResultKind()) {
942 case LookupResult::Found:
943 case LookupResult::FoundOverloaded:
944 case LookupResult::FoundUnresolvedValue: {
Richard Smith3f1b5d02011-05-05 21:57:07 +0000945 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
Nick Lewycky0c438082011-01-24 19:01:04 +0000946 unsigned Kind = 0;
947 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
Richard Smithdda56e42011-04-15 14:24:37 +0000948 else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2;
949 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3;
Nick Lewycky0c438082011-01-24 19:01:04 +0000950 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
951 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
952 break;
Richard Smith3f1b5d02011-05-05 21:57:07 +0000953 }
Nick Lewycky0c438082011-01-24 19:01:04 +0000954 default:
955 // FIXME: Would be nice to highlight just the source range.
956 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
957 << Kind << Id << DC;
958 break;
959 }
Douglas Gregore677daf2010-03-31 22:19:08 +0000960 return QualType();
961 }
Abramo Bagnara6150c882010-05-11 21:36:43 +0000962
Richard Trieucaa33d32011-06-10 03:11:26 +0000963 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
964 IdLoc, *Id)) {
Abramo Bagnarad7548482010-05-19 21:37:53 +0000965 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregore677daf2010-03-31 22:19:08 +0000966 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
967 return QualType();
968 }
969
970 // Build the elaborated-type-specifier type.
971 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Chad Rosier1dcde962012-08-08 18:46:20 +0000972 return SemaRef.Context.getElaboratedType(Keyword,
973 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000974 T);
Douglas Gregor1135c352009-08-06 05:28:30 +0000975 }
Mike Stump11289f42009-09-09 15:08:12 +0000976
Douglas Gregor822d0302011-01-12 17:07:58 +0000977 /// \brief Build a new pack expansion type.
978 ///
979 /// By default, builds a new PackExpansionType type from the given pattern.
980 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000981 QualType RebuildPackExpansionType(QualType Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +0000982 SourceRange PatternRange,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000983 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +0000984 Optional<unsigned> NumExpansions) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000985 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
986 NumExpansions);
Douglas Gregor822d0302011-01-12 17:07:58 +0000987 }
988
Eli Friedman0dfb8892011-10-06 23:00:33 +0000989 /// \brief Build a new atomic type given its value type.
990 ///
991 /// By default, performs semantic analysis when building the atomic type.
992 /// Subclasses may override this routine to provide different behavior.
993 QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
994
Douglas Gregor71dc5092009-08-06 06:41:21 +0000995 /// \brief Build a new template name given a nested name specifier, a flag
996 /// indicating whether the "template" keyword was provided, and the template
997 /// that the template name refers to.
998 ///
999 /// By default, builds the new template name directly. Subclasses may override
1000 /// this routine to provide different behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001001 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +00001002 bool TemplateKW,
1003 TemplateDecl *Template);
1004
Douglas Gregor71dc5092009-08-06 06:41:21 +00001005 /// \brief Build a new template name given a nested name specifier and the
1006 /// name that is referred to as a template.
1007 ///
1008 /// By default, performs semantic analysis to determine whether the name can
1009 /// be resolved to a specific template, then builds the appropriate kind of
1010 /// template name. Subclasses may override this routine to provide different
1011 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001012 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
1013 const IdentifierInfo &Name,
1014 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +00001015 QualType ObjectType,
1016 NamedDecl *FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00001017
Douglas Gregor71395fa2009-11-04 00:56:37 +00001018 /// \brief Build a new template name given a nested name specifier and the
1019 /// overloaded operator name that is referred to as a template.
1020 ///
1021 /// By default, performs semantic analysis to determine whether the name can
1022 /// be resolved to a specific template, then builds the appropriate kind of
1023 /// template name. Subclasses may override this routine to provide different
1024 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001025 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +00001026 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +00001027 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +00001028 QualType ObjectType);
Douglas Gregor5590be02011-01-15 06:45:20 +00001029
1030 /// \brief Build a new template name given a template template parameter pack
Chad Rosier1dcde962012-08-08 18:46:20 +00001031 /// and the
Douglas Gregor5590be02011-01-15 06:45:20 +00001032 ///
1033 /// By default, performs semantic analysis to determine whether the name can
1034 /// be resolved to a specific template, then builds the appropriate kind of
1035 /// template name. Subclasses may override this routine to provide different
1036 /// behavior.
1037 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
1038 const TemplateArgument &ArgPack) {
1039 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
1040 }
1041
Douglas Gregorebe10102009-08-20 07:17:43 +00001042 /// \brief Build a new compound statement.
1043 ///
1044 /// By default, performs semantic analysis to build the new statement.
1045 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001046 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001047 MultiStmtArg Statements,
1048 SourceLocation RBraceLoc,
1049 bool IsStmtExpr) {
John McCallb268a282010-08-23 23:25:46 +00001050 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00001051 IsStmtExpr);
1052 }
1053
1054 /// \brief Build a new case statement.
1055 ///
1056 /// By default, performs semantic analysis to build the new statement.
1057 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001058 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCallb268a282010-08-23 23:25:46 +00001059 Expr *LHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001060 SourceLocation EllipsisLoc,
John McCallb268a282010-08-23 23:25:46 +00001061 Expr *RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001062 SourceLocation ColonLoc) {
John McCallb268a282010-08-23 23:25:46 +00001063 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001064 ColonLoc);
1065 }
Mike Stump11289f42009-09-09 15:08:12 +00001066
Douglas Gregorebe10102009-08-20 07:17:43 +00001067 /// \brief Attach the body to a new case statement.
1068 ///
1069 /// By default, performs semantic analysis to build the new statement.
1070 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001071 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001072 getSema().ActOnCaseStmtBody(S, Body);
1073 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00001074 }
Mike Stump11289f42009-09-09 15:08:12 +00001075
Douglas Gregorebe10102009-08-20 07:17:43 +00001076 /// \brief Build a new default statement.
1077 ///
1078 /// By default, performs semantic analysis to build the new statement.
1079 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001080 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001081 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +00001082 Stmt *SubStmt) {
1083 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregorebe10102009-08-20 07:17:43 +00001084 /*CurScope=*/0);
1085 }
Mike Stump11289f42009-09-09 15:08:12 +00001086
Douglas Gregorebe10102009-08-20 07:17:43 +00001087 /// \brief Build a new label statement.
1088 ///
1089 /// By default, performs semantic analysis to build the new statement.
1090 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001091 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1092 SourceLocation ColonLoc, Stmt *SubStmt) {
1093 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregorebe10102009-08-20 07:17:43 +00001094 }
Mike Stump11289f42009-09-09 15:08:12 +00001095
Richard Smithc202b282012-04-14 00:33:13 +00001096 /// \brief Build a new label statement.
1097 ///
1098 /// By default, performs semantic analysis to build the new statement.
1099 /// Subclasses may override this routine to provide different behavior.
Alexander Kornienko20f6fc62012-07-09 10:04:07 +00001100 StmtResult RebuildAttributedStmt(SourceLocation AttrLoc,
1101 ArrayRef<const Attr*> Attrs,
Richard Smithc202b282012-04-14 00:33:13 +00001102 Stmt *SubStmt) {
1103 return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt);
1104 }
1105
Douglas Gregorebe10102009-08-20 07:17:43 +00001106 /// \brief Build a new "if" statement.
1107 ///
1108 /// By default, performs semantic analysis to build the new statement.
1109 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001110 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Chad Rosier1dcde962012-08-08 18:46:20 +00001111 VarDecl *CondVar, Stmt *Then,
Chris Lattnercab02a62011-02-17 20:34:02 +00001112 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00001113 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregorebe10102009-08-20 07:17:43 +00001114 }
Mike Stump11289f42009-09-09 15:08:12 +00001115
Douglas Gregorebe10102009-08-20 07:17:43 +00001116 /// \brief Start building a new switch statement.
1117 ///
1118 /// By default, performs semantic analysis to build the new statement.
1119 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001120 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001121 Expr *Cond, VarDecl *CondVar) {
Chad Rosier1dcde962012-08-08 18:46:20 +00001122 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCall48871652010-08-21 09:40:31 +00001123 CondVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00001124 }
Mike Stump11289f42009-09-09 15:08:12 +00001125
Douglas Gregorebe10102009-08-20 07:17:43 +00001126 /// \brief Attach the body to the switch statement.
1127 ///
1128 /// By default, performs semantic analysis to build the new statement.
1129 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001130 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001131 Stmt *Switch, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001132 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001133 }
1134
1135 /// \brief Build a new while statement.
1136 ///
1137 /// By default, performs semantic analysis to build the new statement.
1138 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001139 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1140 VarDecl *CondVar, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001141 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001142 }
Mike Stump11289f42009-09-09 15:08:12 +00001143
Douglas Gregorebe10102009-08-20 07:17:43 +00001144 /// \brief Build a new do-while statement.
1145 ///
1146 /// By default, performs semantic analysis to build the new statement.
1147 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001148 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001149 SourceLocation WhileLoc, SourceLocation LParenLoc,
1150 Expr *Cond, SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001151 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1152 Cond, RParenLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001153 }
1154
1155 /// \brief Build a new for statement.
1156 ///
1157 /// By default, performs semantic analysis to build the new statement.
1158 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001159 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
Chad Rosier1dcde962012-08-08 18:46:20 +00001160 Stmt *Init, Sema::FullExprArg Cond,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001161 VarDecl *CondVar, Sema::FullExprArg Inc,
1162 SourceLocation RParenLoc, Stmt *Body) {
Chad Rosier1dcde962012-08-08 18:46:20 +00001163 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001164 CondVar, Inc, RParenLoc, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001165 }
Mike Stump11289f42009-09-09 15:08:12 +00001166
Douglas Gregorebe10102009-08-20 07:17:43 +00001167 /// \brief Build a new goto statement.
1168 ///
1169 /// By default, performs semantic analysis to build the new statement.
1170 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001171 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1172 LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001173 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregorebe10102009-08-20 07:17:43 +00001174 }
1175
1176 /// \brief Build a new indirect goto statement.
1177 ///
1178 /// By default, performs semantic analysis to build the new statement.
1179 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001180 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001181 SourceLocation StarLoc,
1182 Expr *Target) {
John McCallb268a282010-08-23 23:25:46 +00001183 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregorebe10102009-08-20 07:17:43 +00001184 }
Mike Stump11289f42009-09-09 15:08:12 +00001185
Douglas Gregorebe10102009-08-20 07:17:43 +00001186 /// \brief Build a new return statement.
1187 ///
1188 /// By default, performs semantic analysis to build the new statement.
1189 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001190 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
John McCallb268a282010-08-23 23:25:46 +00001191 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregorebe10102009-08-20 07:17:43 +00001192 }
Mike Stump11289f42009-09-09 15:08:12 +00001193
Douglas Gregorebe10102009-08-20 07:17:43 +00001194 /// \brief Build a new declaration statement.
1195 ///
1196 /// By default, performs semantic analysis to build the new statement.
1197 /// Subclasses may override this routine to provide different behavior.
Rafael Espindolaab417692013-07-09 12:05:01 +00001198 StmtResult RebuildDeclStmt(llvm::MutableArrayRef<Decl *> Decls,
1199 SourceLocation StartLoc, SourceLocation EndLoc) {
1200 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls);
Richard Smith2abf6762011-02-23 00:37:57 +00001201 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001202 }
Mike Stump11289f42009-09-09 15:08:12 +00001203
Anders Carlssonaaeef072010-01-24 05:50:09 +00001204 /// \brief Build a new inline asm statement.
1205 ///
1206 /// By default, performs semantic analysis to build the new statement.
1207 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001208 StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
1209 bool IsVolatile, unsigned NumOutputs,
1210 unsigned NumInputs, IdentifierInfo **Names,
1211 MultiExprArg Constraints, MultiExprArg Exprs,
1212 Expr *AsmString, MultiExprArg Clobbers,
1213 SourceLocation RParenLoc) {
1214 return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1215 NumInputs, Names, Constraints, Exprs,
1216 AsmString, Clobbers, RParenLoc);
Anders Carlssonaaeef072010-01-24 05:50:09 +00001217 }
Douglas Gregor306de2f2010-04-22 23:59:56 +00001218
Chad Rosier32503022012-06-11 20:47:18 +00001219 /// \brief Build a new MS style inline asm statement.
1220 ///
1221 /// By default, performs semantic analysis to build the new statement.
1222 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001223 StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc,
John McCallf413f5e2013-05-03 00:10:13 +00001224 ArrayRef<Token> AsmToks,
1225 StringRef AsmString,
1226 unsigned NumOutputs, unsigned NumInputs,
1227 ArrayRef<StringRef> Constraints,
1228 ArrayRef<StringRef> Clobbers,
1229 ArrayRef<Expr*> Exprs,
1230 SourceLocation EndLoc) {
1231 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString,
1232 NumOutputs, NumInputs,
1233 Constraints, Clobbers, Exprs, EndLoc);
Chad Rosier32503022012-06-11 20:47:18 +00001234 }
1235
James Dennett2a4d13c2012-06-15 07:13:21 +00001236 /// \brief Build a new Objective-C \@try statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001237 ///
1238 /// By default, performs semantic analysis to build the new statement.
1239 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001240 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001241 Stmt *TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +00001242 MultiStmtArg CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001243 Stmt *Finally) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001244 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001245 Finally);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001246 }
1247
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001248 /// \brief Rebuild an Objective-C exception declaration.
1249 ///
1250 /// By default, performs semantic analysis to build the new declaration.
1251 /// Subclasses may override this routine to provide different behavior.
1252 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1253 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaradff19302011-03-08 08:55:46 +00001254 return getSema().BuildObjCExceptionDecl(TInfo, T,
1255 ExceptionDecl->getInnerLocStart(),
1256 ExceptionDecl->getLocation(),
1257 ExceptionDecl->getIdentifier());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001258 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001259
James Dennett2a4d13c2012-06-15 07:13:21 +00001260 /// \brief Build a new Objective-C \@catch statement.
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001261 ///
1262 /// By default, performs semantic analysis to build the new statement.
1263 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001264 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001265 SourceLocation RParenLoc,
1266 VarDecl *Var,
John McCallb268a282010-08-23 23:25:46 +00001267 Stmt *Body) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001268 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001269 Var, Body);
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001270 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001271
James Dennett2a4d13c2012-06-15 07:13:21 +00001272 /// \brief Build a new Objective-C \@finally statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001273 ///
1274 /// By default, performs semantic analysis to build the new statement.
1275 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001276 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001277 Stmt *Body) {
1278 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001279 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001280
James Dennett2a4d13c2012-06-15 07:13:21 +00001281 /// \brief Build a new Objective-C \@throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +00001282 ///
1283 /// By default, performs semantic analysis to build the new statement.
1284 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001285 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001286 Expr *Operand) {
1287 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregor2900c162010-04-22 21:44:01 +00001288 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001289
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001290 /// \brief Build a new OpenMP executable directive.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001291 ///
1292 /// By default, performs semantic analysis to build the new statement.
1293 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001294 StmtResult RebuildOMPExecutableDirective(OpenMPDirectiveKind Kind,
1295 ArrayRef<OMPClause *> Clauses,
1296 Stmt *AStmt,
1297 SourceLocation StartLoc,
1298 SourceLocation EndLoc) {
1299 return getSema().ActOnOpenMPExecutableDirective(Kind, Clauses, AStmt,
1300 StartLoc, EndLoc);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001301 }
1302
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001303 /// \brief Build a new OpenMP 'if' clause.
1304 ///
1305 /// By default, performs semantic analysis to build the new statement.
1306 /// Subclasses may override this routine to provide different behavior.
1307 OMPClause *RebuildOMPIfClause(Expr *Condition,
1308 SourceLocation StartLoc,
1309 SourceLocation LParenLoc,
1310 SourceLocation EndLoc) {
1311 return getSema().ActOnOpenMPIfClause(Condition, StartLoc,
1312 LParenLoc, EndLoc);
1313 }
1314
Alexey Bataev568a8332014-03-06 06:15:19 +00001315 /// \brief Build a new OpenMP 'num_threads' clause.
1316 ///
1317 /// By default, performs semantic analysis to build the new statement.
1318 /// Subclasses may override this routine to provide different behavior.
1319 OMPClause *RebuildOMPNumThreadsClause(Expr *NumThreads,
1320 SourceLocation StartLoc,
1321 SourceLocation LParenLoc,
1322 SourceLocation EndLoc) {
1323 return getSema().ActOnOpenMPNumThreadsClause(NumThreads, StartLoc,
1324 LParenLoc, EndLoc);
1325 }
1326
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001327 /// \brief Build a new OpenMP 'default' clause.
1328 ///
1329 /// By default, performs semantic analysis to build the new statement.
1330 /// Subclasses may override this routine to provide different behavior.
1331 OMPClause *RebuildOMPDefaultClause(OpenMPDefaultClauseKind Kind,
1332 SourceLocation KindKwLoc,
1333 SourceLocation StartLoc,
1334 SourceLocation LParenLoc,
1335 SourceLocation EndLoc) {
1336 return getSema().ActOnOpenMPDefaultClause(Kind, KindKwLoc,
1337 StartLoc, LParenLoc, EndLoc);
1338 }
1339
1340 /// \brief Build a new OpenMP 'private' clause.
1341 ///
1342 /// By default, performs semantic analysis to build the new statement.
1343 /// Subclasses may override this routine to provide different behavior.
1344 OMPClause *RebuildOMPPrivateClause(ArrayRef<Expr *> VarList,
1345 SourceLocation StartLoc,
1346 SourceLocation LParenLoc,
1347 SourceLocation EndLoc) {
1348 return getSema().ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc,
1349 EndLoc);
1350 }
1351
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001352 /// \brief Build a new OpenMP 'firstprivate' clause.
1353 ///
1354 /// By default, performs semantic analysis to build the new statement.
1355 /// Subclasses may override this routine to provide different behavior.
1356 OMPClause *RebuildOMPFirstprivateClause(ArrayRef<Expr *> VarList,
1357 SourceLocation StartLoc,
1358 SourceLocation LParenLoc,
1359 SourceLocation EndLoc) {
1360 return getSema().ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc,
1361 EndLoc);
1362 }
1363
Alexey Bataev758e55e2013-09-06 18:03:48 +00001364 OMPClause *RebuildOMPSharedClause(ArrayRef<Expr *> VarList,
1365 SourceLocation StartLoc,
1366 SourceLocation LParenLoc,
1367 SourceLocation EndLoc) {
1368 return getSema().ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc,
1369 EndLoc);
1370 }
1371
James Dennett2a4d13c2012-06-15 07:13:21 +00001372 /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
John McCalld9bb7432011-07-27 21:50:02 +00001373 ///
1374 /// By default, performs semantic analysis to build the new statement.
1375 /// Subclasses may override this routine to provide different behavior.
1376 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1377 Expr *object) {
1378 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1379 }
1380
James Dennett2a4d13c2012-06-15 07:13:21 +00001381 /// \brief Build a new Objective-C \@synchronized statement.
Douglas Gregor6148de72010-04-22 22:01:21 +00001382 ///
Douglas Gregor6148de72010-04-22 22:01:21 +00001383 /// By default, performs semantic analysis to build the new statement.
1384 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001385 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCalld9bb7432011-07-27 21:50:02 +00001386 Expr *Object, Stmt *Body) {
1387 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor6148de72010-04-22 22:01:21 +00001388 }
Douglas Gregorf68a5082010-04-22 23:10:45 +00001389
James Dennett2a4d13c2012-06-15 07:13:21 +00001390 /// \brief Build a new Objective-C \@autoreleasepool statement.
John McCall31168b02011-06-15 23:02:42 +00001391 ///
1392 /// By default, performs semantic analysis to build the new statement.
1393 /// Subclasses may override this routine to provide different behavior.
1394 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1395 Stmt *Body) {
1396 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1397 }
John McCall53848232011-07-27 01:07:15 +00001398
Douglas Gregorf68a5082010-04-22 23:10:45 +00001399 /// \brief Build a new Objective-C fast enumeration statement.
1400 ///
1401 /// By default, performs semantic analysis to build the new statement.
1402 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001403 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001404 Stmt *Element,
1405 Expr *Collection,
1406 SourceLocation RParenLoc,
1407 Stmt *Body) {
Sam Panzer2c4ca0f2012-08-16 21:47:25 +00001408 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001409 Element,
John McCallb268a282010-08-23 23:25:46 +00001410 Collection,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001411 RParenLoc);
1412 if (ForEachStmt.isInvalid())
1413 return StmtError();
1414
1415 return getSema().FinishObjCForCollectionStmt(ForEachStmt.take(), Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +00001416 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001417
Douglas Gregorebe10102009-08-20 07:17:43 +00001418 /// \brief Build a new C++ exception declaration.
1419 ///
1420 /// By default, performs semantic analysis to build the new decaration.
1421 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaradff19302011-03-08 08:55:46 +00001422 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +00001423 TypeSourceInfo *Declarator,
Abramo Bagnaradff19302011-03-08 08:55:46 +00001424 SourceLocation StartLoc,
1425 SourceLocation IdLoc,
1426 IdentifierInfo *Id) {
Douglas Gregor40965fa2011-04-14 22:32:28 +00001427 VarDecl *Var = getSema().BuildExceptionDeclaration(0, Declarator,
1428 StartLoc, IdLoc, Id);
1429 if (Var)
1430 getSema().CurContext->addDecl(Var);
1431 return Var;
Douglas Gregorebe10102009-08-20 07:17:43 +00001432 }
1433
1434 /// \brief Build a new C++ catch statement.
1435 ///
1436 /// By default, performs semantic analysis to build the new statement.
1437 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001438 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001439 VarDecl *ExceptionDecl,
1440 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00001441 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1442 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00001443 }
Mike Stump11289f42009-09-09 15:08:12 +00001444
Douglas Gregorebe10102009-08-20 07:17:43 +00001445 /// \brief Build a new C++ try statement.
1446 ///
1447 /// By default, performs semantic analysis to build the new statement.
1448 /// Subclasses may override this routine to provide different behavior.
Robert Wilhelmcafda822013-08-22 09:20:03 +00001449 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock,
1450 ArrayRef<Stmt *> Handlers) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001451 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00001452 }
Mike Stump11289f42009-09-09 15:08:12 +00001453
Richard Smith02e85f32011-04-14 22:09:26 +00001454 /// \brief Build a new C++0x range-based for statement.
1455 ///
1456 /// By default, performs semantic analysis to build the new statement.
1457 /// Subclasses may override this routine to provide different behavior.
1458 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1459 SourceLocation ColonLoc,
1460 Stmt *Range, Stmt *BeginEnd,
1461 Expr *Cond, Expr *Inc,
1462 Stmt *LoopVar,
1463 SourceLocation RParenLoc) {
Douglas Gregorf7106af2013-04-08 18:40:13 +00001464 // If we've just learned that the range is actually an Objective-C
1465 // collection, treat this as an Objective-C fast enumeration loop.
1466 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
1467 if (RangeStmt->isSingleDecl()) {
1468 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
Douglas Gregor39aaeef2013-05-02 18:35:56 +00001469 if (RangeVar->isInvalidDecl())
1470 return StmtError();
1471
Douglas Gregorf7106af2013-04-08 18:40:13 +00001472 Expr *RangeExpr = RangeVar->getInit();
1473 if (!RangeExpr->isTypeDependent() &&
1474 RangeExpr->getType()->isObjCObjectPointerType())
1475 return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, RangeExpr,
1476 RParenLoc);
1477 }
1478 }
1479 }
1480
Richard Smith02e85f32011-04-14 22:09:26 +00001481 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
Richard Smitha05b3b52012-09-20 21:52:32 +00001482 Cond, Inc, LoopVar, RParenLoc,
1483 Sema::BFRK_Rebuild);
Richard Smith02e85f32011-04-14 22:09:26 +00001484 }
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001485
1486 /// \brief Build a new C++0x range-based for statement.
1487 ///
1488 /// By default, performs semantic analysis to build the new statement.
1489 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00001490 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001491 bool IsIfExists,
1492 NestedNameSpecifierLoc QualifierLoc,
1493 DeclarationNameInfo NameInfo,
1494 Stmt *Nested) {
1495 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1496 QualifierLoc, NameInfo, Nested);
1497 }
1498
Richard Smith02e85f32011-04-14 22:09:26 +00001499 /// \brief Attach body to a C++0x range-based for statement.
1500 ///
1501 /// By default, performs semantic analysis to finish the new statement.
1502 /// Subclasses may override this routine to provide different behavior.
1503 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1504 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1505 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001506
David Majnemerfad8f482013-10-15 09:33:02 +00001507 StmtResult RebuildSEHTryStmt(bool IsCXXTry, SourceLocation TryLoc,
1508 Stmt *TryBlock, Stmt *Handler) {
1509 return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +00001510 }
1511
David Majnemerfad8f482013-10-15 09:33:02 +00001512 StmtResult RebuildSEHExceptStmt(SourceLocation Loc, Expr *FilterExpr,
John Wiegley1c0675e2011-04-28 01:08:34 +00001513 Stmt *Block) {
David Majnemerfad8f482013-10-15 09:33:02 +00001514 return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001515 }
1516
David Majnemerfad8f482013-10-15 09:33:02 +00001517 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, Stmt *Block) {
1518 return getSema().ActOnSEHFinallyBlock(Loc, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001519 }
1520
Douglas Gregora16548e2009-08-11 05:31:07 +00001521 /// \brief Build a new expression that references a declaration.
1522 ///
1523 /// By default, performs semantic analysis to build the new expression.
1524 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001525 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00001526 LookupResult &R,
1527 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00001528 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1529 }
1530
1531
1532 /// \brief Build a new expression that references a declaration.
1533 ///
1534 /// By default, performs semantic analysis to build the new expression.
1535 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorea972d32011-02-28 21:54:11 +00001536 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001537 ValueDecl *VD,
1538 const DeclarationNameInfo &NameInfo,
1539 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001540 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001541 SS.Adopt(QualifierLoc);
John McCallce546572009-12-08 09:08:17 +00001542
1543 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001544
1545 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001546 }
Mike Stump11289f42009-09-09 15:08:12 +00001547
Douglas Gregora16548e2009-08-11 05:31:07 +00001548 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001549 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001550 /// By default, performs semantic analysis to build the new expression.
1551 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001552 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00001553 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00001554 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001555 }
1556
Douglas Gregorad8a3362009-09-04 17:36:40 +00001557 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001558 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001559 /// By default, performs semantic analysis to build the new expression.
1560 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001561 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora6ce6082011-02-25 18:19:59 +00001562 SourceLocation OperatorLoc,
1563 bool isArrow,
1564 CXXScopeSpec &SS,
1565 TypeSourceInfo *ScopeType,
1566 SourceLocation CCLoc,
1567 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001568 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001569
Douglas Gregora16548e2009-08-11 05:31:07 +00001570 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001571 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001572 /// By default, performs semantic analysis to build the new expression.
1573 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001574 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001575 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001576 Expr *SubExpr) {
1577 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001578 }
Mike Stump11289f42009-09-09 15:08:12 +00001579
Douglas Gregor882211c2010-04-28 22:16:22 +00001580 /// \brief Build a new builtin offsetof expression.
1581 ///
1582 /// By default, performs semantic analysis to build the new expression.
1583 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001584 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor882211c2010-04-28 22:16:22 +00001585 TypeSourceInfo *Type,
John McCallfaf5fb42010-08-26 23:41:50 +00001586 Sema::OffsetOfComponent *Components,
Douglas Gregor882211c2010-04-28 22:16:22 +00001587 unsigned NumComponents,
1588 SourceLocation RParenLoc) {
1589 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1590 NumComponents, RParenLoc);
1591 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001592
1593 /// \brief Build a new sizeof, alignof or vec_step expression with a
Peter Collingbournee190dee2011-03-11 19:24:49 +00001594 /// type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001595 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001596 /// By default, performs semantic analysis to build the new expression.
1597 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001598 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1599 SourceLocation OpLoc,
1600 UnaryExprOrTypeTrait ExprKind,
1601 SourceRange R) {
1602 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001603 }
1604
Peter Collingbournee190dee2011-03-11 19:24:49 +00001605 /// \brief Build a new sizeof, alignof or vec step expression with an
1606 /// expression argument.
Mike Stump11289f42009-09-09 15:08:12 +00001607 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001608 /// By default, performs semantic analysis to build the new expression.
1609 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001610 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1611 UnaryExprOrTypeTrait ExprKind,
1612 SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00001613 ExprResult Result
Chandler Carrutha923fb22011-05-29 07:32:14 +00001614 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregora16548e2009-08-11 05:31:07 +00001615 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001616 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001617
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001618 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001619 }
Mike Stump11289f42009-09-09 15:08:12 +00001620
Douglas Gregora16548e2009-08-11 05:31:07 +00001621 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001622 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001623 /// By default, performs semantic analysis to build the new expression.
1624 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001625 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001626 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00001627 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001628 SourceLocation RBracketLoc) {
John McCallb268a282010-08-23 23:25:46 +00001629 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1630 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001631 RBracketLoc);
1632 }
1633
1634 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00001635 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001636 /// By default, performs semantic analysis to build the new expression.
1637 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001638 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001639 MultiExprArg Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00001640 SourceLocation RParenLoc,
1641 Expr *ExecConfig = 0) {
John McCallb268a282010-08-23 23:25:46 +00001642 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001643 Args, RParenLoc, ExecConfig);
Douglas Gregora16548e2009-08-11 05:31:07 +00001644 }
1645
1646 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001647 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001648 /// By default, performs semantic analysis to build the new expression.
1649 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001650 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001651 bool isArrow,
Douglas Gregorea972d32011-02-28 21:54:11 +00001652 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001653 SourceLocation TemplateKWLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001654 const DeclarationNameInfo &MemberNameInfo,
1655 ValueDecl *Member,
1656 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001657 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00001658 NamedDecl *FirstQualifierInScope) {
Richard Smithcab9a7d2011-10-26 19:06:56 +00001659 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
1660 isArrow);
Anders Carlsson5da84842009-09-01 04:26:58 +00001661 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00001662 // We have a reference to an unnamed field. This is always the
1663 // base of an anonymous struct/union member access, i.e. the
1664 // field is always of record type.
Douglas Gregorea972d32011-02-28 21:54:11 +00001665 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCall7decc9e2010-11-18 06:31:45 +00001666 assert(Member->getType()->isRecordType() &&
1667 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00001668
Richard Smithcab9a7d2011-10-26 19:06:56 +00001669 BaseResult =
1670 getSema().PerformObjectMemberConversion(BaseResult.take(),
John Wiegley01296292011-04-08 18:41:53 +00001671 QualifierLoc.getNestedNameSpecifier(),
1672 FoundDecl, Member);
1673 if (BaseResult.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001674 return ExprError();
John Wiegley01296292011-04-08 18:41:53 +00001675 Base = BaseResult.take();
John McCall7decc9e2010-11-18 06:31:45 +00001676 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump11289f42009-09-09 15:08:12 +00001677 MemberExpr *ME =
John McCallb268a282010-08-23 23:25:46 +00001678 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001679 Member, MemberNameInfo,
John McCall7decc9e2010-11-18 06:31:45 +00001680 cast<FieldDecl>(Member)->getType(),
1681 VK, OK_Ordinary);
Anders Carlsson5da84842009-09-01 04:26:58 +00001682 return getSema().Owned(ME);
1683 }
Mike Stump11289f42009-09-09 15:08:12 +00001684
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001685 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001686 SS.Adopt(QualifierLoc);
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001687
John Wiegley01296292011-04-08 18:41:53 +00001688 Base = BaseResult.take();
John McCallb268a282010-08-23 23:25:46 +00001689 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00001690
John McCall16df1e52010-03-30 21:47:33 +00001691 // FIXME: this involves duplicating earlier analysis in a lot of
1692 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001693 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001694 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001695 R.resolveKind();
1696
John McCallb268a282010-08-23 23:25:46 +00001697 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001698 SS, TemplateKWLoc,
1699 FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001700 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001701 }
Mike Stump11289f42009-09-09 15:08:12 +00001702
Douglas Gregora16548e2009-08-11 05:31:07 +00001703 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001704 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001705 /// By default, performs semantic analysis to build the new expression.
1706 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001707 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001708 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001709 Expr *LHS, Expr *RHS) {
1710 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001711 }
1712
1713 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001714 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001715 /// By default, performs semantic analysis to build the new expression.
1716 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001717 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCallc07a0c72011-02-17 10:25:35 +00001718 SourceLocation QuestionLoc,
1719 Expr *LHS,
1720 SourceLocation ColonLoc,
1721 Expr *RHS) {
John McCallb268a282010-08-23 23:25:46 +00001722 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1723 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001724 }
1725
Douglas Gregora16548e2009-08-11 05:31:07 +00001726 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001727 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001728 /// By default, performs semantic analysis to build the new expression.
1729 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001730 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00001731 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001732 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001733 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001734 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001735 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001736 }
Mike Stump11289f42009-09-09 15:08:12 +00001737
Douglas Gregora16548e2009-08-11 05:31:07 +00001738 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001739 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001740 /// By default, performs semantic analysis to build the new expression.
1741 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001742 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001743 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001744 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001745 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001746 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001747 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001748 }
Mike Stump11289f42009-09-09 15:08:12 +00001749
Douglas Gregora16548e2009-08-11 05:31:07 +00001750 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001751 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001752 /// By default, performs semantic analysis to build the new expression.
1753 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001754 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001755 SourceLocation OpLoc,
1756 SourceLocation AccessorLoc,
1757 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001758
John McCall10eae182009-11-30 22:42:35 +00001759 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001760 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00001761 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00001762 OpLoc, /*IsArrow*/ false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001763 SS, SourceLocation(),
1764 /*FirstQualifierInScope*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001765 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00001766 /* TemplateArgs */ 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00001767 }
Mike Stump11289f42009-09-09 15:08:12 +00001768
Douglas Gregora16548e2009-08-11 05:31:07 +00001769 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001770 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001771 /// By default, performs semantic analysis to build the new expression.
1772 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001773 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCall542e7c62011-07-06 07:30:07 +00001774 MultiExprArg Inits,
1775 SourceLocation RBraceLoc,
1776 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00001777 ExprResult Result
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001778 = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
Douglas Gregord3d93062009-11-09 17:16:50 +00001779 if (Result.isInvalid() || ResultTy->isDependentType())
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001780 return Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00001781
Douglas Gregord3d93062009-11-09 17:16:50 +00001782 // Patch in the result type we were given, which may have been computed
1783 // when the initial InitListExpr was built.
1784 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1785 ILE->setType(ResultTy);
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001786 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001787 }
Mike Stump11289f42009-09-09 15:08:12 +00001788
Douglas Gregora16548e2009-08-11 05:31:07 +00001789 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001790 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001791 /// By default, performs semantic analysis to build the new expression.
1792 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001793 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00001794 MultiExprArg ArrayExprs,
1795 SourceLocation EqualOrColonLoc,
1796 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001797 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00001798 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001799 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001800 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001801 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001802 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001803
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001804 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001805 }
Mike Stump11289f42009-09-09 15:08:12 +00001806
Douglas Gregora16548e2009-08-11 05:31:07 +00001807 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001808 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001809 /// By default, builds the implicit value initialization without performing
1810 /// any semantic analysis. Subclasses may override this routine to provide
1811 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001812 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001813 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1814 }
Mike Stump11289f42009-09-09 15:08:12 +00001815
Douglas Gregora16548e2009-08-11 05:31:07 +00001816 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001817 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001818 /// By default, performs semantic analysis to build the new expression.
1819 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001820 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001821 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001822 SourceLocation RParenLoc) {
1823 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001824 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001825 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001826 }
1827
1828 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001829 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001830 /// By default, performs semantic analysis to build the new expression.
1831 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001832 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redla9351792012-02-11 23:51:47 +00001833 MultiExprArg SubExprs,
1834 SourceLocation RParenLoc) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001835 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001836 }
Mike Stump11289f42009-09-09 15:08:12 +00001837
Douglas Gregora16548e2009-08-11 05:31:07 +00001838 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001839 ///
1840 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00001841 /// rather than attempting to map the label statement itself.
1842 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001843 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001844 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001845 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregora16548e2009-08-11 05:31:07 +00001846 }
Mike Stump11289f42009-09-09 15:08:12 +00001847
Douglas Gregora16548e2009-08-11 05:31:07 +00001848 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00001849 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001850 /// By default, performs semantic analysis to build the new expression.
1851 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001852 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001853 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00001854 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001855 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001856 }
Mike Stump11289f42009-09-09 15:08:12 +00001857
Douglas Gregora16548e2009-08-11 05:31:07 +00001858 /// \brief Build a new __builtin_choose_expr expression.
1859 ///
1860 /// By default, performs semantic analysis to build the new expression.
1861 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001862 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001863 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001864 SourceLocation RParenLoc) {
1865 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001866 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001867 RParenLoc);
1868 }
Mike Stump11289f42009-09-09 15:08:12 +00001869
Peter Collingbourne91147592011-04-15 00:35:48 +00001870 /// \brief Build a new generic selection expression.
1871 ///
1872 /// By default, performs semantic analysis to build the new expression.
1873 /// Subclasses may override this routine to provide different behavior.
1874 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
1875 SourceLocation DefaultLoc,
1876 SourceLocation RParenLoc,
1877 Expr *ControllingExpr,
Dmitri Gribenko82360372013-05-10 13:06:58 +00001878 ArrayRef<TypeSourceInfo *> Types,
1879 ArrayRef<Expr *> Exprs) {
Peter Collingbourne91147592011-04-15 00:35:48 +00001880 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
Dmitri Gribenko82360372013-05-10 13:06:58 +00001881 ControllingExpr, Types, Exprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00001882 }
1883
Douglas Gregora16548e2009-08-11 05:31:07 +00001884 /// \brief Build a new overloaded operator call expression.
1885 ///
1886 /// By default, performs semantic analysis to build the new expression.
1887 /// The semantic analysis provides the behavior of template instantiation,
1888 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00001889 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00001890 /// argument-dependent lookup, etc. Subclasses may override this routine to
1891 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001892 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00001893 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00001894 Expr *Callee,
1895 Expr *First,
1896 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00001897
1898 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00001899 /// reinterpret_cast.
1900 ///
1901 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00001902 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00001903 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001904 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001905 Stmt::StmtClass Class,
1906 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001907 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001908 SourceLocation RAngleLoc,
1909 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001910 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001911 SourceLocation RParenLoc) {
1912 switch (Class) {
1913 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001914 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001915 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001916 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001917
1918 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001919 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001920 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001921 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001922
Douglas Gregora16548e2009-08-11 05:31:07 +00001923 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001924 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001925 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001926 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001927 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001928
Douglas Gregora16548e2009-08-11 05:31:07 +00001929 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001930 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001931 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001932 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001933
Douglas Gregora16548e2009-08-11 05:31:07 +00001934 default:
David Blaikie83d382b2011-09-23 05:06:16 +00001935 llvm_unreachable("Invalid C++ named cast");
Douglas Gregora16548e2009-08-11 05:31:07 +00001936 }
Douglas Gregora16548e2009-08-11 05:31:07 +00001937 }
Mike Stump11289f42009-09-09 15:08:12 +00001938
Douglas Gregora16548e2009-08-11 05:31:07 +00001939 /// \brief Build a new C++ static_cast expression.
1940 ///
1941 /// By default, performs semantic analysis to build the new expression.
1942 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001943 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001944 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001945 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001946 SourceLocation RAngleLoc,
1947 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001948 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001949 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001950 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00001951 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001952 SourceRange(LAngleLoc, RAngleLoc),
1953 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001954 }
1955
1956 /// \brief Build a new C++ dynamic_cast expression.
1957 ///
1958 /// By default, performs semantic analysis to build the new expression.
1959 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001960 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001961 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001962 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001963 SourceLocation RAngleLoc,
1964 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001965 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001966 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001967 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00001968 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001969 SourceRange(LAngleLoc, RAngleLoc),
1970 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001971 }
1972
1973 /// \brief Build a new C++ reinterpret_cast expression.
1974 ///
1975 /// By default, performs semantic analysis to build the new expression.
1976 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001977 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001978 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001979 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001980 SourceLocation RAngleLoc,
1981 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001982 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001983 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001984 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00001985 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001986 SourceRange(LAngleLoc, RAngleLoc),
1987 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001988 }
1989
1990 /// \brief Build a new C++ const_cast expression.
1991 ///
1992 /// By default, performs semantic analysis to build the new expression.
1993 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001994 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001995 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001996 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001997 SourceLocation RAngleLoc,
1998 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001999 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002000 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002001 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00002002 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002003 SourceRange(LAngleLoc, RAngleLoc),
2004 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002005 }
Mike Stump11289f42009-09-09 15:08:12 +00002006
Douglas Gregora16548e2009-08-11 05:31:07 +00002007 /// \brief Build a new C++ functional-style cast expression.
2008 ///
2009 /// By default, performs semantic analysis to build the new expression.
2010 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002011 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
2012 SourceLocation LParenLoc,
2013 Expr *Sub,
2014 SourceLocation RParenLoc) {
2015 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00002016 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00002017 RParenLoc);
2018 }
Mike Stump11289f42009-09-09 15:08:12 +00002019
Douglas Gregora16548e2009-08-11 05:31:07 +00002020 /// \brief Build a new C++ typeid(type) expression.
2021 ///
2022 /// By default, performs semantic analysis to build the new expression.
2023 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002024 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002025 SourceLocation TypeidLoc,
2026 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002027 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002028 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002029 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002030 }
Mike Stump11289f42009-09-09 15:08:12 +00002031
Francois Pichet9f4f2072010-09-08 12:20:18 +00002032
Douglas Gregora16548e2009-08-11 05:31:07 +00002033 /// \brief Build a new C++ typeid(expr) expression.
2034 ///
2035 /// By default, performs semantic analysis to build the new expression.
2036 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002037 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002038 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00002039 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002040 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002041 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002042 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002043 }
2044
Francois Pichet9f4f2072010-09-08 12:20:18 +00002045 /// \brief Build a new C++ __uuidof(type) expression.
2046 ///
2047 /// By default, performs semantic analysis to build the new expression.
2048 /// Subclasses may override this routine to provide different behavior.
2049 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2050 SourceLocation TypeidLoc,
2051 TypeSourceInfo *Operand,
2052 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002053 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
Francois Pichet9f4f2072010-09-08 12:20:18 +00002054 RParenLoc);
2055 }
2056
2057 /// \brief Build a new C++ __uuidof(expr) expression.
2058 ///
2059 /// By default, performs semantic analysis to build the new expression.
2060 /// Subclasses may override this routine to provide different behavior.
2061 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2062 SourceLocation TypeidLoc,
2063 Expr *Operand,
2064 SourceLocation RParenLoc) {
2065 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
2066 RParenLoc);
2067 }
2068
Douglas Gregora16548e2009-08-11 05:31:07 +00002069 /// \brief Build a new C++ "this" expression.
2070 ///
2071 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00002072 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00002073 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002074 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00002075 QualType ThisType,
2076 bool isImplicit) {
Eli Friedman20139d32012-01-11 02:36:31 +00002077 getSema().CheckCXXThisCapture(ThisLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002078 return getSema().Owned(
Douglas Gregorb15af892010-01-07 23:12:05 +00002079 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
2080 isImplicit));
Douglas Gregora16548e2009-08-11 05:31:07 +00002081 }
2082
2083 /// \brief Build a new C++ throw expression.
2084 ///
2085 /// By default, performs semantic analysis to build the new expression.
2086 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor53e191ed2011-07-06 22:04:06 +00002087 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
2088 bool IsThrownVariableInScope) {
2089 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00002090 }
2091
2092 /// \brief Build a new C++ default-argument expression.
2093 ///
2094 /// By default, builds a new default-argument expression, which does not
2095 /// require any semantic analysis. Subclasses may override this routine to
2096 /// provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002097 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00002098 ParmVarDecl *Param) {
2099 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
2100 Param));
Douglas Gregora16548e2009-08-11 05:31:07 +00002101 }
2102
Richard Smith852c9db2013-04-20 22:23:05 +00002103 /// \brief Build a new C++11 default-initialization expression.
2104 ///
2105 /// By default, builds a new default field initialization expression, which
2106 /// does not require any semantic analysis. Subclasses may override this
2107 /// routine to provide different behavior.
2108 ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc,
2109 FieldDecl *Field) {
2110 return getSema().Owned(CXXDefaultInitExpr::Create(getSema().Context, Loc,
2111 Field));
2112 }
2113
Douglas Gregora16548e2009-08-11 05:31:07 +00002114 /// \brief Build a new C++ zero-initialization expression.
2115 ///
2116 /// By default, performs semantic analysis to build the new expression.
2117 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002118 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
2119 SourceLocation LParenLoc,
2120 SourceLocation RParenLoc) {
2121 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002122 None, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002123 }
Mike Stump11289f42009-09-09 15:08:12 +00002124
Douglas Gregora16548e2009-08-11 05:31:07 +00002125 /// \brief Build a new C++ "new" expression.
2126 ///
2127 /// By default, performs semantic analysis to build the new expression.
2128 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002129 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002130 bool UseGlobal,
2131 SourceLocation PlacementLParen,
2132 MultiExprArg PlacementArgs,
2133 SourceLocation PlacementRParen,
2134 SourceRange TypeIdParens,
2135 QualType AllocatedType,
2136 TypeSourceInfo *AllocatedTypeInfo,
2137 Expr *ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002138 SourceRange DirectInitRange,
2139 Expr *Initializer) {
Mike Stump11289f42009-09-09 15:08:12 +00002140 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00002141 PlacementLParen,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002142 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00002143 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00002144 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002145 AllocatedType,
2146 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00002147 ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002148 DirectInitRange,
2149 Initializer);
Douglas Gregora16548e2009-08-11 05:31:07 +00002150 }
Mike Stump11289f42009-09-09 15:08:12 +00002151
Douglas Gregora16548e2009-08-11 05:31:07 +00002152 /// \brief Build a new C++ "delete" expression.
2153 ///
2154 /// By default, performs semantic analysis to build the new expression.
2155 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002156 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002157 bool IsGlobalDelete,
2158 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002159 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002160 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002161 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00002162 }
Mike Stump11289f42009-09-09 15:08:12 +00002163
Douglas Gregor29c42f22012-02-24 07:38:34 +00002164 /// \brief Build a new type trait expression.
2165 ///
2166 /// By default, performs semantic analysis to build the new expression.
2167 /// Subclasses may override this routine to provide different behavior.
2168 ExprResult RebuildTypeTrait(TypeTrait Trait,
2169 SourceLocation StartLoc,
2170 ArrayRef<TypeSourceInfo *> Args,
2171 SourceLocation RParenLoc) {
2172 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2173 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002174
John Wiegley6242b6a2011-04-28 00:16:57 +00002175 /// \brief Build a new array type trait expression.
2176 ///
2177 /// By default, performs semantic analysis to build the new expression.
2178 /// Subclasses may override this routine to provide different behavior.
2179 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2180 SourceLocation StartLoc,
2181 TypeSourceInfo *TSInfo,
2182 Expr *DimExpr,
2183 SourceLocation RParenLoc) {
2184 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2185 }
2186
John Wiegleyf9f65842011-04-25 06:54:41 +00002187 /// \brief Build a new expression trait expression.
2188 ///
2189 /// By default, performs semantic analysis to build the new expression.
2190 /// Subclasses may override this routine to provide different behavior.
2191 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2192 SourceLocation StartLoc,
2193 Expr *Queried,
2194 SourceLocation RParenLoc) {
2195 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2196 }
2197
Mike Stump11289f42009-09-09 15:08:12 +00002198 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00002199 /// expression.
2200 ///
2201 /// By default, performs semantic analysis to build the new expression.
2202 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002203 ExprResult RebuildDependentScopeDeclRefExpr(
2204 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002205 SourceLocation TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002206 const DeclarationNameInfo &NameInfo,
Richard Smithdb2630f2012-10-21 03:28:35 +00002207 const TemplateArgumentListInfo *TemplateArgs,
2208 bool IsAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002209 CXXScopeSpec SS;
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002210 SS.Adopt(QualifierLoc);
John McCalle66edc12009-11-24 19:00:30 +00002211
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002212 if (TemplateArgs || TemplateKWLoc.isValid())
Abramo Bagnara7945c982012-01-27 09:46:47 +00002213 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002214 NameInfo, TemplateArgs);
John McCalle66edc12009-11-24 19:00:30 +00002215
Richard Smithdb2630f2012-10-21 03:28:35 +00002216 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo,
2217 IsAddressOfOperand);
Douglas Gregora16548e2009-08-11 05:31:07 +00002218 }
2219
2220 /// \brief Build a new template-id expression.
2221 ///
2222 /// By default, performs semantic analysis to build the new expression.
2223 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002224 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002225 SourceLocation TemplateKWLoc,
2226 LookupResult &R,
2227 bool RequiresADL,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002228 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnara7945c982012-01-27 09:46:47 +00002229 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2230 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002231 }
2232
2233 /// \brief Build a new object-construction expression.
2234 ///
2235 /// By default, performs semantic analysis to build the new expression.
2236 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002237 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002238 SourceLocation Loc,
2239 CXXConstructorDecl *Constructor,
2240 bool IsElidable,
2241 MultiExprArg Args,
2242 bool HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002243 bool ListInitialization,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002244 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00002245 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002246 SourceRange ParenRange) {
Benjamin Kramerf0623432012-08-23 22:51:59 +00002247 SmallVector<Expr*, 8> ConvertedArgs;
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002248 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00002249 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00002250 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002251
Douglas Gregordb121ba2009-12-14 16:27:04 +00002252 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002253 ConvertedArgs,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002254 HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002255 ListInitialization,
Chandler Carruth01718152010-10-25 08:47:36 +00002256 RequiresZeroInit, ConstructKind,
2257 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00002258 }
2259
2260 /// \brief Build a new object-construction expression.
2261 ///
2262 /// By default, performs semantic analysis to build the new expression.
2263 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002264 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2265 SourceLocation LParenLoc,
2266 MultiExprArg Args,
2267 SourceLocation RParenLoc) {
2268 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002269 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002270 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002271 RParenLoc);
2272 }
2273
2274 /// \brief Build a new object-construction expression.
2275 ///
2276 /// By default, performs semantic analysis to build the new expression.
2277 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002278 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2279 SourceLocation LParenLoc,
2280 MultiExprArg Args,
2281 SourceLocation RParenLoc) {
2282 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002283 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002284 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002285 RParenLoc);
2286 }
Mike Stump11289f42009-09-09 15:08:12 +00002287
Douglas Gregora16548e2009-08-11 05:31:07 +00002288 /// \brief Build a new member reference expression.
2289 ///
2290 /// By default, performs semantic analysis to build the new expression.
2291 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002292 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregore16af532011-02-28 18:50:33 +00002293 QualType BaseType,
2294 bool IsArrow,
2295 SourceLocation OperatorLoc,
2296 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002297 SourceLocation TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00002298 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002299 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00002300 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002301 CXXScopeSpec SS;
Douglas Gregore16af532011-02-28 18:50:33 +00002302 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002303
John McCallb268a282010-08-23 23:25:46 +00002304 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002305 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002306 SS, TemplateKWLoc,
2307 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002308 MemberNameInfo,
2309 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002310 }
2311
John McCall10eae182009-11-30 22:42:35 +00002312 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00002313 ///
2314 /// By default, performs semantic analysis to build the new expression.
2315 /// Subclasses may override this routine to provide different behavior.
Richard Smithcab9a7d2011-10-26 19:06:56 +00002316 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2317 SourceLocation OperatorLoc,
2318 bool IsArrow,
2319 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002320 SourceLocation TemplateKWLoc,
Richard Smithcab9a7d2011-10-26 19:06:56 +00002321 NamedDecl *FirstQualifierInScope,
2322 LookupResult &R,
John McCall10eae182009-11-30 22:42:35 +00002323 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00002324 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00002325 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002326
John McCallb268a282010-08-23 23:25:46 +00002327 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002328 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002329 SS, TemplateKWLoc,
2330 FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00002331 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00002332 }
Mike Stump11289f42009-09-09 15:08:12 +00002333
Sebastian Redl4202c0f2010-09-10 20:55:43 +00002334 /// \brief Build a new noexcept expression.
2335 ///
2336 /// By default, performs semantic analysis to build the new expression.
2337 /// Subclasses may override this routine to provide different behavior.
2338 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2339 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2340 }
2341
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002342 /// \brief Build a new expression to compute the length of a parameter pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00002343 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2344 SourceLocation PackLoc,
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002345 SourceLocation RParenLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002346 Optional<unsigned> Length) {
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002347 if (Length)
Chad Rosier1dcde962012-08-08 18:46:20 +00002348 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2349 OperatorLoc, Pack, PackLoc,
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002350 RParenLoc, *Length);
Chad Rosier1dcde962012-08-08 18:46:20 +00002351
2352 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2353 OperatorLoc, Pack, PackLoc,
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002354 RParenLoc);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002355 }
Ted Kremeneke65b0862012-03-06 20:05:56 +00002356
Patrick Beard0caa3942012-04-19 00:25:12 +00002357 /// \brief Build a new Objective-C boxed expression.
2358 ///
2359 /// By default, performs semantic analysis to build the new expression.
2360 /// Subclasses may override this routine to provide different behavior.
2361 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2362 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2363 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002364
Ted Kremeneke65b0862012-03-06 20:05:56 +00002365 /// \brief Build a new Objective-C array literal.
2366 ///
2367 /// By default, performs semantic analysis to build the new expression.
2368 /// Subclasses may override this routine to provide different behavior.
2369 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2370 Expr **Elements, unsigned NumElements) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002371 return getSema().BuildObjCArrayLiteral(Range,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002372 MultiExprArg(Elements, NumElements));
2373 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002374
2375 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002376 Expr *Base, Expr *Key,
2377 ObjCMethodDecl *getterMethod,
2378 ObjCMethodDecl *setterMethod) {
2379 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2380 getterMethod, setterMethod);
2381 }
2382
2383 /// \brief Build a new Objective-C dictionary literal.
2384 ///
2385 /// By default, performs semantic analysis to build the new expression.
2386 /// Subclasses may override this routine to provide different behavior.
2387 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
2388 ObjCDictionaryElement *Elements,
2389 unsigned NumElements) {
2390 return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements);
2391 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002392
James Dennett2a4d13c2012-06-15 07:13:21 +00002393 /// \brief Build a new Objective-C \@encode expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002394 ///
2395 /// By default, performs semantic analysis to build the new expression.
2396 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002397 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00002398 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002399 SourceLocation RParenLoc) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00002400 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002401 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00002402 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002403
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002404 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00002405 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002406 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002407 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002408 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002409 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002410 MultiExprArg Args,
2411 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002412 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2413 ReceiverTypeInfo->getType(),
2414 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002415 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002416 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002417 }
2418
2419 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00002420 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002421 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002422 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002423 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002424 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002425 MultiExprArg Args,
2426 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00002427 return SemaRef.BuildInstanceMessage(Receiver,
2428 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002429 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002430 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002431 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002432 }
2433
Douglas Gregord51d90d2010-04-26 20:11:03 +00002434 /// \brief Build a new Objective-C ivar reference expression.
2435 ///
2436 /// By default, performs semantic analysis to build the new expression.
2437 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002438 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002439 SourceLocation IvarLoc,
2440 bool IsArrow, bool IsFreeIvar) {
2441 // FIXME: We lose track of the IsFreeIvar bit.
2442 CXXScopeSpec SS;
John Wiegley01296292011-04-08 18:41:53 +00002443 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002444 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2445 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00002446 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002447 /*FIME:*/IvarLoc,
John McCall48871652010-08-21 09:40:31 +00002448 SS, 0,
John McCalle9cccd82010-06-16 08:42:20 +00002449 false);
John Wiegley01296292011-04-08 18:41:53 +00002450 if (Result.isInvalid() || Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002451 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002452
Douglas Gregord51d90d2010-04-26 20:11:03 +00002453 if (Result.get())
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002454 return Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00002455
John Wiegley01296292011-04-08 18:41:53 +00002456 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Abramo Bagnara7945c982012-01-27 09:46:47 +00002457 /*FIXME:*/IvarLoc, IsArrow,
2458 SS, SourceLocation(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00002459 /*FirstQualifierInScope=*/0,
Chad Rosier1dcde962012-08-08 18:46:20 +00002460 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002461 /*TemplateArgs=*/0);
2462 }
Douglas Gregor9faee212010-04-26 20:47:02 +00002463
2464 /// \brief Build a new Objective-C property reference expression.
2465 ///
2466 /// By default, performs semantic analysis to build the new expression.
2467 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002468 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall526ab472011-10-25 17:37:35 +00002469 ObjCPropertyDecl *Property,
2470 SourceLocation PropertyLoc) {
Douglas Gregor9faee212010-04-26 20:47:02 +00002471 CXXScopeSpec SS;
John Wiegley01296292011-04-08 18:41:53 +00002472 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregor9faee212010-04-26 20:47:02 +00002473 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2474 Sema::LookupMemberName);
2475 bool IsArrow = false;
John McCalldadc5752010-08-24 06:29:42 +00002476 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregor9faee212010-04-26 20:47:02 +00002477 /*FIME:*/PropertyLoc,
John McCall48871652010-08-21 09:40:31 +00002478 SS, 0, false);
John Wiegley01296292011-04-08 18:41:53 +00002479 if (Result.isInvalid() || Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002480 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002481
Douglas Gregor9faee212010-04-26 20:47:02 +00002482 if (Result.get())
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002483 return Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00002484
John Wiegley01296292011-04-08 18:41:53 +00002485 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Chad Rosier1dcde962012-08-08 18:46:20 +00002486 /*FIXME:*/PropertyLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002487 SS, SourceLocation(),
Douglas Gregor9faee212010-04-26 20:47:02 +00002488 /*FirstQualifierInScope=*/0,
Chad Rosier1dcde962012-08-08 18:46:20 +00002489 R,
Douglas Gregor9faee212010-04-26 20:47:02 +00002490 /*TemplateArgs=*/0);
2491 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002492
John McCallb7bd14f2010-12-02 01:19:52 +00002493 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002494 ///
2495 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00002496 /// Subclasses may override this routine to provide different behavior.
2497 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2498 ObjCMethodDecl *Getter,
2499 ObjCMethodDecl *Setter,
2500 SourceLocation PropertyLoc) {
2501 // Since these expressions can only be value-dependent, we do not
2502 // need to perform semantic analysis again.
2503 return Owned(
2504 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2505 VK_LValue, OK_ObjCProperty,
2506 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002507 }
2508
Douglas Gregord51d90d2010-04-26 20:11:03 +00002509 /// \brief Build a new Objective-C "isa" expression.
2510 ///
2511 /// By default, performs semantic analysis to build the new expression.
2512 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002513 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00002514 SourceLocation OpLoc,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002515 bool IsArrow) {
2516 CXXScopeSpec SS;
John Wiegley01296292011-04-08 18:41:53 +00002517 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002518 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2519 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00002520 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00002521 OpLoc,
John McCall48871652010-08-21 09:40:31 +00002522 SS, 0, false);
John Wiegley01296292011-04-08 18:41:53 +00002523 if (Result.isInvalid() || Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002524 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002525
Douglas Gregord51d90d2010-04-26 20:11:03 +00002526 if (Result.get())
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002527 return Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00002528
John Wiegley01296292011-04-08 18:41:53 +00002529 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00002530 OpLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002531 SS, SourceLocation(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00002532 /*FirstQualifierInScope=*/0,
Chad Rosier1dcde962012-08-08 18:46:20 +00002533 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002534 /*TemplateArgs=*/0);
2535 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002536
Douglas Gregora16548e2009-08-11 05:31:07 +00002537 /// \brief Build a new shuffle vector expression.
2538 ///
2539 /// By default, performs semantic analysis to build the new expression.
2540 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002541 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002542 MultiExprArg SubExprs,
2543 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002544 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00002545 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00002546 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2547 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2548 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
David Blaikieff7d47a2012-12-19 00:45:41 +00002549 assert(!Lookup.empty() && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00002550
Douglas Gregora16548e2009-08-11 05:31:07 +00002551 // Build a reference to the __builtin_shufflevector builtin
David Blaikieff7d47a2012-12-19 00:45:41 +00002552 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
Eli Friedman34866c72012-08-31 00:14:07 +00002553 Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false,
2554 SemaRef.Context.BuiltinFnTy,
2555 VK_RValue, BuiltinLoc);
2556 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
2557 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
2558 CK_BuiltinFnToFnPtr).take();
Mike Stump11289f42009-09-09 15:08:12 +00002559
2560 // Build the CallExpr
Alp Toker314cc812014-01-25 16:55:45 +00002561 ExprResult TheCall = SemaRef.Owned(new (SemaRef.Context) CallExpr(
2562 SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(),
2563 Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00002564
Douglas Gregora16548e2009-08-11 05:31:07 +00002565 // Type-check the __builtin_shufflevector expression.
John Wiegley01296292011-04-08 18:41:53 +00002566 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.take()));
Douglas Gregora16548e2009-08-11 05:31:07 +00002567 }
John McCall31f82722010-11-12 08:19:04 +00002568
Hal Finkelc4d7c822013-09-18 03:29:45 +00002569 /// \brief Build a new convert vector expression.
2570 ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc,
2571 Expr *SrcExpr, TypeSourceInfo *DstTInfo,
2572 SourceLocation RParenLoc) {
2573 return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo,
2574 BuiltinLoc, RParenLoc);
2575 }
2576
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002577 /// \brief Build a new template argument pack expansion.
2578 ///
2579 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00002580 /// for a template argument. Subclasses may override this routine to provide
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002581 /// different behavior.
2582 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002583 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002584 Optional<unsigned> NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002585 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00002586 case TemplateArgument::Expression: {
2587 ExprResult Result
Douglas Gregorb8840002011-01-14 21:20:45 +00002588 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2589 EllipsisLoc, NumExpansions);
Douglas Gregor98318c22011-01-03 21:37:45 +00002590 if (Result.isInvalid())
2591 return TemplateArgumentLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00002592
Douglas Gregor98318c22011-01-03 21:37:45 +00002593 return TemplateArgumentLoc(Result.get(), Result.get());
2594 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002595
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002596 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002597 return TemplateArgumentLoc(TemplateArgument(
2598 Pattern.getArgument().getAsTemplate(),
Douglas Gregore1d60df2011-01-14 23:41:42 +00002599 NumExpansions),
Douglas Gregor9d802122011-03-02 17:09:35 +00002600 Pattern.getTemplateQualifierLoc(),
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002601 Pattern.getTemplateNameLoc(),
2602 EllipsisLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00002603
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002604 case TemplateArgument::Null:
2605 case TemplateArgument::Integral:
2606 case TemplateArgument::Declaration:
2607 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002608 case TemplateArgument::TemplateExpansion:
Eli Friedmanb826a002012-09-26 02:36:12 +00002609 case TemplateArgument::NullPtr:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002610 llvm_unreachable("Pack expansion pattern has no parameter packs");
Chad Rosier1dcde962012-08-08 18:46:20 +00002611
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002612 case TemplateArgument::Type:
Chad Rosier1dcde962012-08-08 18:46:20 +00002613 if (TypeSourceInfo *Expansion
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002614 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002615 EllipsisLoc,
2616 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002617 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2618 Expansion);
2619 break;
2620 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002621
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002622 return TemplateArgumentLoc();
2623 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002624
Douglas Gregor968f23a2011-01-03 19:31:53 +00002625 /// \brief Build a new expression pack expansion.
2626 ///
2627 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00002628 /// for an expression. Subclasses may override this routine to provide
Douglas Gregor968f23a2011-01-03 19:31:53 +00002629 /// different behavior.
Douglas Gregorb8840002011-01-14 21:20:45 +00002630 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002631 Optional<unsigned> NumExpansions) {
Douglas Gregorb8840002011-01-14 21:20:45 +00002632 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002633 }
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002634
2635 /// \brief Build a new atomic operation expression.
2636 ///
2637 /// By default, performs semantic analysis to build the new expression.
2638 /// Subclasses may override this routine to provide different behavior.
2639 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2640 MultiExprArg SubExprs,
2641 QualType RetTy,
2642 AtomicExpr::AtomicOp Op,
2643 SourceLocation RParenLoc) {
2644 // Just create the expression; there is not any interesting semantic
2645 // analysis here because we can't actually build an AtomicExpr until
2646 // we are sure it is semantically sound.
Benjamin Kramerc215e762012-08-24 11:54:20 +00002647 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002648 RParenLoc);
2649 }
2650
John McCall31f82722010-11-12 08:19:04 +00002651private:
Douglas Gregor14454802011-02-25 02:25:35 +00002652 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2653 QualType ObjectType,
2654 NamedDecl *FirstQualifierInScope,
2655 CXXScopeSpec &SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00002656
2657 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2658 QualType ObjectType,
2659 NamedDecl *FirstQualifierInScope,
2660 CXXScopeSpec &SS);
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00002661
2662 TypeSourceInfo *TransformTSIInObjectScope(TypeLoc TL, QualType ObjectType,
2663 NamedDecl *FirstQualifierInScope,
2664 CXXScopeSpec &SS);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002665};
Douglas Gregora16548e2009-08-11 05:31:07 +00002666
Douglas Gregorebe10102009-08-20 07:17:43 +00002667template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002668StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002669 if (!S)
2670 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00002671
Douglas Gregorebe10102009-08-20 07:17:43 +00002672 switch (S->getStmtClass()) {
2673 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00002674
Douglas Gregorebe10102009-08-20 07:17:43 +00002675 // Transform individual statement nodes
2676#define STMT(Node, Parent) \
2677 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCallbd066782011-02-09 08:16:59 +00002678#define ABSTRACT_STMT(Node)
Douglas Gregorebe10102009-08-20 07:17:43 +00002679#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00002680#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002681
Douglas Gregorebe10102009-08-20 07:17:43 +00002682 // Transform expressions by calling TransformExpr.
2683#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00002684#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00002685#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00002686#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00002687 {
John McCalldadc5752010-08-24 06:29:42 +00002688 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00002689 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002690 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002691
Richard Smith945f8d32013-01-14 22:39:08 +00002692 return getSema().ActOnExprStmt(E);
Douglas Gregorebe10102009-08-20 07:17:43 +00002693 }
Mike Stump11289f42009-09-09 15:08:12 +00002694 }
2695
John McCallc3007a22010-10-26 07:05:15 +00002696 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00002697}
Mike Stump11289f42009-09-09 15:08:12 +00002698
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00002699template<typename Derived>
2700OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) {
2701 if (!S)
2702 return S;
2703
2704 switch (S->getClauseKind()) {
2705 default: break;
2706 // Transform individual clause nodes
2707#define OPENMP_CLAUSE(Name, Class) \
2708 case OMPC_ ## Name : \
2709 return getDerived().Transform ## Class(cast<Class>(S));
2710#include "clang/Basic/OpenMPKinds.def"
2711 }
2712
2713 return S;
2714}
2715
Mike Stump11289f42009-09-09 15:08:12 +00002716
Douglas Gregore922c772009-08-04 22:27:00 +00002717template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002718ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002719 if (!E)
2720 return SemaRef.Owned(E);
2721
2722 switch (E->getStmtClass()) {
2723 case Stmt::NoStmtClass: break;
2724#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00002725#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00002726#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00002727 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00002728#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002729 }
2730
John McCallc3007a22010-10-26 07:05:15 +00002731 return SemaRef.Owned(E);
Douglas Gregor766b0bb2009-08-06 22:17:10 +00002732}
2733
2734template<typename Derived>
Richard Smithd59b8322012-12-19 01:39:02 +00002735ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
2736 bool CXXDirectInit) {
2737 // Initializers are instantiated like expressions, except that various outer
2738 // layers are stripped.
2739 if (!Init)
2740 return SemaRef.Owned(Init);
2741
2742 if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init))
2743 Init = ExprTemp->getSubExpr();
2744
Richard Smithe6ca4752013-05-30 22:40:16 +00002745 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
2746 Init = MTE->GetTemporaryExpr();
2747
Richard Smithd59b8322012-12-19 01:39:02 +00002748 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
2749 Init = Binder->getSubExpr();
2750
2751 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
2752 Init = ICE->getSubExprAsWritten();
2753
Richard Smithcc1b96d2013-06-12 22:31:48 +00002754 if (CXXStdInitializerListExpr *ILE =
2755 dyn_cast<CXXStdInitializerListExpr>(Init))
2756 return TransformInitializer(ILE->getSubExpr(), CXXDirectInit);
2757
Richard Smith38a549b2012-12-21 08:13:35 +00002758 // If this is not a direct-initializer, we only need to reconstruct
2759 // InitListExprs. Other forms of copy-initialization will be a no-op if
2760 // the initializer is already the right type.
2761 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
2762 if (!CXXDirectInit && !(Construct && Construct->isListInitialization()))
2763 return getDerived().TransformExpr(Init);
2764
2765 // Revert value-initialization back to empty parens.
2766 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
2767 SourceRange Parens = VIE->getSourceRange();
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002768 return getDerived().RebuildParenListExpr(Parens.getBegin(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00002769 Parens.getEnd());
2770 }
2771
2772 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
2773 if (isa<ImplicitValueInitExpr>(Init))
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002774 return getDerived().RebuildParenListExpr(SourceLocation(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00002775 SourceLocation());
2776
2777 // Revert initialization by constructor back to a parenthesized or braced list
2778 // of expressions. Any other form of initializer can just be reused directly.
2779 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
Richard Smithd59b8322012-12-19 01:39:02 +00002780 return getDerived().TransformExpr(Init);
2781
2782 SmallVector<Expr*, 8> NewArgs;
2783 bool ArgChanged = false;
2784 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
2785 /*IsCall*/true, NewArgs, &ArgChanged))
2786 return ExprError();
2787
2788 // If this was list initialization, revert to list form.
2789 if (Construct->isListInitialization())
2790 return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs,
2791 Construct->getLocEnd(),
2792 Construct->getType());
2793
Richard Smithd59b8322012-12-19 01:39:02 +00002794 // Build a ParenListExpr to represent anything else.
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00002795 SourceRange Parens = Construct->getParenOrBraceRange();
Richard Smithd59b8322012-12-19 01:39:02 +00002796 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
2797 Parens.getEnd());
2798}
2799
2800template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00002801bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2802 unsigned NumInputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00002803 bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +00002804 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00002805 bool *ArgChanged) {
2806 for (unsigned I = 0; I != NumInputs; ++I) {
2807 // If requested, drop call arguments that need to be dropped.
2808 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2809 if (ArgChanged)
2810 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002811
Douglas Gregora3efea12011-01-03 19:04:46 +00002812 break;
2813 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002814
Douglas Gregor968f23a2011-01-03 19:31:53 +00002815 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2816 Expr *Pattern = Expansion->getPattern();
Chad Rosier1dcde962012-08-08 18:46:20 +00002817
Chris Lattner01cf8db2011-07-20 06:58:45 +00002818 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor968f23a2011-01-03 19:31:53 +00002819 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2820 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00002821
Douglas Gregor968f23a2011-01-03 19:31:53 +00002822 // Determine whether the set of unexpanded parameter packs can and should
2823 // be expanded.
2824 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002825 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00002826 Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
2827 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor968f23a2011-01-03 19:31:53 +00002828 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2829 Pattern->getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00002830 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002831 Expand, RetainExpansion,
2832 NumExpansions))
Douglas Gregor968f23a2011-01-03 19:31:53 +00002833 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002834
Douglas Gregor968f23a2011-01-03 19:31:53 +00002835 if (!Expand) {
2836 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00002837 // transformation on the pack expansion, producing another pack
Douglas Gregor968f23a2011-01-03 19:31:53 +00002838 // expansion.
2839 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2840 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2841 if (OutPattern.isInvalid())
2842 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002843
2844 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregorb8840002011-01-14 21:20:45 +00002845 Expansion->getEllipsisLoc(),
2846 NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002847 if (Out.isInvalid())
2848 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002849
Douglas Gregor968f23a2011-01-03 19:31:53 +00002850 if (ArgChanged)
2851 *ArgChanged = true;
2852 Outputs.push_back(Out.get());
2853 continue;
2854 }
John McCall542e7c62011-07-06 07:30:07 +00002855
2856 // Record right away that the argument was changed. This needs
2857 // to happen even if the array expands to nothing.
2858 if (ArgChanged) *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002859
Douglas Gregor968f23a2011-01-03 19:31:53 +00002860 // The transform has determined that we should perform an elementwise
2861 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002862 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor968f23a2011-01-03 19:31:53 +00002863 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2864 ExprResult Out = getDerived().TransformExpr(Pattern);
2865 if (Out.isInvalid())
2866 return true;
2867
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002868 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregorb8840002011-01-14 21:20:45 +00002869 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2870 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002871 if (Out.isInvalid())
2872 return true;
2873 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002874
Douglas Gregor968f23a2011-01-03 19:31:53 +00002875 Outputs.push_back(Out.get());
2876 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002877
Douglas Gregor968f23a2011-01-03 19:31:53 +00002878 continue;
2879 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002880
Richard Smithd59b8322012-12-19 01:39:02 +00002881 ExprResult Result =
2882 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
2883 : getDerived().TransformExpr(Inputs[I]);
Douglas Gregora3efea12011-01-03 19:04:46 +00002884 if (Result.isInvalid())
2885 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002886
Douglas Gregora3efea12011-01-03 19:04:46 +00002887 if (Result.get() != Inputs[I] && ArgChanged)
2888 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002889
2890 Outputs.push_back(Result.get());
Douglas Gregora3efea12011-01-03 19:04:46 +00002891 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002892
Douglas Gregora3efea12011-01-03 19:04:46 +00002893 return false;
2894}
2895
2896template<typename Derived>
Douglas Gregor14454802011-02-25 02:25:35 +00002897NestedNameSpecifierLoc
2898TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2899 NestedNameSpecifierLoc NNS,
2900 QualType ObjectType,
2901 NamedDecl *FirstQualifierInScope) {
Chris Lattner01cf8db2011-07-20 06:58:45 +00002902 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier1dcde962012-08-08 18:46:20 +00002903 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregor14454802011-02-25 02:25:35 +00002904 Qualifier = Qualifier.getPrefix())
2905 Qualifiers.push_back(Qualifier);
2906
2907 CXXScopeSpec SS;
2908 while (!Qualifiers.empty()) {
2909 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2910 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier1dcde962012-08-08 18:46:20 +00002911
Douglas Gregor14454802011-02-25 02:25:35 +00002912 switch (QNNS->getKind()) {
2913 case NestedNameSpecifier::Identifier:
Chad Rosier1dcde962012-08-08 18:46:20 +00002914 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
Douglas Gregor14454802011-02-25 02:25:35 +00002915 *QNNS->getAsIdentifier(),
Chad Rosier1dcde962012-08-08 18:46:20 +00002916 Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00002917 Q.getLocalEndLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00002918 ObjectType, false, SS,
Douglas Gregor14454802011-02-25 02:25:35 +00002919 FirstQualifierInScope, false))
2920 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00002921
Douglas Gregor14454802011-02-25 02:25:35 +00002922 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00002923
Douglas Gregor14454802011-02-25 02:25:35 +00002924 case NestedNameSpecifier::Namespace: {
2925 NamespaceDecl *NS
2926 = cast_or_null<NamespaceDecl>(
2927 getDerived().TransformDecl(
2928 Q.getLocalBeginLoc(),
2929 QNNS->getAsNamespace()));
2930 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2931 break;
2932 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002933
Douglas Gregor14454802011-02-25 02:25:35 +00002934 case NestedNameSpecifier::NamespaceAlias: {
2935 NamespaceAliasDecl *Alias
2936 = cast_or_null<NamespaceAliasDecl>(
2937 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2938 QNNS->getAsNamespaceAlias()));
Chad Rosier1dcde962012-08-08 18:46:20 +00002939 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00002940 Q.getLocalEndLoc());
2941 break;
2942 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002943
Douglas Gregor14454802011-02-25 02:25:35 +00002944 case NestedNameSpecifier::Global:
2945 // There is no meaningful transformation that one could perform on the
2946 // global scope.
2947 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2948 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00002949
Douglas Gregor14454802011-02-25 02:25:35 +00002950 case NestedNameSpecifier::TypeSpecWithTemplate:
2951 case NestedNameSpecifier::TypeSpec: {
2952 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2953 FirstQualifierInScope, SS);
Chad Rosier1dcde962012-08-08 18:46:20 +00002954
Douglas Gregor14454802011-02-25 02:25:35 +00002955 if (!TL)
2956 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00002957
Douglas Gregor14454802011-02-25 02:25:35 +00002958 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Richard Smith2bf7fdb2013-01-02 11:42:31 +00002959 (SemaRef.getLangOpts().CPlusPlus11 &&
Douglas Gregor14454802011-02-25 02:25:35 +00002960 TL.getType()->isEnumeralType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002961 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregor14454802011-02-25 02:25:35 +00002962 "Can't get cv-qualifiers here");
Richard Smith91c7bbd2011-10-20 03:28:47 +00002963 if (TL.getType()->isEnumeralType())
2964 SemaRef.Diag(TL.getBeginLoc(),
2965 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregor14454802011-02-25 02:25:35 +00002966 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2967 Q.getLocalEndLoc());
2968 break;
2969 }
Richard Trieude756fb2011-05-07 01:36:37 +00002970 // If the nested-name-specifier is an invalid type def, don't emit an
2971 // error because a previous error should have already been emitted.
David Blaikie6adc78e2013-02-18 22:06:02 +00002972 TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
2973 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002974 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieude756fb2011-05-07 01:36:37 +00002975 << TL.getType() << SS.getRange();
2976 }
Douglas Gregor14454802011-02-25 02:25:35 +00002977 return NestedNameSpecifierLoc();
2978 }
Douglas Gregore16af532011-02-28 18:50:33 +00002979 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002980
Douglas Gregore16af532011-02-28 18:50:33 +00002981 // The qualifier-in-scope and object type only apply to the leftmost entity.
Douglas Gregor14454802011-02-25 02:25:35 +00002982 FirstQualifierInScope = 0;
Douglas Gregore16af532011-02-28 18:50:33 +00002983 ObjectType = QualType();
Douglas Gregor14454802011-02-25 02:25:35 +00002984 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002985
Douglas Gregor14454802011-02-25 02:25:35 +00002986 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier1dcde962012-08-08 18:46:20 +00002987 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregor14454802011-02-25 02:25:35 +00002988 !getDerived().AlwaysRebuild())
2989 return NNS;
Chad Rosier1dcde962012-08-08 18:46:20 +00002990
2991 // If we can re-use the source-location data from the original
Douglas Gregor14454802011-02-25 02:25:35 +00002992 // nested-name-specifier, do so.
2993 if (SS.location_size() == NNS.getDataLength() &&
2994 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2995 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
2996
2997 // Allocate new nested-name-specifier location information.
2998 return SS.getWithLocInContext(SemaRef.Context);
2999}
3000
3001template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003002DeclarationNameInfo
3003TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00003004::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003005 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003006 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003007 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003008
3009 switch (Name.getNameKind()) {
3010 case DeclarationName::Identifier:
3011 case DeclarationName::ObjCZeroArgSelector:
3012 case DeclarationName::ObjCOneArgSelector:
3013 case DeclarationName::ObjCMultiArgSelector:
3014 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00003015 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00003016 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003017 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00003018
Douglas Gregorf816bd72009-09-03 22:13:48 +00003019 case DeclarationName::CXXConstructorName:
3020 case DeclarationName::CXXDestructorName:
3021 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003022 TypeSourceInfo *NewTInfo;
3023 CanQualType NewCanTy;
3024 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00003025 NewTInfo = getDerived().TransformType(OldTInfo);
3026 if (!NewTInfo)
3027 return DeclarationNameInfo();
3028 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003029 }
3030 else {
3031 NewTInfo = 0;
3032 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00003033 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003034 if (NewT.isNull())
3035 return DeclarationNameInfo();
3036 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
3037 }
Mike Stump11289f42009-09-09 15:08:12 +00003038
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003039 DeclarationName NewName
3040 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
3041 NewCanTy);
3042 DeclarationNameInfo NewNameInfo(NameInfo);
3043 NewNameInfo.setName(NewName);
3044 NewNameInfo.setNamedTypeInfo(NewTInfo);
3045 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00003046 }
Mike Stump11289f42009-09-09 15:08:12 +00003047 }
3048
David Blaikie83d382b2011-09-23 05:06:16 +00003049 llvm_unreachable("Unknown name kind.");
Douglas Gregorf816bd72009-09-03 22:13:48 +00003050}
3051
3052template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003053TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00003054TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
3055 TemplateName Name,
3056 SourceLocation NameLoc,
3057 QualType ObjectType,
3058 NamedDecl *FirstQualifierInScope) {
3059 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
3060 TemplateDecl *Template = QTN->getTemplateDecl();
3061 assert(Template && "qualified template name must refer to a template");
Chad Rosier1dcde962012-08-08 18:46:20 +00003062
Douglas Gregor9db53502011-03-02 18:07:45 +00003063 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003064 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003065 Template));
3066 if (!TransTemplate)
3067 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003068
Douglas Gregor9db53502011-03-02 18:07:45 +00003069 if (!getDerived().AlwaysRebuild() &&
3070 SS.getScopeRep() == QTN->getQualifier() &&
3071 TransTemplate == Template)
3072 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003073
Douglas Gregor9db53502011-03-02 18:07:45 +00003074 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
3075 TransTemplate);
3076 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003077
Douglas Gregor9db53502011-03-02 18:07:45 +00003078 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
3079 if (SS.getScopeRep()) {
3080 // These apply to the scope specifier, not the template.
3081 ObjectType = QualType();
3082 FirstQualifierInScope = 0;
Chad Rosier1dcde962012-08-08 18:46:20 +00003083 }
3084
Douglas Gregor9db53502011-03-02 18:07:45 +00003085 if (!getDerived().AlwaysRebuild() &&
3086 SS.getScopeRep() == DTN->getQualifier() &&
3087 ObjectType.isNull())
3088 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003089
Douglas Gregor9db53502011-03-02 18:07:45 +00003090 if (DTN->isIdentifier()) {
3091 return getDerived().RebuildTemplateName(SS,
Chad Rosier1dcde962012-08-08 18:46:20 +00003092 *DTN->getIdentifier(),
Douglas Gregor9db53502011-03-02 18:07:45 +00003093 NameLoc,
3094 ObjectType,
3095 FirstQualifierInScope);
3096 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003097
Douglas Gregor9db53502011-03-02 18:07:45 +00003098 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
3099 ObjectType);
3100 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003101
Douglas Gregor9db53502011-03-02 18:07:45 +00003102 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
3103 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003104 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003105 Template));
3106 if (!TransTemplate)
3107 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003108
Douglas Gregor9db53502011-03-02 18:07:45 +00003109 if (!getDerived().AlwaysRebuild() &&
3110 TransTemplate == Template)
3111 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003112
Douglas Gregor9db53502011-03-02 18:07:45 +00003113 return TemplateName(TransTemplate);
3114 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003115
Douglas Gregor9db53502011-03-02 18:07:45 +00003116 if (SubstTemplateTemplateParmPackStorage *SubstPack
3117 = Name.getAsSubstTemplateTemplateParmPack()) {
3118 TemplateTemplateParmDecl *TransParam
3119 = cast_or_null<TemplateTemplateParmDecl>(
3120 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
3121 if (!TransParam)
3122 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003123
Douglas Gregor9db53502011-03-02 18:07:45 +00003124 if (!getDerived().AlwaysRebuild() &&
3125 TransParam == SubstPack->getParameterPack())
3126 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003127
3128 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregor9db53502011-03-02 18:07:45 +00003129 SubstPack->getArgumentPack());
3130 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003131
Douglas Gregor9db53502011-03-02 18:07:45 +00003132 // These should be getting filtered out before they reach the AST.
3133 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregor9db53502011-03-02 18:07:45 +00003134}
3135
3136template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003137void TreeTransform<Derived>::InventTemplateArgumentLoc(
3138 const TemplateArgument &Arg,
3139 TemplateArgumentLoc &Output) {
3140 SourceLocation Loc = getDerived().getBaseLocation();
3141 switch (Arg.getKind()) {
3142 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003143 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00003144 break;
3145
3146 case TemplateArgument::Type:
3147 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00003148 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier1dcde962012-08-08 18:46:20 +00003149
John McCall0ad16662009-10-29 08:12:44 +00003150 break;
3151
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003152 case TemplateArgument::Template:
Douglas Gregor9d802122011-03-02 17:09:35 +00003153 case TemplateArgument::TemplateExpansion: {
3154 NestedNameSpecifierLocBuilder Builder;
3155 TemplateName Template = Arg.getAsTemplate();
3156 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3157 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3158 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3159 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003160
Douglas Gregor9d802122011-03-02 17:09:35 +00003161 if (Arg.getKind() == TemplateArgument::Template)
Chad Rosier1dcde962012-08-08 18:46:20 +00003162 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003163 Builder.getWithLocInContext(SemaRef.Context),
3164 Loc);
3165 else
Chad Rosier1dcde962012-08-08 18:46:20 +00003166 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003167 Builder.getWithLocInContext(SemaRef.Context),
3168 Loc, Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003169
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003170 break;
Douglas Gregor9d802122011-03-02 17:09:35 +00003171 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003172
John McCall0ad16662009-10-29 08:12:44 +00003173 case TemplateArgument::Expression:
3174 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3175 break;
3176
3177 case TemplateArgument::Declaration:
3178 case TemplateArgument::Integral:
3179 case TemplateArgument::Pack:
Eli Friedmanb826a002012-09-26 02:36:12 +00003180 case TemplateArgument::NullPtr:
John McCall0d07eb32009-10-29 18:45:58 +00003181 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00003182 break;
3183 }
3184}
3185
3186template<typename Derived>
3187bool TreeTransform<Derived>::TransformTemplateArgument(
3188 const TemplateArgumentLoc &Input,
3189 TemplateArgumentLoc &Output) {
3190 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00003191 switch (Arg.getKind()) {
3192 case TemplateArgument::Null:
3193 case TemplateArgument::Integral:
Eli Friedmancda3db82012-09-25 01:02:42 +00003194 case TemplateArgument::Pack:
3195 case TemplateArgument::Declaration:
Eli Friedmanb826a002012-09-26 02:36:12 +00003196 case TemplateArgument::NullPtr:
3197 llvm_unreachable("Unexpected TemplateArgument");
Mike Stump11289f42009-09-09 15:08:12 +00003198
Douglas Gregore922c772009-08-04 22:27:00 +00003199 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00003200 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall0ad16662009-10-29 08:12:44 +00003201 if (DI == NULL)
John McCallbcd03502009-12-07 02:54:59 +00003202 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00003203
3204 DI = getDerived().TransformType(DI);
3205 if (!DI) return true;
3206
3207 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3208 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003209 }
Mike Stump11289f42009-09-09 15:08:12 +00003210
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003211 case TemplateArgument::Template: {
Douglas Gregor9d802122011-03-02 17:09:35 +00003212 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3213 if (QualifierLoc) {
3214 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3215 if (!QualifierLoc)
3216 return true;
3217 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003218
Douglas Gregordf846d12011-03-02 18:46:51 +00003219 CXXScopeSpec SS;
3220 SS.Adopt(QualifierLoc);
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003221 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00003222 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3223 Input.getTemplateNameLoc());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003224 if (Template.isNull())
3225 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003226
Douglas Gregor9d802122011-03-02 17:09:35 +00003227 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003228 Input.getTemplateNameLoc());
3229 return false;
3230 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003231
3232 case TemplateArgument::TemplateExpansion:
3233 llvm_unreachable("Caller should expand pack expansions");
3234
Douglas Gregore922c772009-08-04 22:27:00 +00003235 case TemplateArgument::Expression: {
Richard Smith764d2fe2011-12-20 02:08:33 +00003236 // Template argument expressions are constant expressions.
Mike Stump11289f42009-09-09 15:08:12 +00003237 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smith764d2fe2011-12-20 02:08:33 +00003238 Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003239
John McCall0ad16662009-10-29 08:12:44 +00003240 Expr *InputExpr = Input.getSourceExpression();
3241 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3242
Chris Lattnercdb591a2011-04-25 20:37:58 +00003243 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanc6237c62012-02-29 03:16:56 +00003244 E = SemaRef.ActOnConstantExpression(E);
John McCall0ad16662009-10-29 08:12:44 +00003245 if (E.isInvalid()) return true;
John McCallb268a282010-08-23 23:25:46 +00003246 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall0ad16662009-10-29 08:12:44 +00003247 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003248 }
Douglas Gregore922c772009-08-04 22:27:00 +00003249 }
Mike Stump11289f42009-09-09 15:08:12 +00003250
Douglas Gregore922c772009-08-04 22:27:00 +00003251 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00003252 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00003253}
3254
Douglas Gregorfe921a72010-12-20 23:36:19 +00003255/// \brief Iterator adaptor that invents template argument location information
3256/// for each of the template arguments in its underlying iterator.
3257template<typename Derived, typename InputIterator>
3258class TemplateArgumentLocInventIterator {
3259 TreeTransform<Derived> &Self;
3260 InputIterator Iter;
Chad Rosier1dcde962012-08-08 18:46:20 +00003261
Douglas Gregorfe921a72010-12-20 23:36:19 +00003262public:
3263 typedef TemplateArgumentLoc value_type;
3264 typedef TemplateArgumentLoc reference;
3265 typedef typename std::iterator_traits<InputIterator>::difference_type
3266 difference_type;
3267 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00003268
Douglas Gregorfe921a72010-12-20 23:36:19 +00003269 class pointer {
3270 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00003271
Douglas Gregorfe921a72010-12-20 23:36:19 +00003272 public:
3273 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003274
Douglas Gregorfe921a72010-12-20 23:36:19 +00003275 const TemplateArgumentLoc *operator->() const { return &Arg; }
3276 };
Chad Rosier1dcde962012-08-08 18:46:20 +00003277
Douglas Gregorfe921a72010-12-20 23:36:19 +00003278 TemplateArgumentLocInventIterator() { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003279
Douglas Gregorfe921a72010-12-20 23:36:19 +00003280 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3281 InputIterator Iter)
3282 : Self(Self), Iter(Iter) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003283
Douglas Gregorfe921a72010-12-20 23:36:19 +00003284 TemplateArgumentLocInventIterator &operator++() {
3285 ++Iter;
3286 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00003287 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003288
Douglas Gregorfe921a72010-12-20 23:36:19 +00003289 TemplateArgumentLocInventIterator operator++(int) {
3290 TemplateArgumentLocInventIterator Old(*this);
3291 ++(*this);
3292 return Old;
3293 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003294
Douglas Gregorfe921a72010-12-20 23:36:19 +00003295 reference operator*() const {
3296 TemplateArgumentLoc Result;
3297 Self.InventTemplateArgumentLoc(*Iter, Result);
3298 return Result;
3299 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003300
Douglas Gregorfe921a72010-12-20 23:36:19 +00003301 pointer operator->() const { return pointer(**this); }
Chad Rosier1dcde962012-08-08 18:46:20 +00003302
Douglas Gregorfe921a72010-12-20 23:36:19 +00003303 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3304 const TemplateArgumentLocInventIterator &Y) {
3305 return X.Iter == Y.Iter;
3306 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00003307
Douglas Gregorfe921a72010-12-20 23:36:19 +00003308 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3309 const TemplateArgumentLocInventIterator &Y) {
3310 return X.Iter != Y.Iter;
3311 }
3312};
Chad Rosier1dcde962012-08-08 18:46:20 +00003313
Douglas Gregor42cafa82010-12-20 17:42:22 +00003314template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00003315template<typename InputIterator>
3316bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3317 InputIterator Last,
Douglas Gregor42cafa82010-12-20 17:42:22 +00003318 TemplateArgumentListInfo &Outputs) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00003319 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00003320 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00003321 TemplateArgumentLoc In = *First;
Chad Rosier1dcde962012-08-08 18:46:20 +00003322
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003323 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3324 // Unpack argument packs, which we translate them into separate
3325 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00003326 // FIXME: We could do much better if we could guarantee that the
3327 // TemplateArgumentLocInfo for the pack expansion would be usable for
3328 // all of the template arguments in the argument pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00003329 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003330 TemplateArgument::pack_iterator>
3331 PackLocIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00003332 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003333 In.getArgument().pack_begin()),
3334 PackLocIterator(*this,
3335 In.getArgument().pack_end()),
3336 Outputs))
3337 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003338
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003339 continue;
3340 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003341
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003342 if (In.getArgument().isPackExpansion()) {
3343 // We have a pack expansion, for which we will be substituting into
3344 // the pattern.
3345 SourceLocation Ellipsis;
David Blaikie05785d12013-02-20 22:23:23 +00003346 Optional<unsigned> OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003347 TemplateArgumentLoc Pattern
Eli Friedman94e9eaa2013-06-20 04:11:21 +00003348 = getSema().getTemplateArgumentPackExpansionPattern(
3349 In, Ellipsis, OrigNumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00003350
Chris Lattner01cf8db2011-07-20 06:58:45 +00003351 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003352 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3353 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00003354
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003355 // Determine whether the set of unexpanded parameter packs can and should
3356 // be expanded.
3357 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003358 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00003359 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003360 if (getDerived().TryExpandParameterPacks(Ellipsis,
3361 Pattern.getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003362 Unexpanded,
Chad Rosier1dcde962012-08-08 18:46:20 +00003363 Expand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003364 RetainExpansion,
3365 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003366 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003367
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003368 if (!Expand) {
3369 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00003370 // transformation on the pack expansion, producing another pack
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003371 // expansion.
3372 TemplateArgumentLoc OutPattern;
3373 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3374 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3375 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003376
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003377 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3378 NumExpansions);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003379 if (Out.getArgument().isNull())
3380 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003381
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003382 Outputs.addArgument(Out);
3383 continue;
3384 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003385
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003386 // The transform has determined that we should perform an elementwise
3387 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003388 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003389 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3390
3391 if (getDerived().TransformTemplateArgument(Pattern, Out))
3392 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003393
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003394 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003395 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3396 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003397 if (Out.getArgument().isNull())
3398 return true;
3399 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003400
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003401 Outputs.addArgument(Out);
3402 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003403
Douglas Gregor48d24112011-01-10 20:53:55 +00003404 // If we're supposed to retain a pack expansion, do so by temporarily
3405 // forgetting the partially-substituted parameter pack.
3406 if (RetainExpansion) {
3407 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00003408
Douglas Gregor48d24112011-01-10 20:53:55 +00003409 if (getDerived().TransformTemplateArgument(Pattern, Out))
3410 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003411
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003412 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3413 OrigNumExpansions);
Douglas Gregor48d24112011-01-10 20:53:55 +00003414 if (Out.getArgument().isNull())
3415 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003416
Douglas Gregor48d24112011-01-10 20:53:55 +00003417 Outputs.addArgument(Out);
3418 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003419
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003420 continue;
3421 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003422
3423 // The simple case:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003424 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor42cafa82010-12-20 17:42:22 +00003425 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003426
Douglas Gregor42cafa82010-12-20 17:42:22 +00003427 Outputs.addArgument(Out);
3428 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003429
Douglas Gregor42cafa82010-12-20 17:42:22 +00003430 return false;
3431
3432}
3433
Douglas Gregord6ff3322009-08-04 16:50:30 +00003434//===----------------------------------------------------------------------===//
3435// Type transformation
3436//===----------------------------------------------------------------------===//
3437
3438template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003439QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00003440 if (getDerived().AlreadyTransformed(T))
3441 return T;
Mike Stump11289f42009-09-09 15:08:12 +00003442
John McCall550e0c22009-10-21 00:40:46 +00003443 // Temporary workaround. All of these transformations should
3444 // eventually turn into transformations on TypeLocs.
Douglas Gregor2d525f02011-01-25 19:13:18 +00003445 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3446 getDerived().getBaseLocation());
Chad Rosier1dcde962012-08-08 18:46:20 +00003447
John McCall31f82722010-11-12 08:19:04 +00003448 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00003449
John McCall550e0c22009-10-21 00:40:46 +00003450 if (!NewDI)
3451 return QualType();
3452
3453 return NewDI->getType();
3454}
3455
3456template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003457TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smith764d2fe2011-12-20 02:08:33 +00003458 // Refine the base location to the type's location.
3459 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3460 getDerived().getBaseEntity());
John McCall550e0c22009-10-21 00:40:46 +00003461 if (getDerived().AlreadyTransformed(DI->getType()))
3462 return DI;
3463
3464 TypeLocBuilder TLB;
3465
3466 TypeLoc TL = DI->getTypeLoc();
3467 TLB.reserve(TL.getFullDataSize());
3468
John McCall31f82722010-11-12 08:19:04 +00003469 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00003470 if (Result.isNull())
3471 return 0;
3472
John McCallbcd03502009-12-07 02:54:59 +00003473 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00003474}
3475
3476template<typename Derived>
3477QualType
John McCall31f82722010-11-12 08:19:04 +00003478TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003479 switch (T.getTypeLocClass()) {
3480#define ABSTRACT_TYPELOC(CLASS, PARENT)
David Blaikie6adc78e2013-02-18 22:06:02 +00003481#define TYPELOC(CLASS, PARENT) \
3482 case TypeLoc::CLASS: \
3483 return getDerived().Transform##CLASS##Type(TLB, \
3484 T.castAs<CLASS##TypeLoc>());
John McCall550e0c22009-10-21 00:40:46 +00003485#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00003486 }
Mike Stump11289f42009-09-09 15:08:12 +00003487
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003488 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00003489}
3490
3491/// FIXME: By default, this routine adds type qualifiers only to types
3492/// that can have qualifiers, and silently suppresses those qualifiers
3493/// that are not permitted (e.g., qualifiers on reference or function
3494/// types). This is the right thing for template instantiation, but
3495/// probably not for other clients.
3496template<typename Derived>
3497QualType
3498TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003499 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00003500 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00003501
John McCall31f82722010-11-12 08:19:04 +00003502 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00003503 if (Result.isNull())
3504 return QualType();
3505
3506 // Silently suppress qualifiers if the result type can't be qualified.
3507 // FIXME: this is the right thing for template instantiation, but
3508 // probably not for other clients.
3509 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00003510 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00003511
John McCall31168b02011-06-15 23:02:42 +00003512 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore46db902011-06-17 22:11:49 +00003513 // resulting type.
3514 if (Quals.hasObjCLifetime()) {
3515 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3516 Quals.removeObjCLifetime();
Douglas Gregord7357a92011-06-17 23:16:24 +00003517 else if (Result.getObjCLifetime()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003518 // Objective-C ARC:
Douglas Gregore46db902011-06-17 22:11:49 +00003519 // A lifetime qualifier applied to a substituted template parameter
3520 // overrides the lifetime qualifier from the template argument.
Douglas Gregorf4e43312013-01-17 23:59:28 +00003521 const AutoType *AutoTy;
Chad Rosier1dcde962012-08-08 18:46:20 +00003522 if (const SubstTemplateTypeParmType *SubstTypeParam
Douglas Gregore46db902011-06-17 22:11:49 +00003523 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3524 QualType Replacement = SubstTypeParam->getReplacementType();
3525 Qualifiers Qs = Replacement.getQualifiers();
3526 Qs.removeObjCLifetime();
Chad Rosier1dcde962012-08-08 18:46:20 +00003527 Replacement
Douglas Gregore46db902011-06-17 22:11:49 +00003528 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3529 Qs);
3530 Result = SemaRef.Context.getSubstTemplateTypeParmType(
Chad Rosier1dcde962012-08-08 18:46:20 +00003531 SubstTypeParam->getReplacedParameter(),
Douglas Gregore46db902011-06-17 22:11:49 +00003532 Replacement);
3533 TLB.TypeWasModifiedSafely(Result);
Douglas Gregorf4e43312013-01-17 23:59:28 +00003534 } else if ((AutoTy = dyn_cast<AutoType>(Result)) && AutoTy->isDeduced()) {
3535 // 'auto' types behave the same way as template parameters.
3536 QualType Deduced = AutoTy->getDeducedType();
3537 Qualifiers Qs = Deduced.getQualifiers();
3538 Qs.removeObjCLifetime();
3539 Deduced = SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(),
3540 Qs);
Faisal Vali2b391ab2013-09-26 19:54:12 +00003541 Result = SemaRef.Context.getAutoType(Deduced, AutoTy->isDecltypeAuto(),
3542 AutoTy->isDependentType());
Douglas Gregorf4e43312013-01-17 23:59:28 +00003543 TLB.TypeWasModifiedSafely(Result);
Douglas Gregore46db902011-06-17 22:11:49 +00003544 } else {
Douglas Gregord7357a92011-06-17 23:16:24 +00003545 // Otherwise, complain about the addition of a qualifier to an
3546 // already-qualified type.
Eli Friedman7152fbe2013-06-07 20:31:48 +00003547 SourceRange R = T.getUnqualifiedLoc().getSourceRange();
Argyrios Kyrtzidiscff00d92011-06-24 00:08:59 +00003548 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregord7357a92011-06-17 23:16:24 +00003549 << Result << R;
Chad Rosier1dcde962012-08-08 18:46:20 +00003550
Douglas Gregore46db902011-06-17 22:11:49 +00003551 Quals.removeObjCLifetime();
3552 }
3553 }
3554 }
John McCallcb0f89a2010-06-05 06:41:15 +00003555 if (!Quals.empty()) {
3556 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
Richard Smithdeec0742013-03-27 23:36:39 +00003557 // BuildQualifiedType might not add qualifiers if they are invalid.
3558 if (Result.hasLocalQualifiers())
3559 TLB.push<QualifiedTypeLoc>(Result);
John McCallcb0f89a2010-06-05 06:41:15 +00003560 // No location information to preserve.
3561 }
John McCall550e0c22009-10-21 00:40:46 +00003562
3563 return Result;
3564}
3565
Douglas Gregor14454802011-02-25 02:25:35 +00003566template<typename Derived>
3567TypeLoc
3568TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3569 QualType ObjectType,
3570 NamedDecl *UnqualLookup,
3571 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003572 if (getDerived().AlreadyTransformed(TL.getType()))
Douglas Gregor14454802011-02-25 02:25:35 +00003573 return TL;
Chad Rosier1dcde962012-08-08 18:46:20 +00003574
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003575 TypeSourceInfo *TSI =
3576 TransformTSIInObjectScope(TL, ObjectType, UnqualLookup, SS);
3577 if (TSI)
3578 return TSI->getTypeLoc();
3579 return TypeLoc();
Douglas Gregor14454802011-02-25 02:25:35 +00003580}
3581
Douglas Gregor579c15f2011-03-02 18:32:08 +00003582template<typename Derived>
3583TypeSourceInfo *
3584TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3585 QualType ObjectType,
3586 NamedDecl *UnqualLookup,
3587 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003588 if (getDerived().AlreadyTransformed(TSInfo->getType()))
Douglas Gregor579c15f2011-03-02 18:32:08 +00003589 return TSInfo;
Chad Rosier1dcde962012-08-08 18:46:20 +00003590
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003591 return TransformTSIInObjectScope(TSInfo->getTypeLoc(), ObjectType,
3592 UnqualLookup, SS);
3593}
3594
3595template <typename Derived>
3596TypeSourceInfo *TreeTransform<Derived>::TransformTSIInObjectScope(
3597 TypeLoc TL, QualType ObjectType, NamedDecl *UnqualLookup,
3598 CXXScopeSpec &SS) {
3599 QualType T = TL.getType();
3600 assert(!getDerived().AlreadyTransformed(T));
3601
Douglas Gregor579c15f2011-03-02 18:32:08 +00003602 TypeLocBuilder TLB;
3603 QualType Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00003604
Douglas Gregor579c15f2011-03-02 18:32:08 +00003605 if (isa<TemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00003606 TemplateSpecializationTypeLoc SpecTL =
3607 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00003608
Douglas Gregor579c15f2011-03-02 18:32:08 +00003609 TemplateName Template
3610 = getDerived().TransformTemplateName(SS,
3611 SpecTL.getTypePtr()->getTemplateName(),
3612 SpecTL.getTemplateNameLoc(),
3613 ObjectType, UnqualLookup);
Chad Rosier1dcde962012-08-08 18:46:20 +00003614 if (Template.isNull())
Douglas Gregor579c15f2011-03-02 18:32:08 +00003615 return 0;
Chad Rosier1dcde962012-08-08 18:46:20 +00003616
3617 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregor579c15f2011-03-02 18:32:08 +00003618 Template);
3619 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00003620 DependentTemplateSpecializationTypeLoc SpecTL =
3621 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00003622
Douglas Gregor579c15f2011-03-02 18:32:08 +00003623 TemplateName Template
Chad Rosier1dcde962012-08-08 18:46:20 +00003624 = getDerived().RebuildTemplateName(SS,
3625 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00003626 SpecTL.getTemplateNameLoc(),
Douglas Gregor579c15f2011-03-02 18:32:08 +00003627 ObjectType, UnqualLookup);
3628 if (Template.isNull())
3629 return 0;
Chad Rosier1dcde962012-08-08 18:46:20 +00003630
3631 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregor579c15f2011-03-02 18:32:08 +00003632 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00003633 Template,
3634 SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00003635 } else {
3636 // Nothing special needs to be done for these.
3637 Result = getDerived().TransformType(TLB, TL);
3638 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003639
3640 if (Result.isNull())
Douglas Gregor579c15f2011-03-02 18:32:08 +00003641 return 0;
Chad Rosier1dcde962012-08-08 18:46:20 +00003642
Douglas Gregor579c15f2011-03-02 18:32:08 +00003643 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3644}
3645
John McCall550e0c22009-10-21 00:40:46 +00003646template <class TyLoc> static inline
3647QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3648 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3649 NewT.setNameLoc(T.getNameLoc());
3650 return T.getType();
3651}
3652
John McCall550e0c22009-10-21 00:40:46 +00003653template<typename Derived>
3654QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003655 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00003656 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3657 NewT.setBuiltinLoc(T.getBuiltinLoc());
3658 if (T.needsExtraLocalData())
3659 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3660 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003661}
Mike Stump11289f42009-09-09 15:08:12 +00003662
Douglas Gregord6ff3322009-08-04 16:50:30 +00003663template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003664QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003665 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003666 // FIXME: recurse?
3667 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003668}
Mike Stump11289f42009-09-09 15:08:12 +00003669
Reid Kleckner0503a872013-12-05 01:23:43 +00003670template <typename Derived>
3671QualType TreeTransform<Derived>::TransformAdjustedType(TypeLocBuilder &TLB,
3672 AdjustedTypeLoc TL) {
3673 // Adjustments applied during transformation are handled elsewhere.
3674 return getDerived().TransformType(TLB, TL.getOriginalLoc());
3675}
3676
Douglas Gregord6ff3322009-08-04 16:50:30 +00003677template<typename Derived>
Reid Kleckner8a365022013-06-24 17:51:48 +00003678QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
3679 DecayedTypeLoc TL) {
3680 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
3681 if (OriginalType.isNull())
3682 return QualType();
3683
3684 QualType Result = TL.getType();
3685 if (getDerived().AlwaysRebuild() ||
3686 OriginalType != TL.getOriginalLoc().getType())
3687 Result = SemaRef.Context.getDecayedType(OriginalType);
3688 TLB.push<DecayedTypeLoc>(Result);
3689 // Nothing to set for DecayedTypeLoc.
3690 return Result;
3691}
3692
3693template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003694QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003695 PointerTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003696 QualType PointeeType
3697 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003698 if (PointeeType.isNull())
3699 return QualType();
3700
3701 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00003702 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003703 // A dependent pointer type 'T *' has is being transformed such
3704 // that an Objective-C class type is being replaced for 'T'. The
3705 // resulting pointer type is an ObjCObjectPointerType, not a
3706 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00003707 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier1dcde962012-08-08 18:46:20 +00003708
John McCall8b07ec22010-05-15 11:32:37 +00003709 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3710 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003711 return Result;
3712 }
John McCall31f82722010-11-12 08:19:04 +00003713
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003714 if (getDerived().AlwaysRebuild() ||
3715 PointeeType != TL.getPointeeLoc().getType()) {
3716 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3717 if (Result.isNull())
3718 return QualType();
3719 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003720
John McCall31168b02011-06-15 23:02:42 +00003721 // Objective-C ARC can add lifetime qualifiers to the type that we're
3722 // pointing to.
3723 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier1dcde962012-08-08 18:46:20 +00003724
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003725 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3726 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00003727 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003728}
Mike Stump11289f42009-09-09 15:08:12 +00003729
3730template<typename Derived>
3731QualType
John McCall550e0c22009-10-21 00:40:46 +00003732TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003733 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00003734 QualType PointeeType
Chad Rosier1dcde962012-08-08 18:46:20 +00003735 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3736 if (PointeeType.isNull())
3737 return QualType();
3738
3739 QualType Result = TL.getType();
3740 if (getDerived().AlwaysRebuild() ||
3741 PointeeType != TL.getPointeeLoc().getType()) {
3742 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00003743 TL.getSigilLoc());
3744 if (Result.isNull())
3745 return QualType();
3746 }
3747
Douglas Gregor049211a2010-04-22 16:50:51 +00003748 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00003749 NewT.setSigilLoc(TL.getSigilLoc());
3750 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003751}
3752
John McCall70dd5f62009-10-30 00:06:24 +00003753/// Transforms a reference type. Note that somewhat paradoxically we
3754/// don't care whether the type itself is an l-value type or an r-value
3755/// type; we only care if the type was *written* as an l-value type
3756/// or an r-value type.
3757template<typename Derived>
3758QualType
3759TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003760 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00003761 const ReferenceType *T = TL.getTypePtr();
3762
3763 // Note that this works with the pointee-as-written.
3764 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3765 if (PointeeType.isNull())
3766 return QualType();
3767
3768 QualType Result = TL.getType();
3769 if (getDerived().AlwaysRebuild() ||
3770 PointeeType != T->getPointeeTypeAsWritten()) {
3771 Result = getDerived().RebuildReferenceType(PointeeType,
3772 T->isSpelledAsLValue(),
3773 TL.getSigilLoc());
3774 if (Result.isNull())
3775 return QualType();
3776 }
3777
John McCall31168b02011-06-15 23:02:42 +00003778 // Objective-C ARC can add lifetime qualifiers to the type that we're
3779 // referring to.
3780 TLB.TypeWasModifiedSafely(
3781 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3782
John McCall70dd5f62009-10-30 00:06:24 +00003783 // r-value references can be rebuilt as l-value references.
3784 ReferenceTypeLoc NewTL;
3785 if (isa<LValueReferenceType>(Result))
3786 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3787 else
3788 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3789 NewTL.setSigilLoc(TL.getSigilLoc());
3790
3791 return Result;
3792}
3793
Mike Stump11289f42009-09-09 15:08:12 +00003794template<typename Derived>
3795QualType
John McCall550e0c22009-10-21 00:40:46 +00003796TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003797 LValueReferenceTypeLoc TL) {
3798 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003799}
3800
Mike Stump11289f42009-09-09 15:08:12 +00003801template<typename Derived>
3802QualType
John McCall550e0c22009-10-21 00:40:46 +00003803TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003804 RValueReferenceTypeLoc TL) {
3805 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003806}
Mike Stump11289f42009-09-09 15:08:12 +00003807
Douglas Gregord6ff3322009-08-04 16:50:30 +00003808template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003809QualType
John McCall550e0c22009-10-21 00:40:46 +00003810TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003811 MemberPointerTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003812 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003813 if (PointeeType.isNull())
3814 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003815
Abramo Bagnara509357842011-03-05 14:42:21 +00003816 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
3817 TypeSourceInfo* NewClsTInfo = 0;
3818 if (OldClsTInfo) {
3819 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3820 if (!NewClsTInfo)
3821 return QualType();
3822 }
3823
3824 const MemberPointerType *T = TL.getTypePtr();
3825 QualType OldClsType = QualType(T->getClass(), 0);
3826 QualType NewClsType;
3827 if (NewClsTInfo)
3828 NewClsType = NewClsTInfo->getType();
3829 else {
3830 NewClsType = getDerived().TransformType(OldClsType);
3831 if (NewClsType.isNull())
3832 return QualType();
3833 }
Mike Stump11289f42009-09-09 15:08:12 +00003834
John McCall550e0c22009-10-21 00:40:46 +00003835 QualType Result = TL.getType();
3836 if (getDerived().AlwaysRebuild() ||
3837 PointeeType != T->getPointeeType() ||
Abramo Bagnara509357842011-03-05 14:42:21 +00003838 NewClsType != OldClsType) {
3839 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall70dd5f62009-10-30 00:06:24 +00003840 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00003841 if (Result.isNull())
3842 return QualType();
3843 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00003844
Reid Kleckner0503a872013-12-05 01:23:43 +00003845 // If we had to adjust the pointee type when building a member pointer, make
3846 // sure to push TypeLoc info for it.
3847 const MemberPointerType *MPT = Result->getAs<MemberPointerType>();
3848 if (MPT && PointeeType != MPT->getPointeeType()) {
3849 assert(isa<AdjustedType>(MPT->getPointeeType()));
3850 TLB.push<AdjustedTypeLoc>(MPT->getPointeeType());
3851 }
3852
John McCall550e0c22009-10-21 00:40:46 +00003853 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3854 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnara509357842011-03-05 14:42:21 +00003855 NewTL.setClassTInfo(NewClsTInfo);
John McCall550e0c22009-10-21 00:40:46 +00003856
3857 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003858}
3859
Mike Stump11289f42009-09-09 15:08:12 +00003860template<typename Derived>
3861QualType
John McCall550e0c22009-10-21 00:40:46 +00003862TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003863 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003864 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003865 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003866 if (ElementType.isNull())
3867 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003868
John McCall550e0c22009-10-21 00:40:46 +00003869 QualType Result = TL.getType();
3870 if (getDerived().AlwaysRebuild() ||
3871 ElementType != T->getElementType()) {
3872 Result = getDerived().RebuildConstantArrayType(ElementType,
3873 T->getSizeModifier(),
3874 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00003875 T->getIndexTypeCVRQualifiers(),
3876 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003877 if (Result.isNull())
3878 return QualType();
3879 }
Eli Friedmanf7f102f2012-01-25 22:19:07 +00003880
3881 // We might have either a ConstantArrayType or a VariableArrayType now:
3882 // a ConstantArrayType is allowed to have an element type which is a
3883 // VariableArrayType if the type is dependent. Fortunately, all array
3884 // types have the same location layout.
3885 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00003886 NewTL.setLBracketLoc(TL.getLBracketLoc());
3887 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00003888
John McCall550e0c22009-10-21 00:40:46 +00003889 Expr *Size = TL.getSizeExpr();
3890 if (Size) {
Richard Smith764d2fe2011-12-20 02:08:33 +00003891 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3892 Sema::ConstantEvaluated);
John McCall550e0c22009-10-21 00:40:46 +00003893 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
Eli Friedmanc6237c62012-02-29 03:16:56 +00003894 Size = SemaRef.ActOnConstantExpression(Size).take();
John McCall550e0c22009-10-21 00:40:46 +00003895 }
3896 NewTL.setSizeExpr(Size);
3897
3898 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003899}
Mike Stump11289f42009-09-09 15:08:12 +00003900
Douglas Gregord6ff3322009-08-04 16:50:30 +00003901template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003902QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00003903 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003904 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003905 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003906 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003907 if (ElementType.isNull())
3908 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003909
John McCall550e0c22009-10-21 00:40:46 +00003910 QualType Result = TL.getType();
3911 if (getDerived().AlwaysRebuild() ||
3912 ElementType != T->getElementType()) {
3913 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00003914 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00003915 T->getIndexTypeCVRQualifiers(),
3916 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003917 if (Result.isNull())
3918 return QualType();
3919 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003920
John McCall550e0c22009-10-21 00:40:46 +00003921 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3922 NewTL.setLBracketLoc(TL.getLBracketLoc());
3923 NewTL.setRBracketLoc(TL.getRBracketLoc());
3924 NewTL.setSizeExpr(0);
3925
3926 return Result;
3927}
3928
3929template<typename Derived>
3930QualType
3931TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003932 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003933 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003934 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3935 if (ElementType.isNull())
3936 return QualType();
3937
John McCalldadc5752010-08-24 06:29:42 +00003938 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00003939 = getDerived().TransformExpr(T->getSizeExpr());
3940 if (SizeResult.isInvalid())
3941 return QualType();
3942
John McCallb268a282010-08-23 23:25:46 +00003943 Expr *Size = SizeResult.take();
John McCall550e0c22009-10-21 00:40:46 +00003944
3945 QualType Result = TL.getType();
3946 if (getDerived().AlwaysRebuild() ||
3947 ElementType != T->getElementType() ||
3948 Size != T->getSizeExpr()) {
3949 Result = getDerived().RebuildVariableArrayType(ElementType,
3950 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00003951 Size,
John McCall550e0c22009-10-21 00:40:46 +00003952 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00003953 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003954 if (Result.isNull())
3955 return QualType();
3956 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003957
Serge Pavlov774c6d02014-02-06 03:49:11 +00003958 // We might have constant size array now, but fortunately it has the same
3959 // location layout.
3960 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00003961 NewTL.setLBracketLoc(TL.getLBracketLoc());
3962 NewTL.setRBracketLoc(TL.getRBracketLoc());
3963 NewTL.setSizeExpr(Size);
3964
3965 return Result;
3966}
3967
3968template<typename Derived>
3969QualType
3970TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003971 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003972 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003973 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3974 if (ElementType.isNull())
3975 return QualType();
3976
Richard Smith764d2fe2011-12-20 02:08:33 +00003977 // Array bounds are constant expressions.
3978 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3979 Sema::ConstantEvaluated);
John McCall550e0c22009-10-21 00:40:46 +00003980
John McCall33ddac02011-01-19 10:06:00 +00003981 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3982 Expr *origSize = TL.getSizeExpr();
3983 if (!origSize) origSize = T->getSizeExpr();
3984
3985 ExprResult sizeResult
3986 = getDerived().TransformExpr(origSize);
Eli Friedmanc6237c62012-02-29 03:16:56 +00003987 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall33ddac02011-01-19 10:06:00 +00003988 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00003989 return QualType();
3990
John McCall33ddac02011-01-19 10:06:00 +00003991 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00003992
3993 QualType Result = TL.getType();
3994 if (getDerived().AlwaysRebuild() ||
3995 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00003996 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00003997 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3998 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00003999 size,
John McCall550e0c22009-10-21 00:40:46 +00004000 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004001 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004002 if (Result.isNull())
4003 return QualType();
4004 }
John McCall550e0c22009-10-21 00:40:46 +00004005
4006 // We might have any sort of array type now, but fortunately they
4007 // all have the same location layout.
4008 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4009 NewTL.setLBracketLoc(TL.getLBracketLoc());
4010 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00004011 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00004012
4013 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004014}
Mike Stump11289f42009-09-09 15:08:12 +00004015
4016template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004017QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00004018 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004019 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004020 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004021
4022 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00004023 QualType ElementType = getDerived().TransformType(T->getElementType());
4024 if (ElementType.isNull())
4025 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004026
Richard Smith764d2fe2011-12-20 02:08:33 +00004027 // Vector sizes are constant expressions.
4028 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4029 Sema::ConstantEvaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00004030
John McCalldadc5752010-08-24 06:29:42 +00004031 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanc6237c62012-02-29 03:16:56 +00004032 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004033 if (Size.isInvalid())
4034 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004035
John McCall550e0c22009-10-21 00:40:46 +00004036 QualType Result = TL.getType();
4037 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00004038 ElementType != T->getElementType() ||
4039 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00004040 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCallb268a282010-08-23 23:25:46 +00004041 Size.take(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00004042 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00004043 if (Result.isNull())
4044 return QualType();
4045 }
John McCall550e0c22009-10-21 00:40:46 +00004046
4047 // Result might be dependent or not.
4048 if (isa<DependentSizedExtVectorType>(Result)) {
4049 DependentSizedExtVectorTypeLoc NewTL
4050 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
4051 NewTL.setNameLoc(TL.getNameLoc());
4052 } else {
4053 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4054 NewTL.setNameLoc(TL.getNameLoc());
4055 }
4056
4057 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004058}
Mike Stump11289f42009-09-09 15:08:12 +00004059
4060template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004061QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004062 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004063 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004064 QualType ElementType = getDerived().TransformType(T->getElementType());
4065 if (ElementType.isNull())
4066 return QualType();
4067
John McCall550e0c22009-10-21 00:40:46 +00004068 QualType Result = TL.getType();
4069 if (getDerived().AlwaysRebuild() ||
4070 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00004071 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00004072 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00004073 if (Result.isNull())
4074 return QualType();
4075 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004076
John McCall550e0c22009-10-21 00:40:46 +00004077 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
4078 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004079
John McCall550e0c22009-10-21 00:40:46 +00004080 return Result;
4081}
4082
4083template<typename Derived>
4084QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004085 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004086 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004087 QualType ElementType = getDerived().TransformType(T->getElementType());
4088 if (ElementType.isNull())
4089 return QualType();
4090
4091 QualType Result = TL.getType();
4092 if (getDerived().AlwaysRebuild() ||
4093 ElementType != T->getElementType()) {
4094 Result = getDerived().RebuildExtVectorType(ElementType,
4095 T->getNumElements(),
4096 /*FIXME*/ SourceLocation());
4097 if (Result.isNull())
4098 return QualType();
4099 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004100
John McCall550e0c22009-10-21 00:40:46 +00004101 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4102 NewTL.setNameLoc(TL.getNameLoc());
4103
4104 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004105}
Mike Stump11289f42009-09-09 15:08:12 +00004106
David Blaikie05785d12013-02-20 22:23:23 +00004107template <typename Derived>
4108ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
4109 ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
4110 bool ExpectParameterPack) {
John McCall58f10c32010-03-11 09:03:00 +00004111 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor715e4612011-01-14 22:40:04 +00004112 TypeSourceInfo *NewDI = 0;
Chad Rosier1dcde962012-08-08 18:46:20 +00004113
Douglas Gregor715e4612011-01-14 22:40:04 +00004114 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004115 // If we're substituting into a pack expansion type and we know the
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004116 // length we want to expand to, just substitute for the pattern.
Douglas Gregor715e4612011-01-14 22:40:04 +00004117 TypeLoc OldTL = OldDI->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004118 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004119
Douglas Gregor715e4612011-01-14 22:40:04 +00004120 TypeLocBuilder TLB;
4121 TypeLoc NewTL = OldDI->getTypeLoc();
4122 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00004123
4124 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor715e4612011-01-14 22:40:04 +00004125 OldExpansionTL.getPatternLoc());
4126 if (Result.isNull())
4127 return 0;
Chad Rosier1dcde962012-08-08 18:46:20 +00004128
4129 Result = RebuildPackExpansionType(Result,
4130 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor715e4612011-01-14 22:40:04 +00004131 OldExpansionTL.getEllipsisLoc(),
4132 NumExpansions);
4133 if (Result.isNull())
4134 return 0;
Chad Rosier1dcde962012-08-08 18:46:20 +00004135
Douglas Gregor715e4612011-01-14 22:40:04 +00004136 PackExpansionTypeLoc NewExpansionTL
4137 = TLB.push<PackExpansionTypeLoc>(Result);
4138 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
4139 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
4140 } else
4141 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00004142 if (!NewDI)
4143 return 0;
4144
John McCall8fb0d9d2011-05-01 22:35:37 +00004145 if (NewDI == OldDI && indexAdjustment == 0)
John McCall58f10c32010-03-11 09:03:00 +00004146 return OldParm;
John McCall8fb0d9d2011-05-01 22:35:37 +00004147
4148 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
4149 OldParm->getDeclContext(),
4150 OldParm->getInnerLocStart(),
4151 OldParm->getLocation(),
4152 OldParm->getIdentifier(),
4153 NewDI->getType(),
4154 NewDI,
4155 OldParm->getStorageClass(),
John McCall8fb0d9d2011-05-01 22:35:37 +00004156 /* DefArg */ NULL);
4157 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
4158 OldParm->getFunctionScopeIndex() + indexAdjustment);
4159 return newParm;
John McCall58f10c32010-03-11 09:03:00 +00004160}
4161
4162template<typename Derived>
4163bool TreeTransform<Derived>::
Douglas Gregordd472162011-01-07 00:20:55 +00004164 TransformFunctionTypeParams(SourceLocation Loc,
4165 ParmVarDecl **Params, unsigned NumParams,
4166 const QualType *ParamTypes,
Chris Lattner01cf8db2011-07-20 06:58:45 +00004167 SmallVectorImpl<QualType> &OutParamTypes,
4168 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004169 int indexAdjustment = 0;
4170
Douglas Gregordd472162011-01-07 00:20:55 +00004171 for (unsigned i = 0; i != NumParams; ++i) {
4172 if (ParmVarDecl *OldParm = Params[i]) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004173 assert(OldParm->getFunctionScopeIndex() == i);
4174
David Blaikie05785d12013-02-20 22:23:23 +00004175 Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004176 ParmVarDecl *NewParm = 0;
Douglas Gregor5499af42011-01-05 23:12:31 +00004177 if (OldParm->isParameterPack()) {
4178 // We have a function parameter pack that may need to be expanded.
Chris Lattner01cf8db2011-07-20 06:58:45 +00004179 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00004180
Douglas Gregor5499af42011-01-05 23:12:31 +00004181 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004182 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004183 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004184 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4185 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004186 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4187
Douglas Gregor5499af42011-01-05 23:12:31 +00004188 // Determine whether we should expand the parameter packs.
4189 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004190 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004191 Optional<unsigned> OrigNumExpansions =
4192 ExpansionTL.getTypePtr()->getNumExpansions();
Douglas Gregor715e4612011-01-14 22:40:04 +00004193 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004194 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4195 Pattern.getSourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004196 Unexpanded,
4197 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004198 RetainExpansion,
4199 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004200 return true;
4201 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004202
Douglas Gregor5499af42011-01-05 23:12:31 +00004203 if (ShouldExpand) {
4204 // Expand the function parameter pack into multiple, separate
4205 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00004206 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004207 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004208 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier1dcde962012-08-08 18:46:20 +00004209 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004210 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004211 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004212 OrigNumExpansions,
4213 /*ExpectParameterPack=*/false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004214 if (!NewParm)
4215 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004216
Douglas Gregordd472162011-01-07 00:20:55 +00004217 OutParamTypes.push_back(NewParm->getType());
4218 if (PVars)
4219 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004220 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004221
4222 // If we're supposed to retain a pack expansion, do so by temporarily
4223 // forgetting the partially-substituted parameter pack.
4224 if (RetainExpansion) {
4225 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00004226 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004227 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004228 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004229 OrigNumExpansions,
4230 /*ExpectParameterPack=*/false);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004231 if (!NewParm)
4232 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004233
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004234 OutParamTypes.push_back(NewParm->getType());
4235 if (PVars)
4236 PVars->push_back(NewParm);
4237 }
4238
John McCall8fb0d9d2011-05-01 22:35:37 +00004239 // The next parameter should have the same adjustment as the
4240 // last thing we pushed, but we post-incremented indexAdjustment
4241 // on every push. Also, if we push nothing, the adjustment should
4242 // go down by one.
4243 indexAdjustment--;
4244
Douglas Gregor5499af42011-01-05 23:12:31 +00004245 // We're done with the pack expansion.
4246 continue;
4247 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004248
4249 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004250 // expansion.
Douglas Gregorc52264e2011-03-02 02:04:06 +00004251 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4252 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004253 indexAdjustment,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004254 NumExpansions,
4255 /*ExpectParameterPack=*/true);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004256 } else {
David Blaikie05785d12013-02-20 22:23:23 +00004257 NewParm = getDerived().TransformFunctionTypeParam(
David Blaikie7a30dc52013-02-21 01:47:18 +00004258 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004259 }
Douglas Gregorc52264e2011-03-02 02:04:06 +00004260
John McCall58f10c32010-03-11 09:03:00 +00004261 if (!NewParm)
4262 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004263
Douglas Gregordd472162011-01-07 00:20:55 +00004264 OutParamTypes.push_back(NewParm->getType());
4265 if (PVars)
4266 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004267 continue;
4268 }
John McCall58f10c32010-03-11 09:03:00 +00004269
4270 // Deal with the possibility that we don't have a parameter
4271 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00004272 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00004273 bool IsPackExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004274 Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004275 QualType NewType;
Chad Rosier1dcde962012-08-08 18:46:20 +00004276 if (const PackExpansionType *Expansion
Douglas Gregor5499af42011-01-05 23:12:31 +00004277 = dyn_cast<PackExpansionType>(OldType)) {
4278 // We have a function parameter pack that may need to be expanded.
4279 QualType Pattern = Expansion->getPattern();
Chris Lattner01cf8db2011-07-20 06:58:45 +00004280 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor5499af42011-01-05 23:12:31 +00004281 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00004282
Douglas Gregor5499af42011-01-05 23:12:31 +00004283 // Determine whether we should expand the parameter packs.
4284 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004285 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00004286 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004287 Unexpanded,
4288 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004289 RetainExpansion,
4290 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00004291 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00004292 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004293
Douglas Gregor5499af42011-01-05 23:12:31 +00004294 if (ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004295 // Expand the function parameter pack into multiple, separate
Douglas Gregor5499af42011-01-05 23:12:31 +00004296 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004297 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004298 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4299 QualType NewType = getDerived().TransformType(Pattern);
4300 if (NewType.isNull())
4301 return true;
John McCall58f10c32010-03-11 09:03:00 +00004302
Douglas Gregordd472162011-01-07 00:20:55 +00004303 OutParamTypes.push_back(NewType);
4304 if (PVars)
4305 PVars->push_back(0);
Douglas Gregor5499af42011-01-05 23:12:31 +00004306 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004307
Douglas Gregor5499af42011-01-05 23:12:31 +00004308 // We're done with the pack expansion.
4309 continue;
4310 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004311
Douglas Gregor48d24112011-01-10 20:53:55 +00004312 // If we're supposed to retain a pack expansion, do so by temporarily
4313 // forgetting the partially-substituted parameter pack.
4314 if (RetainExpansion) {
4315 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4316 QualType NewType = getDerived().TransformType(Pattern);
4317 if (NewType.isNull())
4318 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004319
Douglas Gregor48d24112011-01-10 20:53:55 +00004320 OutParamTypes.push_back(NewType);
4321 if (PVars)
4322 PVars->push_back(0);
4323 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004324
Chad Rosier1dcde962012-08-08 18:46:20 +00004325 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004326 // expansion.
4327 OldType = Expansion->getPattern();
4328 IsPackExpansion = true;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004329 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4330 NewType = getDerived().TransformType(OldType);
4331 } else {
4332 NewType = getDerived().TransformType(OldType);
Douglas Gregor5499af42011-01-05 23:12:31 +00004333 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004334
Douglas Gregor5499af42011-01-05 23:12:31 +00004335 if (NewType.isNull())
4336 return true;
4337
4338 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004339 NewType = getSema().Context.getPackExpansionType(NewType,
4340 NumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00004341
Douglas Gregordd472162011-01-07 00:20:55 +00004342 OutParamTypes.push_back(NewType);
4343 if (PVars)
4344 PVars->push_back(0);
John McCall58f10c32010-03-11 09:03:00 +00004345 }
4346
John McCall8fb0d9d2011-05-01 22:35:37 +00004347#ifndef NDEBUG
4348 if (PVars) {
4349 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4350 if (ParmVarDecl *parm = (*PVars)[i])
4351 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor5499af42011-01-05 23:12:31 +00004352 }
John McCall8fb0d9d2011-05-01 22:35:37 +00004353#endif
4354
4355 return false;
4356}
John McCall58f10c32010-03-11 09:03:00 +00004357
4358template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004359QualType
John McCall550e0c22009-10-21 00:40:46 +00004360TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004361 FunctionProtoTypeLoc TL) {
Douglas Gregor3024f072012-04-16 07:05:22 +00004362 return getDerived().TransformFunctionProtoType(TLB, TL, 0, 0);
4363}
4364
4365template<typename Derived>
4366QualType
4367TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
4368 FunctionProtoTypeLoc TL,
4369 CXXRecordDecl *ThisContext,
4370 unsigned ThisTypeQuals) {
Douglas Gregor4afc2362010-08-31 00:26:14 +00004371 // Transform the parameters and return type.
4372 //
Richard Smithf623c962012-04-17 00:58:00 +00004373 // We are required to instantiate the params and return type in source order.
Douglas Gregor7fb25412010-10-01 18:44:50 +00004374 // When the function has a trailing return type, we instantiate the
4375 // parameters before the return type, since the return type can then refer
4376 // to the parameters themselves (via decltype, sizeof, etc.).
4377 //
Chris Lattner01cf8db2011-07-20 06:58:45 +00004378 SmallVector<QualType, 4> ParamTypes;
4379 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall424cec92011-01-19 06:33:43 +00004380 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00004381
Douglas Gregor7fb25412010-10-01 18:44:50 +00004382 QualType ResultType;
4383
Richard Smith1226c602012-08-14 22:51:13 +00004384 if (T->hasTrailingReturn()) {
Alp Toker9cacbab2014-01-20 20:26:09 +00004385 if (getDerived().TransformFunctionTypeParams(
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004386 TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(),
Alp Toker9cacbab2014-01-20 20:26:09 +00004387 TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004388 return QualType();
4389
Douglas Gregor3024f072012-04-16 07:05:22 +00004390 {
4391 // C++11 [expr.prim.general]p3:
Chad Rosier1dcde962012-08-08 18:46:20 +00004392 // If a declaration declares a member function or member function
4393 // template of a class X, the expression this is a prvalue of type
Douglas Gregor3024f072012-04-16 07:05:22 +00004394 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier1dcde962012-08-08 18:46:20 +00004395 // and the end of the function-definition, member-declarator, or
Douglas Gregor3024f072012-04-16 07:05:22 +00004396 // declarator.
4397 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier1dcde962012-08-08 18:46:20 +00004398
Alp Toker42a16a62014-01-25 23:51:36 +00004399 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor3024f072012-04-16 07:05:22 +00004400 if (ResultType.isNull())
4401 return QualType();
4402 }
Douglas Gregor7fb25412010-10-01 18:44:50 +00004403 }
4404 else {
Alp Toker42a16a62014-01-25 23:51:36 +00004405 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00004406 if (ResultType.isNull())
4407 return QualType();
4408
Alp Toker9cacbab2014-01-20 20:26:09 +00004409 if (getDerived().TransformFunctionTypeParams(
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004410 TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(),
Alp Toker9cacbab2014-01-20 20:26:09 +00004411 TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004412 return QualType();
4413 }
4414
Richard Smithf623c962012-04-17 00:58:00 +00004415 // FIXME: Need to transform the exception-specification too.
4416
John McCall550e0c22009-10-21 00:40:46 +00004417 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00004418 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() ||
Alp Toker9cacbab2014-01-20 20:26:09 +00004419 T->getNumParams() != ParamTypes.size() ||
4420 !std::equal(T->param_type_begin(), T->param_type_end(),
4421 ParamTypes.begin())) {
Jordan Rose5c382722013-03-08 21:51:21 +00004422 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +00004423 T->getExtProtoInfo());
John McCall550e0c22009-10-21 00:40:46 +00004424 if (Result.isNull())
4425 return QualType();
4426 }
Mike Stump11289f42009-09-09 15:08:12 +00004427
John McCall550e0c22009-10-21 00:40:46 +00004428 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004429 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00004430 NewTL.setLParenLoc(TL.getLParenLoc());
4431 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004432 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004433 for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i)
4434 NewTL.setParam(i, ParamDecls[i]);
John McCall550e0c22009-10-21 00:40:46 +00004435
4436 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004437}
Mike Stump11289f42009-09-09 15:08:12 +00004438
Douglas Gregord6ff3322009-08-04 16:50:30 +00004439template<typename Derived>
4440QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00004441 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004442 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004443 const FunctionNoProtoType *T = TL.getTypePtr();
Alp Toker42a16a62014-01-25 23:51:36 +00004444 QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
John McCall550e0c22009-10-21 00:40:46 +00004445 if (ResultType.isNull())
4446 return QualType();
4447
4448 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00004449 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType())
John McCall550e0c22009-10-21 00:40:46 +00004450 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4451
4452 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004453 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00004454 NewTL.setLParenLoc(TL.getLParenLoc());
4455 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004456 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCall550e0c22009-10-21 00:40:46 +00004457
4458 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004459}
Mike Stump11289f42009-09-09 15:08:12 +00004460
John McCallb96ec562009-12-04 22:46:56 +00004461template<typename Derived> QualType
4462TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004463 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004464 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004465 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00004466 if (!D)
4467 return QualType();
4468
4469 QualType Result = TL.getType();
4470 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4471 Result = getDerived().RebuildUnresolvedUsingType(D);
4472 if (Result.isNull())
4473 return QualType();
4474 }
4475
4476 // We might get an arbitrary type spec type back. We should at
4477 // least always get a type spec type, though.
4478 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4479 NewTL.setNameLoc(TL.getNameLoc());
4480
4481 return Result;
4482}
4483
Douglas Gregord6ff3322009-08-04 16:50:30 +00004484template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004485QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004486 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004487 const TypedefType *T = TL.getTypePtr();
Richard Smithdda56e42011-04-15 14:24:37 +00004488 TypedefNameDecl *Typedef
4489 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4490 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004491 if (!Typedef)
4492 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004493
John McCall550e0c22009-10-21 00:40:46 +00004494 QualType Result = TL.getType();
4495 if (getDerived().AlwaysRebuild() ||
4496 Typedef != T->getDecl()) {
4497 Result = getDerived().RebuildTypedefType(Typedef);
4498 if (Result.isNull())
4499 return QualType();
4500 }
Mike Stump11289f42009-09-09 15:08:12 +00004501
John McCall550e0c22009-10-21 00:40:46 +00004502 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4503 NewTL.setNameLoc(TL.getNameLoc());
4504
4505 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004506}
Mike Stump11289f42009-09-09 15:08:12 +00004507
Douglas Gregord6ff3322009-08-04 16:50:30 +00004508template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004509QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004510 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00004511 // typeof expressions are not potentially evaluated contexts
Eli Friedman15681d62012-09-26 04:34:21 +00004512 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4513 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00004514
John McCalldadc5752010-08-24 06:29:42 +00004515 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004516 if (E.isInvalid())
4517 return QualType();
4518
Eli Friedmane4f22df2012-02-29 04:03:55 +00004519 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
4520 if (E.isInvalid())
4521 return QualType();
4522
John McCall550e0c22009-10-21 00:40:46 +00004523 QualType Result = TL.getType();
4524 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00004525 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004526 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00004527 if (Result.isNull())
4528 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004529 }
John McCall550e0c22009-10-21 00:40:46 +00004530 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00004531
John McCall550e0c22009-10-21 00:40:46 +00004532 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004533 NewTL.setTypeofLoc(TL.getTypeofLoc());
4534 NewTL.setLParenLoc(TL.getLParenLoc());
4535 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00004536
4537 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004538}
Mike Stump11289f42009-09-09 15:08:12 +00004539
4540template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004541QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004542 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00004543 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4544 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4545 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00004546 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004547
John McCall550e0c22009-10-21 00:40:46 +00004548 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00004549 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4550 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00004551 if (Result.isNull())
4552 return QualType();
4553 }
Mike Stump11289f42009-09-09 15:08:12 +00004554
John McCall550e0c22009-10-21 00:40:46 +00004555 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004556 NewTL.setTypeofLoc(TL.getTypeofLoc());
4557 NewTL.setLParenLoc(TL.getLParenLoc());
4558 NewTL.setRParenLoc(TL.getRParenLoc());
4559 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00004560
4561 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004562}
Mike Stump11289f42009-09-09 15:08:12 +00004563
4564template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004565QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004566 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004567 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004568
Douglas Gregore922c772009-08-04 22:27:00 +00004569 // decltype expressions are not potentially evaluated contexts
Richard Smithfd555f62012-02-22 02:04:18 +00004570 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, 0,
4571 /*IsDecltype=*/ true);
Mike Stump11289f42009-09-09 15:08:12 +00004572
John McCalldadc5752010-08-24 06:29:42 +00004573 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004574 if (E.isInvalid())
4575 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004576
Richard Smithfd555f62012-02-22 02:04:18 +00004577 E = getSema().ActOnDecltypeExpression(E.take());
4578 if (E.isInvalid())
4579 return QualType();
4580
John McCall550e0c22009-10-21 00:40:46 +00004581 QualType Result = TL.getType();
4582 if (getDerived().AlwaysRebuild() ||
4583 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004584 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004585 if (Result.isNull())
4586 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004587 }
John McCall550e0c22009-10-21 00:40:46 +00004588 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00004589
John McCall550e0c22009-10-21 00:40:46 +00004590 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4591 NewTL.setNameLoc(TL.getNameLoc());
4592
4593 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004594}
4595
4596template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00004597QualType TreeTransform<Derived>::TransformUnaryTransformType(
4598 TypeLocBuilder &TLB,
4599 UnaryTransformTypeLoc TL) {
4600 QualType Result = TL.getType();
4601 if (Result->isDependentType()) {
4602 const UnaryTransformType *T = TL.getTypePtr();
4603 QualType NewBase =
4604 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4605 Result = getDerived().RebuildUnaryTransformType(NewBase,
4606 T->getUTTKind(),
4607 TL.getKWLoc());
4608 if (Result.isNull())
4609 return QualType();
4610 }
4611
4612 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4613 NewTL.setKWLoc(TL.getKWLoc());
4614 NewTL.setParensRange(TL.getParensRange());
4615 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4616 return Result;
4617}
4618
4619template<typename Derived>
Richard Smith30482bc2011-02-20 03:19:35 +00004620QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4621 AutoTypeLoc TL) {
4622 const AutoType *T = TL.getTypePtr();
4623 QualType OldDeduced = T->getDeducedType();
4624 QualType NewDeduced;
4625 if (!OldDeduced.isNull()) {
4626 NewDeduced = getDerived().TransformType(OldDeduced);
4627 if (NewDeduced.isNull())
4628 return QualType();
4629 }
4630
4631 QualType Result = TL.getType();
Richard Smith27d807c2013-04-30 13:56:41 +00004632 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
4633 T->isDependentType()) {
Richard Smith74aeef52013-04-26 16:15:35 +00004634 Result = getDerived().RebuildAutoType(NewDeduced, T->isDecltypeAuto());
Richard Smith30482bc2011-02-20 03:19:35 +00004635 if (Result.isNull())
4636 return QualType();
4637 }
4638
4639 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4640 NewTL.setNameLoc(TL.getNameLoc());
4641
4642 return Result;
4643}
4644
4645template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004646QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004647 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004648 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004649 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004650 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4651 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004652 if (!Record)
4653 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004654
John McCall550e0c22009-10-21 00:40:46 +00004655 QualType Result = TL.getType();
4656 if (getDerived().AlwaysRebuild() ||
4657 Record != T->getDecl()) {
4658 Result = getDerived().RebuildRecordType(Record);
4659 if (Result.isNull())
4660 return QualType();
4661 }
Mike Stump11289f42009-09-09 15:08:12 +00004662
John McCall550e0c22009-10-21 00:40:46 +00004663 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4664 NewTL.setNameLoc(TL.getNameLoc());
4665
4666 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004667}
Mike Stump11289f42009-09-09 15:08:12 +00004668
4669template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004670QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004671 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004672 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004673 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004674 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4675 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004676 if (!Enum)
4677 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004678
John McCall550e0c22009-10-21 00:40:46 +00004679 QualType Result = TL.getType();
4680 if (getDerived().AlwaysRebuild() ||
4681 Enum != T->getDecl()) {
4682 Result = getDerived().RebuildEnumType(Enum);
4683 if (Result.isNull())
4684 return QualType();
4685 }
Mike Stump11289f42009-09-09 15:08:12 +00004686
John McCall550e0c22009-10-21 00:40:46 +00004687 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4688 NewTL.setNameLoc(TL.getNameLoc());
4689
4690 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004691}
John McCallfcc33b02009-09-05 00:15:47 +00004692
John McCalle78aac42010-03-10 03:28:59 +00004693template<typename Derived>
4694QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4695 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004696 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00004697 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4698 TL.getTypePtr()->getDecl());
4699 if (!D) return QualType();
4700
4701 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4702 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4703 return T;
4704}
4705
Douglas Gregord6ff3322009-08-04 16:50:30 +00004706template<typename Derived>
4707QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004708 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004709 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004710 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004711}
4712
Mike Stump11289f42009-09-09 15:08:12 +00004713template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00004714QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004715 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004716 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004717 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00004718
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004719 // Substitute into the replacement type, which itself might involve something
4720 // that needs to be transformed. This only tends to occur with default
4721 // template arguments of template template parameters.
4722 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4723 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4724 if (Replacement.isNull())
4725 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00004726
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004727 // Always canonicalize the replacement type.
4728 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4729 QualType Result
Chad Rosier1dcde962012-08-08 18:46:20 +00004730 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004731 Replacement);
Chad Rosier1dcde962012-08-08 18:46:20 +00004732
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004733 // Propagate type-source information.
4734 SubstTemplateTypeParmTypeLoc NewTL
4735 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4736 NewTL.setNameLoc(TL.getNameLoc());
4737 return Result;
4738
John McCallcebee162009-10-18 09:09:24 +00004739}
4740
4741template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00004742QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4743 TypeLocBuilder &TLB,
4744 SubstTemplateTypeParmPackTypeLoc TL) {
4745 return TransformTypeSpecType(TLB, TL);
4746}
4747
4748template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00004749QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00004750 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004751 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00004752 const TemplateSpecializationType *T = TL.getTypePtr();
4753
Douglas Gregordf846d12011-03-02 18:46:51 +00004754 // The nested-name-specifier never matters in a TemplateSpecializationType,
4755 // because we can't have a dependent nested-name-specifier anyway.
4756 CXXScopeSpec SS;
Mike Stump11289f42009-09-09 15:08:12 +00004757 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00004758 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4759 TL.getTemplateNameLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004760 if (Template.isNull())
4761 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004762
John McCall31f82722010-11-12 08:19:04 +00004763 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4764}
4765
Eli Friedman0dfb8892011-10-06 23:00:33 +00004766template<typename Derived>
4767QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
4768 AtomicTypeLoc TL) {
4769 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
4770 if (ValueType.isNull())
4771 return QualType();
4772
4773 QualType Result = TL.getType();
4774 if (getDerived().AlwaysRebuild() ||
4775 ValueType != TL.getValueLoc().getType()) {
4776 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
4777 if (Result.isNull())
4778 return QualType();
4779 }
4780
4781 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
4782 NewTL.setKWLoc(TL.getKWLoc());
4783 NewTL.setLParenLoc(TL.getLParenLoc());
4784 NewTL.setRParenLoc(TL.getRParenLoc());
4785
4786 return Result;
4787}
4788
Chad Rosier1dcde962012-08-08 18:46:20 +00004789 /// \brief Simple iterator that traverses the template arguments in a
Douglas Gregorfe921a72010-12-20 23:36:19 +00004790 /// container that provides a \c getArgLoc() member function.
4791 ///
4792 /// This iterator is intended to be used with the iterator form of
4793 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4794 template<typename ArgLocContainer>
4795 class TemplateArgumentLocContainerIterator {
4796 ArgLocContainer *Container;
4797 unsigned Index;
Chad Rosier1dcde962012-08-08 18:46:20 +00004798
Douglas Gregorfe921a72010-12-20 23:36:19 +00004799 public:
4800 typedef TemplateArgumentLoc value_type;
4801 typedef TemplateArgumentLoc reference;
4802 typedef int difference_type;
4803 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00004804
Douglas Gregorfe921a72010-12-20 23:36:19 +00004805 class pointer {
4806 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00004807
Douglas Gregorfe921a72010-12-20 23:36:19 +00004808 public:
4809 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00004810
Douglas Gregorfe921a72010-12-20 23:36:19 +00004811 const TemplateArgumentLoc *operator->() const {
4812 return &Arg;
4813 }
4814 };
Chad Rosier1dcde962012-08-08 18:46:20 +00004815
4816
Douglas Gregorfe921a72010-12-20 23:36:19 +00004817 TemplateArgumentLocContainerIterator() {}
Chad Rosier1dcde962012-08-08 18:46:20 +00004818
Douglas Gregorfe921a72010-12-20 23:36:19 +00004819 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4820 unsigned Index)
4821 : Container(&Container), Index(Index) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00004822
Douglas Gregorfe921a72010-12-20 23:36:19 +00004823 TemplateArgumentLocContainerIterator &operator++() {
4824 ++Index;
4825 return *this;
4826 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004827
Douglas Gregorfe921a72010-12-20 23:36:19 +00004828 TemplateArgumentLocContainerIterator operator++(int) {
4829 TemplateArgumentLocContainerIterator Old(*this);
4830 ++(*this);
4831 return Old;
4832 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004833
Douglas Gregorfe921a72010-12-20 23:36:19 +00004834 TemplateArgumentLoc operator*() const {
4835 return Container->getArgLoc(Index);
4836 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004837
Douglas Gregorfe921a72010-12-20 23:36:19 +00004838 pointer operator->() const {
4839 return pointer(Container->getArgLoc(Index));
4840 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004841
Douglas Gregorfe921a72010-12-20 23:36:19 +00004842 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004843 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004844 return X.Container == Y.Container && X.Index == Y.Index;
4845 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004846
Douglas Gregorfe921a72010-12-20 23:36:19 +00004847 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004848 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004849 return !(X == Y);
4850 }
4851 };
Chad Rosier1dcde962012-08-08 18:46:20 +00004852
4853
John McCall31f82722010-11-12 08:19:04 +00004854template <typename Derived>
4855QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4856 TypeLocBuilder &TLB,
4857 TemplateSpecializationTypeLoc TL,
4858 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00004859 TemplateArgumentListInfo NewTemplateArgs;
4860 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4861 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00004862 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4863 ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00004864 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregorfe921a72010-12-20 23:36:19 +00004865 ArgIterator(TL, TL.getNumArgs()),
4866 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00004867 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004868
John McCall0ad16662009-10-29 08:12:44 +00004869 // FIXME: maybe don't rebuild if all the template arguments are the same.
4870
4871 QualType Result =
4872 getDerived().RebuildTemplateSpecializationType(Template,
4873 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00004874 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00004875
4876 if (!Result.isNull()) {
Richard Smith3f1b5d02011-05-05 21:57:07 +00004877 // Specializations of template template parameters are represented as
4878 // TemplateSpecializationTypes, and substitution of type alias templates
4879 // within a dependent context can transform them into
4880 // DependentTemplateSpecializationTypes.
4881 if (isa<DependentTemplateSpecializationType>(Result)) {
4882 DependentTemplateSpecializationTypeLoc NewTL
4883 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004884 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3f1b5d02011-05-05 21:57:07 +00004885 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00004886 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004887 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3f1b5d02011-05-05 21:57:07 +00004888 NewTL.setLAngleLoc(TL.getLAngleLoc());
4889 NewTL.setRAngleLoc(TL.getRAngleLoc());
4890 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4891 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4892 return Result;
4893 }
4894
John McCall0ad16662009-10-29 08:12:44 +00004895 TemplateSpecializationTypeLoc NewTL
4896 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004897 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall0ad16662009-10-29 08:12:44 +00004898 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4899 NewTL.setLAngleLoc(TL.getLAngleLoc());
4900 NewTL.setRAngleLoc(TL.getRAngleLoc());
4901 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4902 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004903 }
Mike Stump11289f42009-09-09 15:08:12 +00004904
John McCall0ad16662009-10-29 08:12:44 +00004905 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004906}
Mike Stump11289f42009-09-09 15:08:12 +00004907
Douglas Gregor5a064722011-02-28 17:23:35 +00004908template <typename Derived>
4909QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4910 TypeLocBuilder &TLB,
4911 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +00004912 TemplateName Template,
4913 CXXScopeSpec &SS) {
Douglas Gregor5a064722011-02-28 17:23:35 +00004914 TemplateArgumentListInfo NewTemplateArgs;
4915 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4916 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4917 typedef TemplateArgumentLocContainerIterator<
4918 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00004919 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor5a064722011-02-28 17:23:35 +00004920 ArgIterator(TL, TL.getNumArgs()),
4921 NewTemplateArgs))
4922 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00004923
Douglas Gregor5a064722011-02-28 17:23:35 +00004924 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier1dcde962012-08-08 18:46:20 +00004925
Douglas Gregor5a064722011-02-28 17:23:35 +00004926 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4927 QualType Result
4928 = getSema().Context.getDependentTemplateSpecializationType(
4929 TL.getTypePtr()->getKeyword(),
4930 DTN->getQualifier(),
4931 DTN->getIdentifier(),
4932 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00004933
Douglas Gregor5a064722011-02-28 17:23:35 +00004934 DependentTemplateSpecializationTypeLoc NewTL
4935 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004936 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004937 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00004938 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004939 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00004940 NewTL.setLAngleLoc(TL.getLAngleLoc());
4941 NewTL.setRAngleLoc(TL.getRAngleLoc());
4942 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4943 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4944 return Result;
4945 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004946
4947 QualType Result
Douglas Gregor5a064722011-02-28 17:23:35 +00004948 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004949 TL.getTemplateNameLoc(),
Douglas Gregor5a064722011-02-28 17:23:35 +00004950 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00004951
Douglas Gregor5a064722011-02-28 17:23:35 +00004952 if (!Result.isNull()) {
4953 /// FIXME: Wrap this in an elaborated-type-specifier?
4954 TemplateSpecializationTypeLoc NewTL
4955 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00004956 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004957 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00004958 NewTL.setLAngleLoc(TL.getLAngleLoc());
4959 NewTL.setRAngleLoc(TL.getRAngleLoc());
4960 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4961 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4962 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004963
Douglas Gregor5a064722011-02-28 17:23:35 +00004964 return Result;
4965}
4966
Mike Stump11289f42009-09-09 15:08:12 +00004967template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004968QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00004969TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004970 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004971 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00004972
Douglas Gregor844cb502011-03-01 18:12:44 +00004973 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara6150c882010-05-11 21:36:43 +00004974 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor844cb502011-03-01 18:12:44 +00004975 if (TL.getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004976 QualifierLoc
Douglas Gregor844cb502011-03-01 18:12:44 +00004977 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4978 if (!QualifierLoc)
Abramo Bagnara6150c882010-05-11 21:36:43 +00004979 return QualType();
4980 }
Mike Stump11289f42009-09-09 15:08:12 +00004981
John McCall31f82722010-11-12 08:19:04 +00004982 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4983 if (NamedT.isNull())
4984 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00004985
Richard Smith3f1b5d02011-05-05 21:57:07 +00004986 // C++0x [dcl.type.elab]p2:
4987 // If the identifier resolves to a typedef-name or the simple-template-id
4988 // resolves to an alias template specialization, the
4989 // elaborated-type-specifier is ill-formed.
Richard Smith0c4a34b2011-05-14 15:04:18 +00004990 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
4991 if (const TemplateSpecializationType *TST =
4992 NamedT->getAs<TemplateSpecializationType>()) {
4993 TemplateName Template = TST->getTemplateName();
4994 if (TypeAliasTemplateDecl *TAT =
4995 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
4996 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
4997 diag::err_tag_reference_non_tag) << 4;
4998 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
4999 }
Richard Smith3f1b5d02011-05-05 21:57:07 +00005000 }
5001 }
5002
John McCall550e0c22009-10-21 00:40:46 +00005003 QualType Result = TL.getType();
5004 if (getDerived().AlwaysRebuild() ||
Douglas Gregor844cb502011-03-01 18:12:44 +00005005 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00005006 NamedT != T->getNamedType()) {
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005007 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00005008 T->getKeyword(),
Douglas Gregor844cb502011-03-01 18:12:44 +00005009 QualifierLoc, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00005010 if (Result.isNull())
5011 return QualType();
5012 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00005013
Abramo Bagnara6150c882010-05-11 21:36:43 +00005014 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005015 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005016 NewTL.setQualifierLoc(QualifierLoc);
John McCall550e0c22009-10-21 00:40:46 +00005017 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005018}
Mike Stump11289f42009-09-09 15:08:12 +00005019
5020template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00005021QualType TreeTransform<Derived>::TransformAttributedType(
5022 TypeLocBuilder &TLB,
5023 AttributedTypeLoc TL) {
5024 const AttributedType *oldType = TL.getTypePtr();
5025 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
5026 if (modifiedType.isNull())
5027 return QualType();
5028
5029 QualType result = TL.getType();
5030
5031 // FIXME: dependent operand expressions?
5032 if (getDerived().AlwaysRebuild() ||
5033 modifiedType != oldType->getModifiedType()) {
5034 // TODO: this is really lame; we should really be rebuilding the
5035 // equivalent type from first principles.
5036 QualType equivalentType
5037 = getDerived().TransformType(oldType->getEquivalentType());
5038 if (equivalentType.isNull())
5039 return QualType();
5040 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
5041 modifiedType,
5042 equivalentType);
5043 }
5044
5045 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
5046 newTL.setAttrNameLoc(TL.getAttrNameLoc());
5047 if (TL.hasAttrOperand())
5048 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5049 if (TL.hasAttrExprOperand())
5050 newTL.setAttrExprOperand(TL.getAttrExprOperand());
5051 else if (TL.hasAttrEnumOperand())
5052 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
5053
5054 return result;
5055}
5056
5057template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00005058QualType
5059TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
5060 ParenTypeLoc TL) {
5061 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
5062 if (Inner.isNull())
5063 return QualType();
5064
5065 QualType Result = TL.getType();
5066 if (getDerived().AlwaysRebuild() ||
5067 Inner != TL.getInnerLoc().getType()) {
5068 Result = getDerived().RebuildParenType(Inner);
5069 if (Result.isNull())
5070 return QualType();
5071 }
5072
5073 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
5074 NewTL.setLParenLoc(TL.getLParenLoc());
5075 NewTL.setRParenLoc(TL.getRParenLoc());
5076 return Result;
5077}
5078
5079template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00005080QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005081 DependentNameTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005082 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00005083
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005084 NestedNameSpecifierLoc QualifierLoc
5085 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5086 if (!QualifierLoc)
Douglas Gregord6ff3322009-08-04 16:50:30 +00005087 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005088
John McCallc392f372010-06-11 00:33:02 +00005089 QualType Result
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005090 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005091 TL.getElaboratedKeywordLoc(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005092 QualifierLoc,
5093 T->getIdentifier(),
John McCallc392f372010-06-11 00:33:02 +00005094 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00005095 if (Result.isNull())
5096 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005097
Abramo Bagnarad7548482010-05-19 21:37:53 +00005098 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
5099 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00005100 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
5101
Abramo Bagnarad7548482010-05-19 21:37:53 +00005102 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005103 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005104 NewTL.setQualifierLoc(QualifierLoc);
John McCallc392f372010-06-11 00:33:02 +00005105 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00005106 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005107 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005108 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00005109 NewTL.setNameLoc(TL.getNameLoc());
5110 }
John McCall550e0c22009-10-21 00:40:46 +00005111 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005112}
Mike Stump11289f42009-09-09 15:08:12 +00005113
Douglas Gregord6ff3322009-08-04 16:50:30 +00005114template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00005115QualType TreeTransform<Derived>::
5116 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005117 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregora7a795b2011-03-01 20:11:18 +00005118 NestedNameSpecifierLoc QualifierLoc;
5119 if (TL.getQualifierLoc()) {
5120 QualifierLoc
5121 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5122 if (!QualifierLoc)
Douglas Gregor5a064722011-02-28 17:23:35 +00005123 return QualType();
5124 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005125
John McCall31f82722010-11-12 08:19:04 +00005126 return getDerived()
Douglas Gregora7a795b2011-03-01 20:11:18 +00005127 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall31f82722010-11-12 08:19:04 +00005128}
5129
5130template<typename Derived>
5131QualType TreeTransform<Derived>::
Douglas Gregora7a795b2011-03-01 20:11:18 +00005132TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
5133 DependentTemplateSpecializationTypeLoc TL,
5134 NestedNameSpecifierLoc QualifierLoc) {
5135 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00005136
Douglas Gregora7a795b2011-03-01 20:11:18 +00005137 TemplateArgumentListInfo NewTemplateArgs;
5138 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5139 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00005140
Douglas Gregora7a795b2011-03-01 20:11:18 +00005141 typedef TemplateArgumentLocContainerIterator<
5142 DependentTemplateSpecializationTypeLoc> ArgIterator;
5143 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5144 ArgIterator(TL, TL.getNumArgs()),
5145 NewTemplateArgs))
5146 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005147
Douglas Gregora7a795b2011-03-01 20:11:18 +00005148 QualType Result
5149 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
5150 QualifierLoc,
5151 T->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005152 TL.getTemplateNameLoc(),
Douglas Gregora7a795b2011-03-01 20:11:18 +00005153 NewTemplateArgs);
5154 if (Result.isNull())
5155 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005156
Douglas Gregora7a795b2011-03-01 20:11:18 +00005157 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
5158 QualType NamedT = ElabT->getNamedType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005159
Douglas Gregora7a795b2011-03-01 20:11:18 +00005160 // Copy information relevant to the template specialization.
5161 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor43f788f2011-03-07 02:33:33 +00005162 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005163 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005164 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005165 NamedTL.setLAngleLoc(TL.getLAngleLoc());
5166 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005167 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005168 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier1dcde962012-08-08 18:46:20 +00005169
Douglas Gregora7a795b2011-03-01 20:11:18 +00005170 // Copy information relevant to the elaborated type.
5171 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005172 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005173 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor43f788f2011-03-07 02:33:33 +00005174 } else if (isa<DependentTemplateSpecializationType>(Result)) {
5175 DependentTemplateSpecializationTypeLoc SpecTL
5176 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005177 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005178 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005179 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005180 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005181 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5182 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005183 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005184 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005185 } else {
Douglas Gregor43f788f2011-03-07 02:33:33 +00005186 TemplateSpecializationTypeLoc SpecTL
5187 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005188 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005189 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005190 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5191 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005192 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005193 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005194 }
5195 return Result;
5196}
5197
5198template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00005199QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5200 PackExpansionTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005201 QualType Pattern
5202 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor822d0302011-01-12 17:07:58 +00005203 if (Pattern.isNull())
5204 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005205
5206 QualType Result = TL.getType();
Douglas Gregor822d0302011-01-12 17:07:58 +00005207 if (getDerived().AlwaysRebuild() ||
5208 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005209 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00005210 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00005211 TL.getEllipsisLoc(),
5212 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00005213 if (Result.isNull())
5214 return QualType();
5215 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005216
Douglas Gregor822d0302011-01-12 17:07:58 +00005217 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5218 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5219 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00005220}
5221
5222template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005223QualType
5224TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005225 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005226 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00005227 TLB.pushFullCopy(TL);
5228 return TL.getType();
5229}
5230
5231template<typename Derived>
5232QualType
5233TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005234 ObjCObjectTypeLoc TL) {
John McCall8b07ec22010-05-15 11:32:37 +00005235 // ObjCObjectType is never dependent.
5236 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00005237 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005238}
Mike Stump11289f42009-09-09 15:08:12 +00005239
5240template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005241QualType
5242TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005243 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005244 // ObjCObjectPointerType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00005245 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00005246 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00005247}
5248
Douglas Gregord6ff3322009-08-04 16:50:30 +00005249//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00005250// Statement transformation
5251//===----------------------------------------------------------------------===//
5252template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005253StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005254TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00005255 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005256}
5257
5258template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005259StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005260TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
5261 return getDerived().TransformCompoundStmt(S, false);
5262}
5263
5264template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005265StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005266TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00005267 bool IsStmtExpr) {
Dmitri Gribenko800ddf32012-02-14 22:14:32 +00005268 Sema::CompoundScopeRAII CompoundScope(getSema());
5269
John McCall1ababa62010-08-27 19:56:05 +00005270 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00005271 bool SubStmtChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005272 SmallVector<Stmt*, 8> Statements;
Douglas Gregorebe10102009-08-20 07:17:43 +00005273 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
5274 B != BEnd; ++B) {
John McCalldadc5752010-08-24 06:29:42 +00005275 StmtResult Result = getDerived().TransformStmt(*B);
John McCall1ababa62010-08-27 19:56:05 +00005276 if (Result.isInvalid()) {
5277 // Immediately fail if this was a DeclStmt, since it's very
5278 // likely that this will cause problems for future statements.
5279 if (isa<DeclStmt>(*B))
5280 return StmtError();
5281
5282 // Otherwise, just keep processing substatements and fail later.
5283 SubStmtInvalid = true;
5284 continue;
5285 }
Mike Stump11289f42009-09-09 15:08:12 +00005286
Douglas Gregorebe10102009-08-20 07:17:43 +00005287 SubStmtChanged = SubStmtChanged || Result.get() != *B;
5288 Statements.push_back(Result.takeAs<Stmt>());
5289 }
Mike Stump11289f42009-09-09 15:08:12 +00005290
John McCall1ababa62010-08-27 19:56:05 +00005291 if (SubStmtInvalid)
5292 return StmtError();
5293
Douglas Gregorebe10102009-08-20 07:17:43 +00005294 if (!getDerived().AlwaysRebuild() &&
5295 !SubStmtChanged)
John McCallc3007a22010-10-26 07:05:15 +00005296 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005297
5298 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00005299 Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00005300 S->getRBracLoc(),
5301 IsStmtExpr);
5302}
Mike Stump11289f42009-09-09 15:08:12 +00005303
Douglas Gregorebe10102009-08-20 07:17:43 +00005304template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005305StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005306TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005307 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00005308 {
Eli Friedman1f4f9dd2012-01-18 02:54:10 +00005309 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5310 Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005311
Eli Friedman06577382009-11-19 03:14:00 +00005312 // Transform the left-hand case value.
5313 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00005314 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman06577382009-11-19 03:14:00 +00005315 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005316 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005317
Eli Friedman06577382009-11-19 03:14:00 +00005318 // Transform the right-hand case value (for the GNU case-range extension).
5319 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00005320 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman06577382009-11-19 03:14:00 +00005321 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005322 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00005323 }
Mike Stump11289f42009-09-09 15:08:12 +00005324
Douglas Gregorebe10102009-08-20 07:17:43 +00005325 // Build the case statement.
5326 // Case statements are always rebuilt so that they will attached to their
5327 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005328 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00005329 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005330 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00005331 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005332 S->getColonLoc());
5333 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005334 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005335
Douglas Gregorebe10102009-08-20 07:17:43 +00005336 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00005337 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005338 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005339 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005340
Douglas Gregorebe10102009-08-20 07:17:43 +00005341 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00005342 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005343}
5344
5345template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005346StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005347TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005348 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00005349 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005350 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005351 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005352
Douglas Gregorebe10102009-08-20 07:17:43 +00005353 // Default statements are always rebuilt
5354 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00005355 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005356}
Mike Stump11289f42009-09-09 15:08:12 +00005357
Douglas Gregorebe10102009-08-20 07:17:43 +00005358template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005359StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005360TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005361 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005362 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005363 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005364
Chris Lattnercab02a62011-02-17 20:34:02 +00005365 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5366 S->getDecl());
5367 if (!LD)
5368 return StmtError();
Richard Smithc202b282012-04-14 00:33:13 +00005369
5370
Douglas Gregorebe10102009-08-20 07:17:43 +00005371 // FIXME: Pass the real colon location in.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00005372 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005373 cast<LabelDecl>(LD), SourceLocation(),
5374 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005375}
Mike Stump11289f42009-09-09 15:08:12 +00005376
Douglas Gregorebe10102009-08-20 07:17:43 +00005377template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005378StmtResult
Richard Smithc202b282012-04-14 00:33:13 +00005379TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
5380 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5381 if (SubStmt.isInvalid())
5382 return StmtError();
5383
5384 // TODO: transform attributes
5385 if (SubStmt.get() == S->getSubStmt() /* && attrs are the same */)
5386 return S;
5387
5388 return getDerived().RebuildAttributedStmt(S->getAttrLoc(),
5389 S->getAttrs(),
5390 SubStmt.get());
5391}
5392
5393template<typename Derived>
5394StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005395TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005396 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005397 ExprResult Cond;
Douglas Gregor633caca2009-11-23 23:44:04 +00005398 VarDecl *ConditionVar = 0;
5399 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005400 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00005401 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005402 getDerived().TransformDefinition(
5403 S->getConditionVariable()->getLocation(),
5404 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00005405 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005406 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005407 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00005408 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005409
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005410 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005411 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005412
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005413 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00005414 if (S->getCond()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005415 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005416 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005417 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005418 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005419
John McCallb268a282010-08-23 23:25:46 +00005420 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005421 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005422 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005423
John McCallb268a282010-08-23 23:25:46 +00005424 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5425 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005426 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005427
Douglas Gregorebe10102009-08-20 07:17:43 +00005428 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00005429 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00005430 if (Then.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005431 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005432
Douglas Gregorebe10102009-08-20 07:17:43 +00005433 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00005434 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00005435 if (Else.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005436 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005437
Douglas Gregorebe10102009-08-20 07:17:43 +00005438 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00005439 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005440 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005441 Then.get() == S->getThen() &&
5442 Else.get() == S->getElse())
John McCallc3007a22010-10-26 07:05:15 +00005443 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005444
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005445 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00005446 Then.get(),
John McCallb268a282010-08-23 23:25:46 +00005447 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005448}
5449
5450template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005451StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005452TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005453 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00005454 ExprResult Cond;
Douglas Gregordcf19622009-11-24 17:07:59 +00005455 VarDecl *ConditionVar = 0;
5456 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005457 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00005458 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005459 getDerived().TransformDefinition(
5460 S->getConditionVariable()->getLocation(),
5461 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00005462 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005463 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005464 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00005465 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005466
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005467 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005468 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005469 }
Mike Stump11289f42009-09-09 15:08:12 +00005470
Douglas Gregorebe10102009-08-20 07:17:43 +00005471 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005472 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00005473 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00005474 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00005475 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005476 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005477
Douglas Gregorebe10102009-08-20 07:17:43 +00005478 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005479 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005480 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005481 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005482
Douglas Gregorebe10102009-08-20 07:17:43 +00005483 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00005484 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5485 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005486}
Mike Stump11289f42009-09-09 15:08:12 +00005487
Douglas Gregorebe10102009-08-20 07:17:43 +00005488template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005489StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005490TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005491 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005492 ExprResult Cond;
Douglas Gregor680f8612009-11-24 21:15:44 +00005493 VarDecl *ConditionVar = 0;
5494 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005495 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00005496 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005497 getDerived().TransformDefinition(
5498 S->getConditionVariable()->getLocation(),
5499 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00005500 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005501 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005502 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00005503 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005504
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005505 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005506 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005507
5508 if (S->getCond()) {
5509 // Convert the condition to a boolean value.
Chad Rosier1dcde962012-08-08 18:46:20 +00005510 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005511 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005512 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005513 return StmtError();
John McCallb268a282010-08-23 23:25:46 +00005514 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00005515 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005516 }
Mike Stump11289f42009-09-09 15:08:12 +00005517
John McCallb268a282010-08-23 23:25:46 +00005518 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5519 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005520 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005521
Douglas Gregorebe10102009-08-20 07:17:43 +00005522 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005523 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005524 if (Body.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 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00005528 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005529 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005530 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00005531 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005532
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005533 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00005534 ConditionVar, 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
Douglas Gregorebe10102009-08-20 07:17:43 +00005539TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005540 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005541 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005542 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005543 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005544
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005545 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005546 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005547 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005548 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005549
Douglas Gregorebe10102009-08-20 07:17:43 +00005550 if (!getDerived().AlwaysRebuild() &&
5551 Cond.get() == S->getCond() &&
5552 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005553 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005554
John McCallb268a282010-08-23 23:25:46 +00005555 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5556 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005557 S->getRParenLoc());
5558}
Mike Stump11289f42009-09-09 15:08:12 +00005559
Douglas Gregorebe10102009-08-20 07:17:43 +00005560template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005561StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005562TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005563 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00005564 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00005565 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005566 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005567
Douglas Gregorebe10102009-08-20 07:17:43 +00005568 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005569 ExprResult Cond;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005570 VarDecl *ConditionVar = 0;
5571 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005572 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005573 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005574 getDerived().TransformDefinition(
5575 S->getConditionVariable()->getLocation(),
5576 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005577 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005578 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005579 } else {
5580 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005581
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005582 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005583 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005584
5585 if (S->getCond()) {
5586 // Convert the condition to a boolean value.
Chad Rosier1dcde962012-08-08 18:46:20 +00005587 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005588 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005589 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005590 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005591
John McCallb268a282010-08-23 23:25:46 +00005592 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005593 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005594 }
Mike Stump11289f42009-09-09 15:08:12 +00005595
Chad Rosier1dcde962012-08-08 18:46:20 +00005596 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
John McCallb268a282010-08-23 23:25:46 +00005597 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005598 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005599
Douglas Gregorebe10102009-08-20 07:17:43 +00005600 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00005601 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005602 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005603 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005604
Richard Smith945f8d32013-01-14 22:39:08 +00005605 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
John McCallb268a282010-08-23 23:25:46 +00005606 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005607 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005608
Douglas Gregorebe10102009-08-20 07:17:43 +00005609 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005610 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005611 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005612 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005613
Douglas Gregorebe10102009-08-20 07:17:43 +00005614 if (!getDerived().AlwaysRebuild() &&
5615 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00005616 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005617 Inc.get() == S->getInc() &&
5618 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005619 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005620
Douglas Gregorebe10102009-08-20 07:17:43 +00005621 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005622 Init.get(), FullCond, ConditionVar,
5623 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005624}
5625
5626template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005627StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005628TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattnercab02a62011-02-17 20:34:02 +00005629 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5630 S->getLabel());
5631 if (!LD)
5632 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005633
Douglas Gregorebe10102009-08-20 07:17:43 +00005634 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00005635 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005636 cast<LabelDecl>(LD));
Douglas Gregorebe10102009-08-20 07:17:43 +00005637}
5638
5639template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005640StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005641TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005642 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00005643 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005644 return StmtError();
Eli Friedman9ccdb1d2012-01-31 22:47:07 +00005645 Target = SemaRef.MaybeCreateExprWithCleanups(Target.take());
Mike Stump11289f42009-09-09 15:08:12 +00005646
Douglas Gregorebe10102009-08-20 07:17:43 +00005647 if (!getDerived().AlwaysRebuild() &&
5648 Target.get() == S->getTarget())
John McCallc3007a22010-10-26 07:05:15 +00005649 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005650
5651 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00005652 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005653}
5654
5655template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005656StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005657TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00005658 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005659}
Mike Stump11289f42009-09-09 15:08:12 +00005660
Douglas Gregorebe10102009-08-20 07:17:43 +00005661template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005662StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005663TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00005664 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005665}
Mike Stump11289f42009-09-09 15:08:12 +00005666
Douglas Gregorebe10102009-08-20 07:17:43 +00005667template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005668StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005669TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005670 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregorebe10102009-08-20 07:17:43 +00005671 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005672 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00005673
Mike Stump11289f42009-09-09 15:08:12 +00005674 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00005675 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00005676 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005677}
Mike Stump11289f42009-09-09 15:08:12 +00005678
Douglas Gregorebe10102009-08-20 07:17:43 +00005679template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005680StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005681TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005682 bool DeclChanged = false;
Chris Lattner01cf8db2011-07-20 06:58:45 +00005683 SmallVector<Decl *, 4> Decls;
Douglas Gregorebe10102009-08-20 07:17:43 +00005684 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5685 D != DEnd; ++D) {
Douglas Gregor25289362010-03-01 17:25:41 +00005686 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5687 *D);
Douglas Gregorebe10102009-08-20 07:17:43 +00005688 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00005689 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005690
Douglas Gregorebe10102009-08-20 07:17:43 +00005691 if (Transformed != *D)
5692 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00005693
Douglas Gregorebe10102009-08-20 07:17:43 +00005694 Decls.push_back(Transformed);
5695 }
Mike Stump11289f42009-09-09 15:08:12 +00005696
Douglas Gregorebe10102009-08-20 07:17:43 +00005697 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCallc3007a22010-10-26 07:05:15 +00005698 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005699
Rafael Espindolaab417692013-07-09 12:05:01 +00005700 return getDerived().RebuildDeclStmt(Decls, S->getStartLoc(), S->getEndLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005701}
Mike Stump11289f42009-09-09 15:08:12 +00005702
Douglas Gregorebe10102009-08-20 07:17:43 +00005703template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005704StmtResult
Chad Rosierde70e0e2012-08-25 00:11:56 +00005705TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005706
Benjamin Kramerf0623432012-08-23 22:51:59 +00005707 SmallVector<Expr*, 8> Constraints;
5708 SmallVector<Expr*, 8> Exprs;
Chris Lattner01cf8db2011-07-20 06:58:45 +00005709 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00005710
John McCalldadc5752010-08-24 06:29:42 +00005711 ExprResult AsmString;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005712 SmallVector<Expr*, 8> Clobbers;
Anders Carlssonaaeef072010-01-24 05:50:09 +00005713
5714 bool ExprsChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00005715
Anders Carlssonaaeef072010-01-24 05:50:09 +00005716 // Go through the outputs.
5717 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005718 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005719
Anders Carlssonaaeef072010-01-24 05:50:09 +00005720 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005721 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005722
Anders Carlssonaaeef072010-01-24 05:50:09 +00005723 // Transform the output expr.
5724 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005725 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005726 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005727 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005728
Anders Carlssonaaeef072010-01-24 05:50:09 +00005729 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00005730
John McCallb268a282010-08-23 23:25:46 +00005731 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005732 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005733
Anders Carlssonaaeef072010-01-24 05:50:09 +00005734 // Go through the inputs.
5735 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005736 Names.push_back(S->getInputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005737
Anders Carlssonaaeef072010-01-24 05:50:09 +00005738 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005739 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005740
Anders Carlssonaaeef072010-01-24 05:50:09 +00005741 // Transform the input expr.
5742 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005743 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005744 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005745 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005746
Anders Carlssonaaeef072010-01-24 05:50:09 +00005747 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00005748
John McCallb268a282010-08-23 23:25:46 +00005749 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005750 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005751
Anders Carlssonaaeef072010-01-24 05:50:09 +00005752 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCallc3007a22010-10-26 07:05:15 +00005753 return SemaRef.Owned(S);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005754
5755 // Go through the clobbers.
5756 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosierd9fb09a2012-08-27 23:28:41 +00005757 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00005758
5759 // No need to transform the asm string literal.
5760 AsmString = SemaRef.Owned(S->getAsmString());
Chad Rosierde70e0e2012-08-25 00:11:56 +00005761 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
5762 S->isVolatile(), S->getNumOutputs(),
5763 S->getNumInputs(), Names.data(),
5764 Constraints, Exprs, AsmString.get(),
5765 Clobbers, S->getRParenLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005766}
5767
Chad Rosier32503022012-06-11 20:47:18 +00005768template<typename Derived>
5769StmtResult
5770TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier99fc3812012-08-07 00:29:06 +00005771 ArrayRef<Token> AsmToks =
5772 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier3ed0bd92012-08-08 19:48:07 +00005773
John McCallf413f5e2013-05-03 00:10:13 +00005774 bool HadError = false, HadChange = false;
5775
5776 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
5777 SmallVector<Expr*, 8> TransformedExprs;
5778 TransformedExprs.reserve(SrcExprs.size());
5779 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
5780 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
5781 if (!Result.isUsable()) {
5782 HadError = true;
5783 } else {
5784 HadChange |= (Result.get() != SrcExprs[i]);
5785 TransformedExprs.push_back(Result.take());
5786 }
5787 }
5788
5789 if (HadError) return StmtError();
5790 if (!HadChange && !getDerived().AlwaysRebuild())
5791 return Owned(S);
5792
Chad Rosierb6f46c12012-08-15 16:53:30 +00005793 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
John McCallf413f5e2013-05-03 00:10:13 +00005794 AsmToks, S->getAsmString(),
5795 S->getNumOutputs(), S->getNumInputs(),
5796 S->getAllConstraints(), S->getClobbers(),
5797 TransformedExprs, S->getEndLoc());
Chad Rosier32503022012-06-11 20:47:18 +00005798}
Douglas Gregorebe10102009-08-20 07:17:43 +00005799
5800template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005801StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005802TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005803 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00005804 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005805 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005806 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005807
Douglas Gregor96c79492010-04-23 22:50:49 +00005808 // Transform the @catch statements (if present).
5809 bool AnyCatchChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005810 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor96c79492010-04-23 22:50:49 +00005811 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00005812 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00005813 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005814 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00005815 if (Catch.get() != S->getCatchStmt(I))
5816 AnyCatchChanged = true;
5817 CatchStmts.push_back(Catch.release());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005818 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005819
Douglas Gregor306de2f2010-04-22 23:59:56 +00005820 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00005821 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00005822 if (S->getFinallyStmt()) {
5823 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5824 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005825 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00005826 }
5827
5828 // If nothing changed, just retain this statement.
5829 if (!getDerived().AlwaysRebuild() &&
5830 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00005831 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00005832 Finally.get() == S->getFinallyStmt())
John McCallc3007a22010-10-26 07:05:15 +00005833 return SemaRef.Owned(S);
Chad Rosier1dcde962012-08-08 18:46:20 +00005834
Douglas Gregor306de2f2010-04-22 23:59:56 +00005835 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00005836 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00005837 CatchStmts, Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005838}
Mike Stump11289f42009-09-09 15:08:12 +00005839
Douglas Gregorebe10102009-08-20 07:17:43 +00005840template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005841StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005842TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005843 // Transform the @catch parameter, if there is one.
5844 VarDecl *Var = 0;
5845 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5846 TypeSourceInfo *TSInfo = 0;
5847 if (FromVar->getTypeSourceInfo()) {
5848 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5849 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005850 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005851 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005852
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005853 QualType T;
5854 if (TSInfo)
5855 T = TSInfo->getType();
5856 else {
5857 T = getDerived().TransformType(FromVar->getType());
5858 if (T.isNull())
Chad Rosier1dcde962012-08-08 18:46:20 +00005859 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005860 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005861
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005862 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5863 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00005864 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005865 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005866
John McCalldadc5752010-08-24 06:29:42 +00005867 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005868 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005869 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005870
5871 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005872 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005873 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005874}
Mike Stump11289f42009-09-09 15:08:12 +00005875
Douglas Gregorebe10102009-08-20 07:17:43 +00005876template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005877StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005878TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005879 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005880 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005881 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005882 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005883
Douglas Gregor306de2f2010-04-22 23:59:56 +00005884 // If nothing changed, just retain this statement.
5885 if (!getDerived().AlwaysRebuild() &&
5886 Body.get() == S->getFinallyBody())
John McCallc3007a22010-10-26 07:05:15 +00005887 return SemaRef.Owned(S);
Douglas Gregor306de2f2010-04-22 23:59:56 +00005888
5889 // Build a new statement.
5890 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00005891 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005892}
Mike Stump11289f42009-09-09 15:08:12 +00005893
Douglas Gregorebe10102009-08-20 07:17:43 +00005894template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005895StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005896TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005897 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00005898 if (S->getThrowExpr()) {
5899 Operand = getDerived().TransformExpr(S->getThrowExpr());
5900 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005901 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00005902 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005903
Douglas Gregor2900c162010-04-22 21:44:01 +00005904 if (!getDerived().AlwaysRebuild() &&
5905 Operand.get() == S->getThrowExpr())
John McCallc3007a22010-10-26 07:05:15 +00005906 return getSema().Owned(S);
Chad Rosier1dcde962012-08-08 18:46:20 +00005907
John McCallb268a282010-08-23 23:25:46 +00005908 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005909}
Mike Stump11289f42009-09-09 15:08:12 +00005910
Douglas Gregorebe10102009-08-20 07:17:43 +00005911template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005912StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005913TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00005914 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00005915 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00005916 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00005917 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005918 return StmtError();
John McCalld9bb7432011-07-27 21:50:02 +00005919 Object =
5920 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
5921 Object.get());
5922 if (Object.isInvalid())
5923 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005924
Douglas Gregor6148de72010-04-22 22:01:21 +00005925 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005926 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00005927 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005928 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005929
Douglas Gregor6148de72010-04-22 22:01:21 +00005930 // If nothing change, just retain the current statement.
5931 if (!getDerived().AlwaysRebuild() &&
5932 Object.get() == S->getSynchExpr() &&
5933 Body.get() == S->getSynchBody())
John McCallc3007a22010-10-26 07:05:15 +00005934 return SemaRef.Owned(S);
Douglas Gregor6148de72010-04-22 22:01:21 +00005935
5936 // Build a new statement.
5937 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00005938 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005939}
5940
5941template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005942StmtResult
John McCall31168b02011-06-15 23:02:42 +00005943TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
5944 ObjCAutoreleasePoolStmt *S) {
5945 // Transform the body.
5946 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
5947 if (Body.isInvalid())
5948 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005949
John McCall31168b02011-06-15 23:02:42 +00005950 // If nothing changed, just retain this statement.
5951 if (!getDerived().AlwaysRebuild() &&
5952 Body.get() == S->getSubStmt())
5953 return SemaRef.Owned(S);
5954
5955 // Build a new statement.
5956 return getDerived().RebuildObjCAutoreleasePoolStmt(
5957 S->getAtLoc(), Body.get());
5958}
5959
5960template<typename Derived>
5961StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005962TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00005963 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00005964 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00005965 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005966 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005967 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005968
Douglas Gregorf68a5082010-04-22 23:10:45 +00005969 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00005970 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005971 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005972 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005973
Douglas Gregorf68a5082010-04-22 23:10:45 +00005974 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005975 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005976 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005977 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005978
Douglas Gregorf68a5082010-04-22 23:10:45 +00005979 // If nothing changed, just retain this statement.
5980 if (!getDerived().AlwaysRebuild() &&
5981 Element.get() == S->getElement() &&
5982 Collection.get() == S->getCollection() &&
5983 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005984 return SemaRef.Owned(S);
Chad Rosier1dcde962012-08-08 18:46:20 +00005985
Douglas Gregorf68a5082010-04-22 23:10:45 +00005986 // Build a new statement.
5987 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00005988 Element.get(),
5989 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00005990 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005991 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005992}
5993
David Majnemer5f7efef2013-10-15 09:50:08 +00005994template <typename Derived>
5995StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005996 // Transform the exception declaration, if any.
5997 VarDecl *Var = 0;
David Majnemer5f7efef2013-10-15 09:50:08 +00005998 if (VarDecl *ExceptionDecl = S->getExceptionDecl()) {
5999 TypeSourceInfo *T =
6000 getDerived().TransformType(ExceptionDecl->getTypeSourceInfo());
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00006001 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006002 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006003
David Majnemer5f7efef2013-10-15 09:50:08 +00006004 Var = getDerived().RebuildExceptionDecl(
6005 ExceptionDecl, T, ExceptionDecl->getInnerLocStart(),
6006 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
Douglas Gregorb412e172010-07-25 18:17:45 +00006007 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00006008 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00006009 }
Mike Stump11289f42009-09-09 15:08:12 +00006010
Douglas Gregorebe10102009-08-20 07:17:43 +00006011 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00006012 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00006013 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006014 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006015
David Majnemer5f7efef2013-10-15 09:50:08 +00006016 if (!getDerived().AlwaysRebuild() && !Var &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006017 Handler.get() == S->getHandlerBlock())
John McCallc3007a22010-10-26 07:05:15 +00006018 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00006019
David Majnemer5f7efef2013-10-15 09:50:08 +00006020 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006021}
Mike Stump11289f42009-09-09 15:08:12 +00006022
David Majnemer5f7efef2013-10-15 09:50:08 +00006023template <typename Derived>
6024StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006025 // Transform the try block itself.
David Majnemer5f7efef2013-10-15 09:50:08 +00006026 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
Douglas Gregorebe10102009-08-20 07:17:43 +00006027 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006028 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006029
Douglas Gregorebe10102009-08-20 07:17:43 +00006030 // Transform the handlers.
6031 bool HandlerChanged = false;
David Majnemer5f7efef2013-10-15 09:50:08 +00006032 SmallVector<Stmt *, 8> Handlers;
Douglas Gregorebe10102009-08-20 07:17:43 +00006033 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
David Majnemer5f7efef2013-10-15 09:50:08 +00006034 StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I));
Douglas Gregorebe10102009-08-20 07:17:43 +00006035 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006036 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006037
Douglas Gregorebe10102009-08-20 07:17:43 +00006038 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
6039 Handlers.push_back(Handler.takeAs<Stmt>());
6040 }
Mike Stump11289f42009-09-09 15:08:12 +00006041
David Majnemer5f7efef2013-10-15 09:50:08 +00006042 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006043 !HandlerChanged)
John McCallc3007a22010-10-26 07:05:15 +00006044 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00006045
John McCallb268a282010-08-23 23:25:46 +00006046 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006047 Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00006048}
Mike Stump11289f42009-09-09 15:08:12 +00006049
Richard Smith02e85f32011-04-14 22:09:26 +00006050template<typename Derived>
6051StmtResult
6052TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
6053 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
6054 if (Range.isInvalid())
6055 return StmtError();
6056
6057 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
6058 if (BeginEnd.isInvalid())
6059 return StmtError();
6060
6061 ExprResult Cond = getDerived().TransformExpr(S->getCond());
6062 if (Cond.isInvalid())
6063 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006064 if (Cond.get())
6065 Cond = SemaRef.CheckBooleanCondition(Cond.take(), S->getColonLoc());
6066 if (Cond.isInvalid())
6067 return StmtError();
6068 if (Cond.get())
6069 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.take());
Richard Smith02e85f32011-04-14 22:09:26 +00006070
6071 ExprResult Inc = getDerived().TransformExpr(S->getInc());
6072 if (Inc.isInvalid())
6073 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006074 if (Inc.get())
6075 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.take());
Richard Smith02e85f32011-04-14 22:09:26 +00006076
6077 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
6078 if (LoopVar.isInvalid())
6079 return StmtError();
6080
6081 StmtResult NewStmt = S;
6082 if (getDerived().AlwaysRebuild() ||
6083 Range.get() != S->getRangeStmt() ||
6084 BeginEnd.get() != S->getBeginEndStmt() ||
6085 Cond.get() != S->getCond() ||
6086 Inc.get() != S->getInc() ||
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006087 LoopVar.get() != S->getLoopVarStmt()) {
Richard Smith02e85f32011-04-14 22:09:26 +00006088 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6089 S->getColonLoc(), Range.get(),
6090 BeginEnd.get(), Cond.get(),
6091 Inc.get(), LoopVar.get(),
6092 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006093 if (NewStmt.isInvalid())
6094 return StmtError();
6095 }
Richard Smith02e85f32011-04-14 22:09:26 +00006096
6097 StmtResult Body = getDerived().TransformStmt(S->getBody());
6098 if (Body.isInvalid())
6099 return StmtError();
6100
6101 // Body has changed but we didn't rebuild the for-range statement. Rebuild
6102 // it now so we have a new statement to attach the body to.
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006103 if (Body.get() != S->getBody() && NewStmt.get() == S) {
Richard Smith02e85f32011-04-14 22:09:26 +00006104 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6105 S->getColonLoc(), Range.get(),
6106 BeginEnd.get(), Cond.get(),
6107 Inc.get(), LoopVar.get(),
6108 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006109 if (NewStmt.isInvalid())
6110 return StmtError();
6111 }
Richard Smith02e85f32011-04-14 22:09:26 +00006112
6113 if (NewStmt.get() == S)
6114 return SemaRef.Owned(S);
6115
6116 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
6117}
6118
John Wiegley1c0675e2011-04-28 01:08:34 +00006119template<typename Derived>
6120StmtResult
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006121TreeTransform<Derived>::TransformMSDependentExistsStmt(
6122 MSDependentExistsStmt *S) {
6123 // Transform the nested-name-specifier, if any.
6124 NestedNameSpecifierLoc QualifierLoc;
6125 if (S->getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006126 QualifierLoc
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006127 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
6128 if (!QualifierLoc)
6129 return StmtError();
6130 }
6131
6132 // Transform the declaration name.
6133 DeclarationNameInfo NameInfo = S->getNameInfo();
6134 if (NameInfo.getName()) {
6135 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6136 if (!NameInfo.getName())
6137 return StmtError();
6138 }
6139
6140 // Check whether anything changed.
6141 if (!getDerived().AlwaysRebuild() &&
6142 QualifierLoc == S->getQualifierLoc() &&
6143 NameInfo.getName() == S->getNameInfo().getName())
6144 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006145
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006146 // Determine whether this name exists, if we can.
6147 CXXScopeSpec SS;
6148 SS.Adopt(QualifierLoc);
6149 bool Dependent = false;
6150 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/0, SS, NameInfo)) {
6151 case Sema::IER_Exists:
6152 if (S->isIfExists())
6153 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006154
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006155 return new (getSema().Context) NullStmt(S->getKeywordLoc());
6156
6157 case Sema::IER_DoesNotExist:
6158 if (S->isIfNotExists())
6159 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006160
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006161 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00006162
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006163 case Sema::IER_Dependent:
6164 Dependent = true;
6165 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006166
Douglas Gregor4a2a8f72011-10-25 03:44:56 +00006167 case Sema::IER_Error:
6168 return StmtError();
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006169 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006170
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006171 // We need to continue with the instantiation, so do so now.
6172 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
6173 if (SubStmt.isInvalid())
6174 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006175
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006176 // If we have resolved the name, just transform to the substatement.
6177 if (!Dependent)
6178 return SubStmt;
Chad Rosier1dcde962012-08-08 18:46:20 +00006179
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006180 // The name is still dependent, so build a dependent expression again.
6181 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
6182 S->isIfExists(),
6183 QualifierLoc,
6184 NameInfo,
6185 SubStmt.get());
6186}
6187
6188template<typename Derived>
John McCall5e77d762013-04-16 07:28:30 +00006189ExprResult
6190TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
6191 NestedNameSpecifierLoc QualifierLoc;
6192 if (E->getQualifierLoc()) {
6193 QualifierLoc
6194 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6195 if (!QualifierLoc)
6196 return ExprError();
6197 }
6198
6199 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
6200 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
6201 if (!PD)
6202 return ExprError();
6203
6204 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
6205 if (Base.isInvalid())
6206 return ExprError();
6207
6208 return new (SemaRef.getASTContext())
6209 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
6210 SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
6211 QualifierLoc, E->getMemberLoc());
6212}
6213
David Majnemerfad8f482013-10-15 09:33:02 +00006214template <typename Derived>
6215StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00006216 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006217 if (TryBlock.isInvalid())
6218 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006219
6220 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
David Majnemer7e755502013-10-15 09:30:14 +00006221 if (Handler.isInvalid())
6222 return StmtError();
6223
David Majnemerfad8f482013-10-15 09:33:02 +00006224 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
6225 Handler.get() == S->getHandler())
John Wiegley1c0675e2011-04-28 01:08:34 +00006226 return SemaRef.Owned(S);
6227
David Majnemerfad8f482013-10-15 09:33:02 +00006228 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(),
6229 TryBlock.take(), Handler.take());
John Wiegley1c0675e2011-04-28 01:08:34 +00006230}
6231
David Majnemerfad8f482013-10-15 09:33:02 +00006232template <typename Derived>
6233StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00006234 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006235 if (Block.isInvalid())
6236 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006237
David Majnemerfad8f482013-10-15 09:33:02 +00006238 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.take());
John Wiegley1c0675e2011-04-28 01:08:34 +00006239}
6240
David Majnemerfad8f482013-10-15 09:33:02 +00006241template <typename Derived>
6242StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
John Wiegley1c0675e2011-04-28 01:08:34 +00006243 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
David Majnemerfad8f482013-10-15 09:33:02 +00006244 if (FilterExpr.isInvalid())
6245 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006246
David Majnemer7e755502013-10-15 09:30:14 +00006247 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006248 if (Block.isInvalid())
6249 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006250
David Majnemerfad8f482013-10-15 09:33:02 +00006251 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.take(),
John Wiegley1c0675e2011-04-28 01:08:34 +00006252 Block.take());
6253}
6254
David Majnemerfad8f482013-10-15 09:33:02 +00006255template <typename Derived>
6256StmtResult TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
6257 if (isa<SEHFinallyStmt>(Handler))
John Wiegley1c0675e2011-04-28 01:08:34 +00006258 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
6259 else
6260 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
6261}
6262
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006263template<typename Derived>
6264StmtResult
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006265TreeTransform<Derived>::TransformOMPExecutableDirective(
6266 OMPExecutableDirective *D) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00006267
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006268 // Transform the clauses
Alexey Bataev758e55e2013-09-06 18:03:48 +00006269 llvm::SmallVector<OMPClause *, 16> TClauses;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006270 ArrayRef<OMPClause *> Clauses = D->clauses();
6271 TClauses.reserve(Clauses.size());
6272 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
6273 I != E; ++I) {
6274 if (*I) {
6275 OMPClause *Clause = getDerived().TransformOMPClause(*I);
Alexey Bataev758e55e2013-09-06 18:03:48 +00006276 if (!Clause) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006277 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00006278 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006279 TClauses.push_back(Clause);
6280 }
6281 else {
6282 TClauses.push_back(0);
6283 }
6284 }
Alexey Bataev758e55e2013-09-06 18:03:48 +00006285 if (!D->getAssociatedStmt()) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006286 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00006287 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006288 StmtResult AssociatedStmt =
6289 getDerived().TransformStmt(D->getAssociatedStmt());
Alexey Bataev758e55e2013-09-06 18:03:48 +00006290 if (AssociatedStmt.isInvalid()) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006291 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00006292 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006293
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006294 return getDerived().RebuildOMPExecutableDirective(D->getDirectiveKind(),
6295 TClauses,
6296 AssociatedStmt.take(),
6297 D->getLocStart(),
6298 D->getLocEnd());
6299}
6300
6301template<typename Derived>
6302StmtResult
6303TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
6304 DeclarationNameInfo DirName;
6305 getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, 0);
6306 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6307 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6308 return Res;
6309}
6310
6311template<typename Derived>
6312StmtResult
6313TreeTransform<Derived>::TransformOMPSimdDirective(OMPSimdDirective *D) {
6314 DeclarationNameInfo DirName;
6315 getSema().StartOpenMPDSABlock(OMPD_simd, DirName, 0);
6316 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6317 getDerived().getSema().EndOpenMPDSABlock(Res.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00006318 return Res;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006319}
6320
6321template<typename Derived>
6322OMPClause *
Alexey Bataevaadd52e2014-02-13 05:29:23 +00006323TreeTransform<Derived>::TransformOMPIfClause(OMPIfClause *C) {
Alexey Bataevaf7849e2014-03-05 06:45:14 +00006324 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
6325 if (Cond.isInvalid())
6326 return 0;
6327 return getDerived().RebuildOMPIfClause(Cond.take(), C->getLocStart(),
Alexey Bataevaadd52e2014-02-13 05:29:23 +00006328 C->getLParenLoc(), C->getLocEnd());
6329}
6330
6331template<typename Derived>
6332OMPClause *
Alexey Bataev568a8332014-03-06 06:15:19 +00006333TreeTransform<Derived>::TransformOMPNumThreadsClause(OMPNumThreadsClause *C) {
6334 ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads());
6335 if (NumThreads.isInvalid())
6336 return 0;
6337 return getDerived().RebuildOMPNumThreadsClause(NumThreads.take(),
6338 C->getLocStart(),
6339 C->getLParenLoc(),
6340 C->getLocEnd());
6341}
6342
6343template<typename Derived>
6344OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006345TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
6346 return getDerived().RebuildOMPDefaultClause(C->getDefaultKind(),
6347 C->getDefaultKindKwLoc(),
6348 C->getLocStart(),
6349 C->getLParenLoc(),
6350 C->getLocEnd());
6351}
6352
6353template<typename Derived>
6354OMPClause *
6355TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00006356 llvm::SmallVector<Expr *, 16> Vars;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006357 Vars.reserve(C->varlist_size());
Alexey Bataev756c1962013-09-24 03:17:45 +00006358 for (OMPPrivateClause::varlist_iterator I = C->varlist_begin(),
6359 E = C->varlist_end();
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006360 I != E; ++I) {
6361 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(*I));
6362 if (EVar.isInvalid())
6363 return 0;
6364 Vars.push_back(EVar.take());
6365 }
6366 return getDerived().RebuildOMPPrivateClause(Vars,
6367 C->getLocStart(),
6368 C->getLParenLoc(),
6369 C->getLocEnd());
6370}
6371
Alexey Bataev758e55e2013-09-06 18:03:48 +00006372template<typename Derived>
6373OMPClause *
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006374TreeTransform<Derived>::TransformOMPFirstprivateClause(
6375 OMPFirstprivateClause *C) {
6376 llvm::SmallVector<Expr *, 16> Vars;
6377 Vars.reserve(C->varlist_size());
6378 for (OMPFirstprivateClause::varlist_iterator I = C->varlist_begin(),
6379 E = C->varlist_end();
6380 I != E; ++I) {
6381 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(*I));
6382 if (EVar.isInvalid())
6383 return 0;
6384 Vars.push_back(EVar.take());
6385 }
6386 return getDerived().RebuildOMPFirstprivateClause(Vars,
6387 C->getLocStart(),
6388 C->getLParenLoc(),
6389 C->getLocEnd());
6390}
6391
6392template<typename Derived>
6393OMPClause *
Alexey Bataev758e55e2013-09-06 18:03:48 +00006394TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
6395 llvm::SmallVector<Expr *, 16> Vars;
6396 Vars.reserve(C->varlist_size());
Alexey Bataev756c1962013-09-24 03:17:45 +00006397 for (OMPSharedClause::varlist_iterator I = C->varlist_begin(),
6398 E = C->varlist_end();
Alexey Bataev758e55e2013-09-06 18:03:48 +00006399 I != E; ++I) {
6400 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(*I));
6401 if (EVar.isInvalid())
6402 return 0;
6403 Vars.push_back(EVar.take());
6404 }
6405 return getDerived().RebuildOMPSharedClause(Vars,
6406 C->getLocStart(),
6407 C->getLParenLoc(),
6408 C->getLocEnd());
6409}
6410
Douglas Gregorebe10102009-08-20 07:17:43 +00006411//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00006412// Expression transformation
6413//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00006414template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006415ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006416TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006417 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006418}
Mike Stump11289f42009-09-09 15:08:12 +00006419
6420template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006421ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006422TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregorea972d32011-02-28 21:54:11 +00006423 NestedNameSpecifierLoc QualifierLoc;
6424 if (E->getQualifierLoc()) {
6425 QualifierLoc
6426 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6427 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00006428 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00006429 }
John McCallce546572009-12-08 09:08:17 +00006430
6431 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006432 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6433 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006434 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00006435 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006436
John McCall815039a2010-08-17 21:27:17 +00006437 DeclarationNameInfo NameInfo = E->getNameInfo();
6438 if (NameInfo.getName()) {
6439 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6440 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00006441 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00006442 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006443
6444 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00006445 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00006446 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006447 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00006448 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00006449
6450 // Mark it referenced in the new context regardless.
6451 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00006452 SemaRef.MarkDeclRefReferenced(E);
John McCallce546572009-12-08 09:08:17 +00006453
John McCallc3007a22010-10-26 07:05:15 +00006454 return SemaRef.Owned(E);
Douglas Gregor4bd90e52009-10-23 18:54:35 +00006455 }
John McCallce546572009-12-08 09:08:17 +00006456
6457 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCallb3774b52010-08-19 23:49:38 +00006458 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00006459 TemplateArgs = &TransArgs;
6460 TransArgs.setLAngleLoc(E->getLAngleLoc());
6461 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006462 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6463 E->getNumTemplateArgs(),
6464 TransArgs))
6465 return ExprError();
John McCallce546572009-12-08 09:08:17 +00006466 }
6467
Chad Rosier1dcde962012-08-08 18:46:20 +00006468 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregorea972d32011-02-28 21:54:11 +00006469 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00006470}
Mike Stump11289f42009-09-09 15:08:12 +00006471
Douglas Gregora16548e2009-08-11 05:31:07 +00006472template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006473ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006474TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00006475 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006476}
Mike Stump11289f42009-09-09 15:08:12 +00006477
Douglas Gregora16548e2009-08-11 05:31:07 +00006478template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006479ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006480TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00006481 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006482}
Mike Stump11289f42009-09-09 15:08:12 +00006483
Douglas Gregora16548e2009-08-11 05:31:07 +00006484template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006485ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006486TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00006487 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006488}
Mike Stump11289f42009-09-09 15:08:12 +00006489
Douglas Gregora16548e2009-08-11 05:31:07 +00006490template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006491ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006492TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00006493 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006494}
Mike Stump11289f42009-09-09 15:08:12 +00006495
Douglas Gregora16548e2009-08-11 05:31:07 +00006496template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006497ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006498TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00006499 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006500}
6501
6502template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006503ExprResult
Richard Smithc67fdd42012-03-07 08:35:16 +00006504TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
Argyrios Kyrtzidis25049092013-04-09 01:17:02 +00006505 if (FunctionDecl *FD = E->getDirectCallee())
6506 SemaRef.MarkFunctionReferenced(E->getLocStart(), FD);
Richard Smithc67fdd42012-03-07 08:35:16 +00006507 return SemaRef.MaybeBindToTemporary(E);
6508}
6509
6510template<typename Derived>
6511ExprResult
Peter Collingbourne91147592011-04-15 00:35:48 +00006512TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
6513 ExprResult ControllingExpr =
6514 getDerived().TransformExpr(E->getControllingExpr());
6515 if (ControllingExpr.isInvalid())
6516 return ExprError();
6517
Chris Lattner01cf8db2011-07-20 06:58:45 +00006518 SmallVector<Expr *, 4> AssocExprs;
6519 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbourne91147592011-04-15 00:35:48 +00006520 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
6521 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
6522 if (TS) {
6523 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
6524 if (!AssocType)
6525 return ExprError();
6526 AssocTypes.push_back(AssocType);
6527 } else {
6528 AssocTypes.push_back(0);
6529 }
6530
6531 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
6532 if (AssocExpr.isInvalid())
6533 return ExprError();
6534 AssocExprs.push_back(AssocExpr.release());
6535 }
6536
6537 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
6538 E->getDefaultLoc(),
6539 E->getRParenLoc(),
6540 ControllingExpr.release(),
Dmitri Gribenko82360372013-05-10 13:06:58 +00006541 AssocTypes,
6542 AssocExprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00006543}
6544
6545template<typename Derived>
6546ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006547TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006548 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006549 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006550 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006551
Douglas Gregora16548e2009-08-11 05:31:07 +00006552 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006553 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006554
John McCallb268a282010-08-23 23:25:46 +00006555 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006556 E->getRParen());
6557}
6558
Richard Smithdb2630f2012-10-21 03:28:35 +00006559/// \brief The operand of a unary address-of operator has special rules: it's
6560/// allowed to refer to a non-static member of a class even if there's no 'this'
6561/// object available.
6562template<typename Derived>
6563ExprResult
6564TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
6565 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
6566 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true);
6567 else
6568 return getDerived().TransformExpr(E);
6569}
6570
Mike Stump11289f42009-09-09 15:08:12 +00006571template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006572ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006573TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smitheebe125f2013-05-21 23:29:46 +00006574 ExprResult SubExpr;
6575 if (E->getOpcode() == UO_AddrOf)
6576 SubExpr = TransformAddressOfOperand(E->getSubExpr());
6577 else
6578 SubExpr = TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006579 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006580 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006581
Douglas Gregora16548e2009-08-11 05:31:07 +00006582 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006583 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006584
Douglas Gregora16548e2009-08-11 05:31:07 +00006585 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
6586 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00006587 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006588}
Mike Stump11289f42009-09-09 15:08:12 +00006589
Douglas Gregora16548e2009-08-11 05:31:07 +00006590template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006591ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00006592TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
6593 // Transform the type.
6594 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
6595 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00006596 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006597
Douglas Gregor882211c2010-04-28 22:16:22 +00006598 // Transform all of the components into components similar to what the
6599 // parser uses.
Chad Rosier1dcde962012-08-08 18:46:20 +00006600 // FIXME: It would be slightly more efficient in the non-dependent case to
6601 // just map FieldDecls, rather than requiring the rebuilder to look for
6602 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00006603 // template code that we don't care.
6604 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00006605 typedef Sema::OffsetOfComponent Component;
Douglas Gregor882211c2010-04-28 22:16:22 +00006606 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner01cf8db2011-07-20 06:58:45 +00006607 SmallVector<Component, 4> Components;
Douglas Gregor882211c2010-04-28 22:16:22 +00006608 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
6609 const Node &ON = E->getComponent(I);
6610 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00006611 Comp.isBrackets = true;
Abramo Bagnara6b6f0512011-03-12 09:45:03 +00006612 Comp.LocStart = ON.getSourceRange().getBegin();
6613 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor882211c2010-04-28 22:16:22 +00006614 switch (ON.getKind()) {
6615 case Node::Array: {
6616 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00006617 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00006618 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006619 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006620
Douglas Gregor882211c2010-04-28 22:16:22 +00006621 ExprChanged = ExprChanged || Index.get() != FromIndex;
6622 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00006623 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00006624 break;
6625 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006626
Douglas Gregor882211c2010-04-28 22:16:22 +00006627 case Node::Field:
6628 case Node::Identifier:
6629 Comp.isBrackets = false;
6630 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00006631 if (!Comp.U.IdentInfo)
6632 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00006633
Douglas Gregor882211c2010-04-28 22:16:22 +00006634 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006635
Douglas Gregord1702062010-04-29 00:18:15 +00006636 case Node::Base:
6637 // Will be recomputed during the rebuild.
6638 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00006639 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006640
Douglas Gregor882211c2010-04-28 22:16:22 +00006641 Components.push_back(Comp);
6642 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006643
Douglas Gregor882211c2010-04-28 22:16:22 +00006644 // If nothing changed, retain the existing expression.
6645 if (!getDerived().AlwaysRebuild() &&
6646 Type == E->getTypeSourceInfo() &&
6647 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00006648 return SemaRef.Owned(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00006649
Douglas Gregor882211c2010-04-28 22:16:22 +00006650 // Build a new offsetof expression.
6651 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
6652 Components.data(), Components.size(),
6653 E->getRParenLoc());
6654}
6655
6656template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006657ExprResult
John McCall8d69a212010-11-15 23:31:06 +00006658TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
6659 assert(getDerived().AlreadyTransformed(E->getType()) &&
6660 "opaque value expression requires transformation");
6661 return SemaRef.Owned(E);
6662}
6663
6664template<typename Derived>
6665ExprResult
John McCallfe96e0b2011-11-06 09:01:30 +00006666TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCalle9290822011-11-30 04:42:31 +00006667 // Rebuild the syntactic form. The original syntactic form has
6668 // opaque-value expressions in it, so strip those away and rebuild
6669 // the result. This is a really awful way of doing this, but the
6670 // better solution (rebuilding the semantic expressions and
6671 // rebinding OVEs as necessary) doesn't work; we'd need
6672 // TreeTransform to not strip away implicit conversions.
6673 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
6674 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCallfe96e0b2011-11-06 09:01:30 +00006675 if (result.isInvalid()) return ExprError();
6676
6677 // If that gives us a pseudo-object result back, the pseudo-object
6678 // expression must have been an lvalue-to-rvalue conversion which we
6679 // should reapply.
6680 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
6681 result = SemaRef.checkPseudoObjectRValue(result.take());
6682
6683 return result;
6684}
6685
6686template<typename Derived>
6687ExprResult
Peter Collingbournee190dee2011-03-11 19:24:49 +00006688TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
6689 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006690 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00006691 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00006692
John McCallbcd03502009-12-07 02:54:59 +00006693 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00006694 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00006695 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006696
John McCall4c98fd82009-11-04 07:28:41 +00006697 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCallc3007a22010-10-26 07:05:15 +00006698 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006699
Peter Collingbournee190dee2011-03-11 19:24:49 +00006700 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
6701 E->getKind(),
6702 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00006703 }
Mike Stump11289f42009-09-09 15:08:12 +00006704
Eli Friedmane4f22df2012-02-29 04:03:55 +00006705 // C++0x [expr.sizeof]p1:
6706 // The operand is either an expression, which is an unevaluated operand
6707 // [...]
Eli Friedman15681d62012-09-26 04:34:21 +00006708 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
6709 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00006710
Eli Friedmane4f22df2012-02-29 04:03:55 +00006711 ExprResult SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
6712 if (SubExpr.isInvalid())
6713 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006714
Eli Friedmane4f22df2012-02-29 04:03:55 +00006715 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
6716 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006717
Peter Collingbournee190dee2011-03-11 19:24:49 +00006718 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
6719 E->getOperatorLoc(),
6720 E->getKind(),
6721 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00006722}
Mike Stump11289f42009-09-09 15:08:12 +00006723
Douglas Gregora16548e2009-08-11 05:31:07 +00006724template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006725ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006726TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006727 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006728 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006729 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006730
John McCalldadc5752010-08-24 06:29:42 +00006731 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006732 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006733 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006734
6735
Douglas Gregora16548e2009-08-11 05:31:07 +00006736 if (!getDerived().AlwaysRebuild() &&
6737 LHS.get() == E->getLHS() &&
6738 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00006739 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006740
John McCallb268a282010-08-23 23:25:46 +00006741 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006742 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00006743 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006744 E->getRBracketLoc());
6745}
Mike Stump11289f42009-09-09 15:08:12 +00006746
6747template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006748ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006749TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006750 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00006751 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00006752 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006753 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006754
6755 // Transform arguments.
6756 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006757 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00006758 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00006759 &ArgChanged))
6760 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006761
Douglas Gregora16548e2009-08-11 05:31:07 +00006762 if (!getDerived().AlwaysRebuild() &&
6763 Callee.get() == E->getCallee() &&
6764 !ArgChanged)
Dmitri Gribenko76bb5cabfa2012-09-10 21:20:09 +00006765 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00006766
Douglas Gregora16548e2009-08-11 05:31:07 +00006767 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00006768 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00006769 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00006770 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006771 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00006772 E->getRParenLoc());
6773}
Mike Stump11289f42009-09-09 15:08:12 +00006774
6775template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006776ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006777TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006778 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00006779 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006780 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006781
Douglas Gregorea972d32011-02-28 21:54:11 +00006782 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorf405d7e2009-08-31 23:41:50 +00006783 if (E->hasQualifier()) {
Douglas Gregorea972d32011-02-28 21:54:11 +00006784 QualifierLoc
6785 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00006786
Douglas Gregorea972d32011-02-28 21:54:11 +00006787 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00006788 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00006789 }
Abramo Bagnara7945c982012-01-27 09:46:47 +00006790 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00006791
Eli Friedman2cfcef62009-12-04 06:40:45 +00006792 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006793 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
6794 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006795 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00006796 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006797
John McCall16df1e52010-03-30 21:47:33 +00006798 NamedDecl *FoundDecl = E->getFoundDecl();
6799 if (FoundDecl == E->getMemberDecl()) {
6800 FoundDecl = Member;
6801 } else {
6802 FoundDecl = cast_or_null<NamedDecl>(
6803 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
6804 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00006805 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00006806 }
6807
Douglas Gregora16548e2009-08-11 05:31:07 +00006808 if (!getDerived().AlwaysRebuild() &&
6809 Base.get() == E->getBase() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00006810 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00006811 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00006812 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00006813 !E->hasExplicitTemplateArgs()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006814
Anders Carlsson9c45ad72009-12-22 05:24:09 +00006815 // Mark it referenced in the new context regardless.
6816 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00006817 SemaRef.MarkMemberReferenced(E);
6818
John McCallc3007a22010-10-26 07:05:15 +00006819 return SemaRef.Owned(E);
Anders Carlsson9c45ad72009-12-22 05:24:09 +00006820 }
Douglas Gregora16548e2009-08-11 05:31:07 +00006821
John McCall6b51f282009-11-23 01:53:49 +00006822 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00006823 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00006824 TransArgs.setLAngleLoc(E->getLAngleLoc());
6825 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006826 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6827 E->getNumTemplateArgs(),
6828 TransArgs))
6829 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00006830 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006831
Douglas Gregora16548e2009-08-11 05:31:07 +00006832 // FIXME: Bogus source location for the operator
6833 SourceLocation FakeOperatorLoc
6834 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
6835
John McCall38836f02010-01-15 08:34:02 +00006836 // FIXME: to do this check properly, we will need to preserve the
6837 // first-qualifier-in-scope here, just in case we had a dependent
6838 // base (and therefore couldn't do the check) and a
6839 // nested-name-qualifier (and therefore could do the lookup).
6840 NamedDecl *FirstQualifierInScope = 0;
6841
John McCallb268a282010-08-23 23:25:46 +00006842 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00006843 E->isArrow(),
Douglas Gregorea972d32011-02-28 21:54:11 +00006844 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00006845 TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006846 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00006847 Member,
John McCall16df1e52010-03-30 21:47:33 +00006848 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00006849 (E->hasExplicitTemplateArgs()
John McCall6b51f282009-11-23 01:53:49 +00006850 ? &TransArgs : 0),
John McCall38836f02010-01-15 08:34:02 +00006851 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00006852}
Mike Stump11289f42009-09-09 15:08:12 +00006853
Douglas Gregora16548e2009-08-11 05:31:07 +00006854template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006855ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006856TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00006857 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006858 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006859 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006860
John McCalldadc5752010-08-24 06:29:42 +00006861 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006862 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006863 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006864
Douglas Gregora16548e2009-08-11 05:31:07 +00006865 if (!getDerived().AlwaysRebuild() &&
6866 LHS.get() == E->getLHS() &&
6867 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00006868 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006869
Lang Hames5de91cc2012-10-02 04:45:10 +00006870 Sema::FPContractStateRAII FPContractState(getSema());
6871 getSema().FPFeatures.fp_contract = E->isFPContractable();
6872
Douglas Gregora16548e2009-08-11 05:31:07 +00006873 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00006874 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006875}
6876
Mike Stump11289f42009-09-09 15:08:12 +00006877template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006878ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006879TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00006880 CompoundAssignOperator *E) {
6881 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006882}
Mike Stump11289f42009-09-09 15:08:12 +00006883
Douglas Gregora16548e2009-08-11 05:31:07 +00006884template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00006885ExprResult TreeTransform<Derived>::
6886TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
6887 // Just rebuild the common and RHS expressions and see whether we
6888 // get any changes.
6889
6890 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
6891 if (commonExpr.isInvalid())
6892 return ExprError();
6893
6894 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
6895 if (rhs.isInvalid())
6896 return ExprError();
6897
6898 if (!getDerived().AlwaysRebuild() &&
6899 commonExpr.get() == e->getCommon() &&
6900 rhs.get() == e->getFalseExpr())
6901 return SemaRef.Owned(e);
6902
6903 return getDerived().RebuildConditionalOperator(commonExpr.take(),
6904 e->getQuestionLoc(),
6905 0,
6906 e->getColonLoc(),
6907 rhs.get());
6908}
6909
6910template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006911ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006912TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00006913 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00006914 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006915 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006916
John McCalldadc5752010-08-24 06:29:42 +00006917 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006918 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006919 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006920
John McCalldadc5752010-08-24 06:29:42 +00006921 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006922 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006923 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006924
Douglas Gregora16548e2009-08-11 05:31:07 +00006925 if (!getDerived().AlwaysRebuild() &&
6926 Cond.get() == E->getCond() &&
6927 LHS.get() == E->getLHS() &&
6928 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00006929 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006930
John McCallb268a282010-08-23 23:25:46 +00006931 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00006932 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00006933 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00006934 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00006935 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006936}
Mike Stump11289f42009-09-09 15:08:12 +00006937
6938template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006939ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006940TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00006941 // Implicit casts are eliminated during transformation, since they
6942 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00006943 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006944}
Mike Stump11289f42009-09-09 15:08:12 +00006945
Douglas Gregora16548e2009-08-11 05:31:07 +00006946template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006947ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006948TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006949 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6950 if (!Type)
6951 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006952
John McCalldadc5752010-08-24 06:29:42 +00006953 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00006954 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006955 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006956 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006957
Douglas Gregora16548e2009-08-11 05:31:07 +00006958 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006959 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006960 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006961 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006962
John McCall97513962010-01-15 18:39:57 +00006963 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006964 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00006965 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006966 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006967}
Mike Stump11289f42009-09-09 15:08:12 +00006968
Douglas Gregora16548e2009-08-11 05:31:07 +00006969template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006970ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006971TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00006972 TypeSourceInfo *OldT = E->getTypeSourceInfo();
6973 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
6974 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00006975 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006976
John McCalldadc5752010-08-24 06:29:42 +00006977 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00006978 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006979 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006980
Douglas Gregora16548e2009-08-11 05:31:07 +00006981 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00006982 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006983 Init.get() == E->getInitializer())
Douglas Gregorc7f46f22011-12-10 00:23:21 +00006984 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006985
John McCall5d7aa7f2010-01-19 22:33:45 +00006986 // Note: the expression type doesn't necessarily match the
6987 // type-as-written, but that's okay, because it should always be
6988 // derivable from the initializer.
6989
John McCalle15bbff2010-01-18 19:35:47 +00006990 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00006991 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00006992 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006993}
Mike Stump11289f42009-09-09 15:08:12 +00006994
Douglas Gregora16548e2009-08-11 05:31:07 +00006995template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006996ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006997TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006998 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00006999 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007000 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007001
Douglas Gregora16548e2009-08-11 05:31:07 +00007002 if (!getDerived().AlwaysRebuild() &&
7003 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007004 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007005
Douglas Gregora16548e2009-08-11 05:31:07 +00007006 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00007007 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00007008 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00007009 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00007010 E->getAccessorLoc(),
7011 E->getAccessor());
7012}
Mike Stump11289f42009-09-09 15:08:12 +00007013
Douglas Gregora16548e2009-08-11 05:31:07 +00007014template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007015ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007016TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007017 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00007018
Benjamin Kramerf0623432012-08-23 22:51:59 +00007019 SmallVector<Expr*, 4> Inits;
Chad Rosier1dcde962012-08-08 18:46:20 +00007020 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00007021 Inits, &InitChanged))
7022 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007023
Douglas Gregora16548e2009-08-11 05:31:07 +00007024 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCallc3007a22010-10-26 07:05:15 +00007025 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007026
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007027 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00007028 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00007029}
Mike Stump11289f42009-09-09 15:08:12 +00007030
Douglas Gregora16548e2009-08-11 05:31:07 +00007031template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007032ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007033TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007034 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00007035
Douglas Gregorebe10102009-08-20 07:17:43 +00007036 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00007037 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00007038 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007039 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007040
Douglas Gregorebe10102009-08-20 07:17:43 +00007041 // transform the designators.
Benjamin Kramerf0623432012-08-23 22:51:59 +00007042 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregora16548e2009-08-11 05:31:07 +00007043 bool ExprChanged = false;
7044 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
7045 DEnd = E->designators_end();
7046 D != DEnd; ++D) {
7047 if (D->isFieldDesignator()) {
7048 Desig.AddDesignator(Designator::getField(D->getFieldName(),
7049 D->getDotLoc(),
7050 D->getFieldLoc()));
7051 continue;
7052 }
Mike Stump11289f42009-09-09 15:08:12 +00007053
Douglas Gregora16548e2009-08-11 05:31:07 +00007054 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00007055 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00007056 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007057 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007058
7059 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007060 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00007061
Douglas Gregora16548e2009-08-11 05:31:07 +00007062 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
7063 ArrayExprs.push_back(Index.release());
7064 continue;
7065 }
Mike Stump11289f42009-09-09 15:08:12 +00007066
Douglas Gregora16548e2009-08-11 05:31:07 +00007067 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00007068 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00007069 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
7070 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007071 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007072
John McCalldadc5752010-08-24 06:29:42 +00007073 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00007074 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007075 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007076
7077 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007078 End.get(),
7079 D->getLBracketLoc(),
7080 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00007081
Douglas Gregora16548e2009-08-11 05:31:07 +00007082 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
7083 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00007084
Douglas Gregora16548e2009-08-11 05:31:07 +00007085 ArrayExprs.push_back(Start.release());
7086 ArrayExprs.push_back(End.release());
7087 }
Mike Stump11289f42009-09-09 15:08:12 +00007088
Douglas Gregora16548e2009-08-11 05:31:07 +00007089 if (!getDerived().AlwaysRebuild() &&
7090 Init.get() == E->getInit() &&
7091 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00007092 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007093
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007094 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00007095 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00007096 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007097}
Mike Stump11289f42009-09-09 15:08:12 +00007098
Douglas Gregora16548e2009-08-11 05:31:07 +00007099template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007100ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007101TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007102 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00007103 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier1dcde962012-08-08 18:46:20 +00007104
Douglas Gregor3da3c062009-10-28 00:29:27 +00007105 // FIXME: Will we ever have proper type location here? Will we actually
7106 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00007107 QualType T = getDerived().TransformType(E->getType());
7108 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00007109 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007110
Douglas Gregora16548e2009-08-11 05:31:07 +00007111 if (!getDerived().AlwaysRebuild() &&
7112 T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00007113 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007114
Douglas Gregora16548e2009-08-11 05:31:07 +00007115 return getDerived().RebuildImplicitValueInitExpr(T);
7116}
Mike Stump11289f42009-09-09 15:08:12 +00007117
Douglas Gregora16548e2009-08-11 05:31:07 +00007118template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007119ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007120TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00007121 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
7122 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007123 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007124
John McCalldadc5752010-08-24 06:29:42 +00007125 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007126 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007127 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007128
Douglas Gregora16548e2009-08-11 05:31:07 +00007129 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00007130 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007131 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00007132 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007133
John McCallb268a282010-08-23 23:25:46 +00007134 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00007135 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007136}
7137
7138template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007139ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007140TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007141 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007142 SmallVector<Expr*, 4> Inits;
Douglas Gregora3efea12011-01-03 19:04:46 +00007143 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
7144 &ArgumentChanged))
7145 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007146
Douglas Gregora16548e2009-08-11 05:31:07 +00007147 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007148 Inits,
Douglas Gregora16548e2009-08-11 05:31:07 +00007149 E->getRParenLoc());
7150}
Mike Stump11289f42009-09-09 15:08:12 +00007151
Douglas Gregora16548e2009-08-11 05:31:07 +00007152/// \brief Transform an address-of-label expression.
7153///
7154/// By default, the transformation of an address-of-label expression always
7155/// rebuilds the expression, so that the label identifier can be resolved to
7156/// the corresponding label statement by semantic analysis.
7157template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007158ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007159TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +00007160 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
7161 E->getLabel());
7162 if (!LD)
7163 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007164
Douglas Gregora16548e2009-08-11 05:31:07 +00007165 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00007166 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +00007167}
Mike Stump11289f42009-09-09 15:08:12 +00007168
7169template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00007170ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007171TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalled7b2782012-04-06 18:20:53 +00007172 SemaRef.ActOnStartStmtExpr();
John McCalldadc5752010-08-24 06:29:42 +00007173 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00007174 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCalled7b2782012-04-06 18:20:53 +00007175 if (SubStmt.isInvalid()) {
7176 SemaRef.ActOnStmtExprError();
John McCallfaf5fb42010-08-26 23:41:50 +00007177 return ExprError();
John McCalled7b2782012-04-06 18:20:53 +00007178 }
Mike Stump11289f42009-09-09 15:08:12 +00007179
Douglas Gregora16548e2009-08-11 05:31:07 +00007180 if (!getDerived().AlwaysRebuild() &&
John McCalled7b2782012-04-06 18:20:53 +00007181 SubStmt.get() == E->getSubStmt()) {
7182 // Calling this an 'error' is unintuitive, but it does the right thing.
7183 SemaRef.ActOnStmtExprError();
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007184 return SemaRef.MaybeBindToTemporary(E);
John McCalled7b2782012-04-06 18:20:53 +00007185 }
Mike Stump11289f42009-09-09 15:08:12 +00007186
7187 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007188 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007189 E->getRParenLoc());
7190}
Mike Stump11289f42009-09-09 15:08:12 +00007191
Douglas Gregora16548e2009-08-11 05:31:07 +00007192template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007193ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007194TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007195 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00007196 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007197 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007198
John McCalldadc5752010-08-24 06:29:42 +00007199 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007200 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007201 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007202
John McCalldadc5752010-08-24 06:29:42 +00007203 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007204 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007205 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007206
Douglas Gregora16548e2009-08-11 05:31:07 +00007207 if (!getDerived().AlwaysRebuild() &&
7208 Cond.get() == E->getCond() &&
7209 LHS.get() == E->getLHS() &&
7210 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00007211 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007212
Douglas Gregora16548e2009-08-11 05:31:07 +00007213 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00007214 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007215 E->getRParenLoc());
7216}
Mike Stump11289f42009-09-09 15:08:12 +00007217
Douglas Gregora16548e2009-08-11 05:31:07 +00007218template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007219ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007220TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007221 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007222}
7223
7224template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007225ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007226TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007227 switch (E->getOperator()) {
7228 case OO_New:
7229 case OO_Delete:
7230 case OO_Array_New:
7231 case OO_Array_Delete:
7232 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier1dcde962012-08-08 18:46:20 +00007233
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007234 case OO_Call: {
7235 // This is a call to an object's operator().
7236 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
7237
7238 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00007239 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007240 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007241 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007242
7243 // FIXME: Poor location information
7244 SourceLocation FakeLParenLoc
7245 = SemaRef.PP.getLocForEndOfToken(
7246 static_cast<Expr *>(Object.get())->getLocEnd());
7247
7248 // Transform the call arguments.
Benjamin Kramerf0623432012-08-23 22:51:59 +00007249 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00007250 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregora3efea12011-01-03 19:04:46 +00007251 Args))
7252 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007253
John McCallb268a282010-08-23 23:25:46 +00007254 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007255 Args,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007256 E->getLocEnd());
7257 }
7258
7259#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
7260 case OO_##Name:
7261#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
7262#include "clang/Basic/OperatorKinds.def"
7263 case OO_Subscript:
7264 // Handled below.
7265 break;
7266
7267 case OO_Conditional:
7268 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007269
7270 case OO_None:
7271 case NUM_OVERLOADED_OPERATORS:
7272 llvm_unreachable("not an overloaded operator?");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007273 }
7274
John McCalldadc5752010-08-24 06:29:42 +00007275 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00007276 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007277 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007278
Richard Smithdb2630f2012-10-21 03:28:35 +00007279 ExprResult First;
7280 if (E->getOperator() == OO_Amp)
7281 First = getDerived().TransformAddressOfOperand(E->getArg(0));
7282 else
7283 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00007284 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007285 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007286
John McCalldadc5752010-08-24 06:29:42 +00007287 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00007288 if (E->getNumArgs() == 2) {
7289 Second = getDerived().TransformExpr(E->getArg(1));
7290 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007291 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007292 }
Mike Stump11289f42009-09-09 15:08:12 +00007293
Douglas Gregora16548e2009-08-11 05:31:07 +00007294 if (!getDerived().AlwaysRebuild() &&
7295 Callee.get() == E->getCallee() &&
7296 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00007297 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007298 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00007299
Lang Hames5de91cc2012-10-02 04:45:10 +00007300 Sema::FPContractStateRAII FPContractState(getSema());
7301 getSema().FPFeatures.fp_contract = E->isFPContractable();
7302
Douglas Gregora16548e2009-08-11 05:31:07 +00007303 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
7304 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00007305 Callee.get(),
7306 First.get(),
7307 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007308}
Mike Stump11289f42009-09-09 15:08:12 +00007309
Douglas Gregora16548e2009-08-11 05:31:07 +00007310template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007311ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007312TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
7313 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007314}
Mike Stump11289f42009-09-09 15:08:12 +00007315
Douglas Gregora16548e2009-08-11 05:31:07 +00007316template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007317ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +00007318TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
7319 // Transform the callee.
7320 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
7321 if (Callee.isInvalid())
7322 return ExprError();
7323
7324 // Transform exec config.
7325 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
7326 if (EC.isInvalid())
7327 return ExprError();
7328
7329 // Transform arguments.
7330 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007331 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00007332 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00007333 &ArgChanged))
7334 return ExprError();
7335
7336 if (!getDerived().AlwaysRebuild() &&
7337 Callee.get() == E->getCallee() &&
7338 !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007339 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbourne41f85462011-02-09 21:07:24 +00007340
7341 // FIXME: Wrong source location information for the '('.
7342 SourceLocation FakeLParenLoc
7343 = ((Expr *)Callee.get())->getSourceRange().getBegin();
7344 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007345 Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00007346 E->getRParenLoc(), EC.get());
7347}
7348
7349template<typename Derived>
7350ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007351TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007352 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7353 if (!Type)
7354 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007355
John McCalldadc5752010-08-24 06:29:42 +00007356 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00007357 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007358 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007359 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007360
Douglas Gregora16548e2009-08-11 05:31:07 +00007361 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007362 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007363 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00007364 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007365 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00007366 E->getStmtClass(),
Fariborz Jahanianf0738712013-02-22 22:02:53 +00007367 E->getAngleBrackets().getBegin(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007368 Type,
Fariborz Jahanianf0738712013-02-22 22:02:53 +00007369 E->getAngleBrackets().getEnd(),
7370 // FIXME. this should be '(' location
7371 E->getAngleBrackets().getEnd(),
John McCallb268a282010-08-23 23:25:46 +00007372 SubExpr.get(),
Abramo Bagnara9fb43862012-10-15 21:08:58 +00007373 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007374}
Mike Stump11289f42009-09-09 15:08:12 +00007375
Douglas Gregora16548e2009-08-11 05:31:07 +00007376template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007377ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007378TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
7379 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007380}
Mike Stump11289f42009-09-09 15:08:12 +00007381
7382template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007383ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007384TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
7385 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00007386}
7387
Douglas Gregora16548e2009-08-11 05:31:07 +00007388template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007389ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007390TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007391 CXXReinterpretCastExpr *E) {
7392 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007393}
Mike Stump11289f42009-09-09 15:08:12 +00007394
Douglas Gregora16548e2009-08-11 05:31:07 +00007395template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007396ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007397TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
7398 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007399}
Mike Stump11289f42009-09-09 15:08:12 +00007400
Douglas Gregora16548e2009-08-11 05:31:07 +00007401template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007402ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007403TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007404 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007405 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7406 if (!Type)
7407 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007408
John McCalldadc5752010-08-24 06:29:42 +00007409 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00007410 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007411 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007412 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007413
Douglas Gregora16548e2009-08-11 05:31:07 +00007414 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007415 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007416 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00007417 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007418
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007419 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Eli Friedman89fe0d52013-08-15 22:02:56 +00007420 E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007421 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007422 E->getRParenLoc());
7423}
Mike Stump11289f42009-09-09 15:08:12 +00007424
Douglas Gregora16548e2009-08-11 05:31:07 +00007425template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007426ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007427TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007428 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00007429 TypeSourceInfo *TInfo
7430 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7431 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007432 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007433
Douglas Gregora16548e2009-08-11 05:31:07 +00007434 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00007435 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00007436 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007437
Douglas Gregor9da64192010-04-26 22:37:10 +00007438 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7439 E->getLocStart(),
7440 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00007441 E->getLocEnd());
7442 }
Mike Stump11289f42009-09-09 15:08:12 +00007443
Eli Friedman456f0182012-01-20 01:26:23 +00007444 // We don't know whether the subexpression is potentially evaluated until
7445 // after we perform semantic analysis. We speculatively assume it is
7446 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregora16548e2009-08-11 05:31:07 +00007447 // potentially evaluated.
Eli Friedman15681d62012-09-26 04:34:21 +00007448 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
7449 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00007450
John McCalldadc5752010-08-24 06:29:42 +00007451 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00007452 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007453 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007454
Douglas Gregora16548e2009-08-11 05:31:07 +00007455 if (!getDerived().AlwaysRebuild() &&
7456 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00007457 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007458
Douglas Gregor9da64192010-04-26 22:37:10 +00007459 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7460 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00007461 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007462 E->getLocEnd());
7463}
7464
7465template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007466ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00007467TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
7468 if (E->isTypeOperand()) {
7469 TypeSourceInfo *TInfo
7470 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7471 if (!TInfo)
7472 return ExprError();
7473
7474 if (!getDerived().AlwaysRebuild() &&
7475 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00007476 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00007477
Douglas Gregor69735112011-03-06 17:40:41 +00007478 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet9f4f2072010-09-08 12:20:18 +00007479 E->getLocStart(),
7480 TInfo,
7481 E->getLocEnd());
7482 }
7483
Francois Pichet9f4f2072010-09-08 12:20:18 +00007484 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7485
7486 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
7487 if (SubExpr.isInvalid())
7488 return ExprError();
7489
7490 if (!getDerived().AlwaysRebuild() &&
7491 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00007492 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00007493
7494 return getDerived().RebuildCXXUuidofExpr(E->getType(),
7495 E->getLocStart(),
7496 SubExpr.get(),
7497 E->getLocEnd());
7498}
7499
7500template<typename Derived>
7501ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007502TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007503 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007504}
Mike Stump11289f42009-09-09 15:08:12 +00007505
Douglas Gregora16548e2009-08-11 05:31:07 +00007506template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007507ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007508TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007509 CXXNullPtrLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007510 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007511}
Mike Stump11289f42009-09-09 15:08:12 +00007512
Douglas Gregora16548e2009-08-11 05:31:07 +00007513template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007514ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007515TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Richard Smithc3d2ebb2013-06-07 02:33:37 +00007516 QualType T = getSema().getCurrentThisType();
Mike Stump11289f42009-09-09 15:08:12 +00007517
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00007518 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
7519 // Make sure that we capture 'this'.
7520 getSema().CheckCXXThisCapture(E->getLocStart());
John McCallc3007a22010-10-26 07:05:15 +00007521 return SemaRef.Owned(E);
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00007522 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007523
Douglas Gregorb15af892010-01-07 23:12:05 +00007524 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00007525}
Mike Stump11289f42009-09-09 15:08:12 +00007526
Douglas Gregora16548e2009-08-11 05:31:07 +00007527template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007528ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007529TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007530 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007531 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007532 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007533
Douglas Gregora16548e2009-08-11 05:31:07 +00007534 if (!getDerived().AlwaysRebuild() &&
7535 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00007536 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007537
Douglas Gregor53e191ed2011-07-06 22:04:06 +00007538 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
7539 E->isThrownVariableInScope());
Douglas Gregora16548e2009-08-11 05:31:07 +00007540}
Mike Stump11289f42009-09-09 15:08:12 +00007541
Douglas Gregora16548e2009-08-11 05:31:07 +00007542template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007543ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007544TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00007545 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007546 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
7547 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007548 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00007549 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007550
Chandler Carruth794da4c2010-02-08 06:42:49 +00007551 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007552 Param == E->getParam())
John McCallc3007a22010-10-26 07:05:15 +00007553 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007554
Douglas Gregor033f6752009-12-23 23:03:06 +00007555 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00007556}
Mike Stump11289f42009-09-09 15:08:12 +00007557
Douglas Gregora16548e2009-08-11 05:31:07 +00007558template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007559ExprResult
Richard Smith852c9db2013-04-20 22:23:05 +00007560TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
7561 FieldDecl *Field
7562 = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(),
7563 E->getField()));
7564 if (!Field)
7565 return ExprError();
7566
7567 if (!getDerived().AlwaysRebuild() && Field == E->getField())
7568 return SemaRef.Owned(E);
7569
7570 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
7571}
7572
7573template<typename Derived>
7574ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00007575TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
7576 CXXScalarValueInitExpr *E) {
7577 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7578 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007579 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007580
Douglas Gregora16548e2009-08-11 05:31:07 +00007581 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00007582 T == E->getTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00007583 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007584
Chad Rosier1dcde962012-08-08 18:46:20 +00007585 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregor2b88c112010-09-08 00:15:04 +00007586 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00007587 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007588}
Mike Stump11289f42009-09-09 15:08:12 +00007589
Douglas Gregora16548e2009-08-11 05:31:07 +00007590template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007591ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007592TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007593 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00007594 TypeSourceInfo *AllocTypeInfo
7595 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
7596 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007597 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007598
Douglas Gregora16548e2009-08-11 05:31:07 +00007599 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00007600 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00007601 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007602 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007603
Douglas Gregora16548e2009-08-11 05:31:07 +00007604 // Transform the placement arguments (if any).
7605 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007606 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier1dcde962012-08-08 18:46:20 +00007607 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregora3efea12011-01-03 19:04:46 +00007608 E->getNumPlacementArgs(), true,
7609 PlacementArgs, &ArgumentChanged))
Sebastian Redl6047f072012-02-16 12:22:20 +00007610 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007611
Sebastian Redl6047f072012-02-16 12:22:20 +00007612 // Transform the initializer (if any).
7613 Expr *OldInit = E->getInitializer();
7614 ExprResult NewInit;
7615 if (OldInit)
7616 NewInit = getDerived().TransformExpr(OldInit);
7617 if (NewInit.isInvalid())
7618 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007619
Sebastian Redl6047f072012-02-16 12:22:20 +00007620 // Transform new operator and delete operator.
Douglas Gregord2d9da02010-02-26 00:38:10 +00007621 FunctionDecl *OperatorNew = 0;
7622 if (E->getOperatorNew()) {
7623 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007624 getDerived().TransformDecl(E->getLocStart(),
7625 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00007626 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00007627 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00007628 }
7629
7630 FunctionDecl *OperatorDelete = 0;
7631 if (E->getOperatorDelete()) {
7632 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007633 getDerived().TransformDecl(E->getLocStart(),
7634 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00007635 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00007636 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00007637 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007638
Douglas Gregora16548e2009-08-11 05:31:07 +00007639 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00007640 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007641 ArraySize.get() == E->getArraySize() &&
Sebastian Redl6047f072012-02-16 12:22:20 +00007642 NewInit.get() == OldInit &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00007643 OperatorNew == E->getOperatorNew() &&
7644 OperatorDelete == E->getOperatorDelete() &&
7645 !ArgumentChanged) {
7646 // Mark any declarations we need as referenced.
7647 // FIXME: instantiation-specific.
Douglas Gregord2d9da02010-02-26 00:38:10 +00007648 if (OperatorNew)
Eli Friedmanfa0df832012-02-02 03:46:19 +00007649 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregord2d9da02010-02-26 00:38:10 +00007650 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00007651 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00007652
Sebastian Redl6047f072012-02-16 12:22:20 +00007653 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor72912fb2011-07-26 15:11:03 +00007654 QualType ElementType
7655 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
7656 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
7657 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
7658 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedmanfa0df832012-02-02 03:46:19 +00007659 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor72912fb2011-07-26 15:11:03 +00007660 }
7661 }
7662 }
Sebastian Redl6047f072012-02-16 12:22:20 +00007663
John McCallc3007a22010-10-26 07:05:15 +00007664 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00007665 }
Mike Stump11289f42009-09-09 15:08:12 +00007666
Douglas Gregor0744ef62010-09-07 21:49:58 +00007667 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00007668 if (!ArraySize.get()) {
7669 // If no array size was specified, but the new expression was
7670 // instantiated with an array type (e.g., "new T" where T is
7671 // instantiated with "int[4]"), extract the outer bound from the
7672 // array type as our array size. We do this with constant and
7673 // dependently-sized array types.
7674 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
7675 if (!ArrayT) {
7676 // Do nothing
7677 } else if (const ConstantArrayType *ConsArrayT
7678 = dyn_cast<ConstantArrayType>(ArrayT)) {
Chad Rosier1dcde962012-08-08 18:46:20 +00007679 ArraySize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00007680 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
Chad Rosier1dcde962012-08-08 18:46:20 +00007681 ConsArrayT->getSize(),
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00007682 SemaRef.Context.getSizeType(),
7683 /*FIXME:*/E->getLocStart()));
Douglas Gregor2e9c7952009-12-22 17:13:37 +00007684 AllocType = ConsArrayT->getElementType();
7685 } else if (const DependentSizedArrayType *DepArrayT
7686 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
7687 if (DepArrayT->getSizeExpr()) {
John McCallc3007a22010-10-26 07:05:15 +00007688 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00007689 AllocType = DepArrayT->getElementType();
7690 }
7691 }
7692 }
Sebastian Redl6047f072012-02-16 12:22:20 +00007693
Douglas Gregora16548e2009-08-11 05:31:07 +00007694 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
7695 E->isGlobalNew(),
7696 /*FIXME:*/E->getLocStart(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007697 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00007698 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00007699 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007700 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00007701 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00007702 ArraySize.get(),
Sebastian Redl6047f072012-02-16 12:22:20 +00007703 E->getDirectInitRange(),
7704 NewInit.take());
Douglas Gregora16548e2009-08-11 05:31:07 +00007705}
Mike Stump11289f42009-09-09 15:08:12 +00007706
Douglas Gregora16548e2009-08-11 05:31:07 +00007707template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007708ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007709TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007710 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00007711 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007712 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007713
Douglas Gregord2d9da02010-02-26 00:38:10 +00007714 // Transform the delete operator, if known.
7715 FunctionDecl *OperatorDelete = 0;
7716 if (E->getOperatorDelete()) {
7717 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007718 getDerived().TransformDecl(E->getLocStart(),
7719 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00007720 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00007721 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00007722 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007723
Douglas Gregora16548e2009-08-11 05:31:07 +00007724 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00007725 Operand.get() == E->getArgument() &&
7726 OperatorDelete == E->getOperatorDelete()) {
7727 // Mark any declarations we need as referenced.
7728 // FIXME: instantiation-specific.
7729 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00007730 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00007731
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00007732 if (!E->getArgument()->isTypeDependent()) {
7733 QualType Destroyed = SemaRef.Context.getBaseElementType(
7734 E->getDestroyedType());
7735 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
7736 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +00007737 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedmanfa0df832012-02-02 03:46:19 +00007738 SemaRef.LookupDestructor(Record));
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00007739 }
7740 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007741
John McCallc3007a22010-10-26 07:05:15 +00007742 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00007743 }
Mike Stump11289f42009-09-09 15:08:12 +00007744
Douglas Gregora16548e2009-08-11 05:31:07 +00007745 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
7746 E->isGlobalDelete(),
7747 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00007748 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007749}
Mike Stump11289f42009-09-09 15:08:12 +00007750
Douglas Gregora16548e2009-08-11 05:31:07 +00007751template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007752ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00007753TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007754 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007755 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00007756 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007757 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007758
John McCallba7bf592010-08-24 05:47:05 +00007759 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00007760 bool MayBePseudoDestructor = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00007761 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00007762 E->getOperatorLoc(),
7763 E->isArrow()? tok::arrow : tok::period,
7764 ObjectTypePtr,
7765 MayBePseudoDestructor);
7766 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007767 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007768
John McCallba7bf592010-08-24 05:47:05 +00007769 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +00007770 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
7771 if (QualifierLoc) {
7772 QualifierLoc
7773 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
7774 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +00007775 return ExprError();
7776 }
Douglas Gregora6ce6082011-02-25 18:19:59 +00007777 CXXScopeSpec SS;
7778 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00007779
Douglas Gregor678f90d2010-02-25 01:56:36 +00007780 PseudoDestructorTypeStorage Destroyed;
7781 if (E->getDestroyedTypeInfo()) {
7782 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00007783 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregor579c15f2011-03-02 18:32:08 +00007784 ObjectType, 0, SS);
Douglas Gregor678f90d2010-02-25 01:56:36 +00007785 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007786 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00007787 Destroyed = DestroyedTypeInfo;
Douglas Gregorf39a8dd2011-11-09 02:19:47 +00007788 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregor678f90d2010-02-25 01:56:36 +00007789 // We aren't likely to be able to resolve the identifier down to a type
7790 // now anyway, so just retain the identifier.
7791 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
7792 E->getDestroyedTypeLoc());
7793 } else {
7794 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +00007795 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00007796 *E->getDestroyedTypeIdentifier(),
7797 E->getDestroyedTypeLoc(),
7798 /*Scope=*/0,
7799 SS, ObjectTypePtr,
7800 false);
7801 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007802 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007803
Douglas Gregor678f90d2010-02-25 01:56:36 +00007804 Destroyed
7805 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
7806 E->getDestroyedTypeLoc());
7807 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007808
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007809 TypeSourceInfo *ScopeTypeInfo = 0;
7810 if (E->getScopeTypeInfo()) {
Douglas Gregora88c55b2013-03-08 21:25:01 +00007811 CXXScopeSpec EmptySS;
7812 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
7813 E->getScopeTypeInfo(), ObjectType, 0, EmptySS);
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007814 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007815 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00007816 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007817
John McCallb268a282010-08-23 23:25:46 +00007818 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00007819 E->getOperatorLoc(),
7820 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +00007821 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007822 ScopeTypeInfo,
7823 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00007824 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00007825 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00007826}
Mike Stump11289f42009-09-09 15:08:12 +00007827
Douglas Gregorad8a3362009-09-04 17:36:40 +00007828template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007829ExprResult
John McCalld14a8642009-11-21 08:51:07 +00007830TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007831 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00007832 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
7833 Sema::LookupOrdinaryName);
7834
7835 // Transform all the decls.
7836 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
7837 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007838 NamedDecl *InstD = static_cast<NamedDecl*>(
7839 getDerived().TransformDecl(Old->getNameLoc(),
7840 *I));
John McCall84d87672009-12-10 09:41:52 +00007841 if (!InstD) {
7842 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7843 // This can happen because of dependent hiding.
7844 if (isa<UsingShadowDecl>(*I))
7845 continue;
Serge Pavlov82605302013-09-04 04:50:29 +00007846 else {
7847 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00007848 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00007849 }
John McCall84d87672009-12-10 09:41:52 +00007850 }
John McCalle66edc12009-11-24 19:00:30 +00007851
7852 // Expand using declarations.
7853 if (isa<UsingDecl>(InstD)) {
7854 UsingDecl *UD = cast<UsingDecl>(InstD);
7855 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7856 E = UD->shadow_end(); I != E; ++I)
7857 R.addDecl(*I);
7858 continue;
7859 }
7860
7861 R.addDecl(InstD);
7862 }
7863
7864 // Resolve a kind, but don't do any further analysis. If it's
7865 // ambiguous, the callee needs to deal with it.
7866 R.resolveKind();
7867
7868 // Rebuild the nested-name qualifier, if present.
7869 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00007870 if (Old->getQualifierLoc()) {
7871 NestedNameSpecifierLoc QualifierLoc
7872 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7873 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007874 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007875
Douglas Gregor0da1d432011-02-28 20:01:57 +00007876 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00007877 }
7878
Douglas Gregor9262f472010-04-27 18:19:34 +00007879 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00007880 CXXRecordDecl *NamingClass
7881 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
7882 Old->getNameLoc(),
7883 Old->getNamingClass()));
Serge Pavlov82605302013-09-04 04:50:29 +00007884 if (!NamingClass) {
7885 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00007886 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00007887 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007888
Douglas Gregorda7be082010-04-27 16:10:10 +00007889 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00007890 }
7891
Abramo Bagnara7945c982012-01-27 09:46:47 +00007892 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
7893
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00007894 // If we have neither explicit template arguments, nor the template keyword,
7895 // it's a normal declaration name.
7896 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
John McCalle66edc12009-11-24 19:00:30 +00007897 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
7898
7899 // If we have template arguments, rebuild them, then rebuild the
7900 // templateid expression.
7901 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola3dd531d2012-08-28 04:13:54 +00007902 if (Old->hasExplicitTemplateArgs() &&
7903 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregor62e06f22010-12-20 17:31:10 +00007904 Old->getNumTemplateArgs(),
Serge Pavlov82605302013-09-04 04:50:29 +00007905 TransArgs)) {
7906 R.clear();
Douglas Gregor62e06f22010-12-20 17:31:10 +00007907 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00007908 }
John McCalle66edc12009-11-24 19:00:30 +00007909
Abramo Bagnara7945c982012-01-27 09:46:47 +00007910 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00007911 Old->requiresADL(), &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00007912}
Mike Stump11289f42009-09-09 15:08:12 +00007913
Douglas Gregora16548e2009-08-11 05:31:07 +00007914template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007915ExprResult
Douglas Gregor29c42f22012-02-24 07:38:34 +00007916TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
7917 bool ArgChanged = false;
Dmitri Gribenkof8579502013-01-12 19:30:44 +00007918 SmallVector<TypeSourceInfo *, 4> Args;
Douglas Gregor29c42f22012-02-24 07:38:34 +00007919 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
7920 TypeSourceInfo *From = E->getArg(I);
7921 TypeLoc FromTL = From->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00007922 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
Douglas Gregor29c42f22012-02-24 07:38:34 +00007923 TypeLocBuilder TLB;
7924 TLB.reserve(FromTL.getFullDataSize());
7925 QualType To = getDerived().TransformType(TLB, FromTL);
7926 if (To.isNull())
7927 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007928
Douglas Gregor29c42f22012-02-24 07:38:34 +00007929 if (To == From->getType())
7930 Args.push_back(From);
7931 else {
7932 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7933 ArgChanged = true;
7934 }
7935 continue;
7936 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007937
Douglas Gregor29c42f22012-02-24 07:38:34 +00007938 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00007939
Douglas Gregor29c42f22012-02-24 07:38:34 +00007940 // We have a pack expansion. Instantiate it.
David Blaikie6adc78e2013-02-18 22:06:02 +00007941 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
Douglas Gregor29c42f22012-02-24 07:38:34 +00007942 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
7943 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
7944 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00007945
Douglas Gregor29c42f22012-02-24 07:38:34 +00007946 // Determine whether the set of unexpanded parameter packs can and should
7947 // be expanded.
7948 bool Expand = true;
7949 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00007950 Optional<unsigned> OrigNumExpansions =
7951 ExpansionTL.getTypePtr()->getNumExpansions();
7952 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor29c42f22012-02-24 07:38:34 +00007953 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
7954 PatternTL.getSourceRange(),
7955 Unexpanded,
7956 Expand, RetainExpansion,
7957 NumExpansions))
7958 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007959
Douglas Gregor29c42f22012-02-24 07:38:34 +00007960 if (!Expand) {
7961 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00007962 // transformation on the pack expansion, producing another pack
Douglas Gregor29c42f22012-02-24 07:38:34 +00007963 // expansion.
7964 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier1dcde962012-08-08 18:46:20 +00007965
Douglas Gregor29c42f22012-02-24 07:38:34 +00007966 TypeLocBuilder TLB;
7967 TLB.reserve(From->getTypeLoc().getFullDataSize());
7968
7969 QualType To = getDerived().TransformType(TLB, PatternTL);
7970 if (To.isNull())
7971 return ExprError();
7972
Chad Rosier1dcde962012-08-08 18:46:20 +00007973 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00007974 PatternTL.getSourceRange(),
7975 ExpansionTL.getEllipsisLoc(),
7976 NumExpansions);
7977 if (To.isNull())
7978 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007979
Douglas Gregor29c42f22012-02-24 07:38:34 +00007980 PackExpansionTypeLoc ToExpansionTL
7981 = TLB.push<PackExpansionTypeLoc>(To);
7982 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7983 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7984 continue;
7985 }
7986
7987 // Expand the pack expansion by substituting for each argument in the
7988 // pack(s).
7989 for (unsigned I = 0; I != *NumExpansions; ++I) {
7990 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
7991 TypeLocBuilder TLB;
7992 TLB.reserve(PatternTL.getFullDataSize());
7993 QualType To = getDerived().TransformType(TLB, PatternTL);
7994 if (To.isNull())
7995 return ExprError();
7996
Eli Friedman5e05c4a2013-07-19 21:49:32 +00007997 if (To->containsUnexpandedParameterPack()) {
7998 To = getDerived().RebuildPackExpansionType(To,
7999 PatternTL.getSourceRange(),
8000 ExpansionTL.getEllipsisLoc(),
8001 NumExpansions);
8002 if (To.isNull())
8003 return ExprError();
8004
8005 PackExpansionTypeLoc ToExpansionTL
8006 = TLB.push<PackExpansionTypeLoc>(To);
8007 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8008 }
8009
Douglas Gregor29c42f22012-02-24 07:38:34 +00008010 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8011 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008012
Douglas Gregor29c42f22012-02-24 07:38:34 +00008013 if (!RetainExpansion)
8014 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00008015
Douglas Gregor29c42f22012-02-24 07:38:34 +00008016 // If we're supposed to retain a pack expansion, do so by temporarily
8017 // forgetting the partially-substituted parameter pack.
8018 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
8019
8020 TypeLocBuilder TLB;
8021 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00008022
Douglas Gregor29c42f22012-02-24 07:38:34 +00008023 QualType To = getDerived().TransformType(TLB, PatternTL);
8024 if (To.isNull())
8025 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008026
8027 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00008028 PatternTL.getSourceRange(),
8029 ExpansionTL.getEllipsisLoc(),
8030 NumExpansions);
8031 if (To.isNull())
8032 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008033
Douglas Gregor29c42f22012-02-24 07:38:34 +00008034 PackExpansionTypeLoc ToExpansionTL
8035 = TLB.push<PackExpansionTypeLoc>(To);
8036 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8037 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8038 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008039
Douglas Gregor29c42f22012-02-24 07:38:34 +00008040 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8041 return SemaRef.Owned(E);
8042
8043 return getDerived().RebuildTypeTrait(E->getTrait(),
8044 E->getLocStart(),
8045 Args,
8046 E->getLocEnd());
8047}
8048
8049template<typename Derived>
8050ExprResult
John Wiegley6242b6a2011-04-28 00:16:57 +00008051TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
8052 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
8053 if (!T)
8054 return ExprError();
8055
8056 if (!getDerived().AlwaysRebuild() &&
8057 T == E->getQueriedTypeSourceInfo())
8058 return SemaRef.Owned(E);
8059
8060 ExprResult SubExpr;
8061 {
8062 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8063 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
8064 if (SubExpr.isInvalid())
8065 return ExprError();
8066
8067 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
8068 return SemaRef.Owned(E);
8069 }
8070
8071 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
8072 E->getLocStart(),
8073 T,
8074 SubExpr.get(),
8075 E->getLocEnd());
8076}
8077
8078template<typename Derived>
8079ExprResult
John Wiegleyf9f65842011-04-25 06:54:41 +00008080TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
8081 ExprResult SubExpr;
8082 {
8083 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8084 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
8085 if (SubExpr.isInvalid())
8086 return ExprError();
8087
8088 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
8089 return SemaRef.Owned(E);
8090 }
8091
8092 return getDerived().RebuildExpressionTrait(
8093 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
8094}
8095
8096template<typename Derived>
8097ExprResult
John McCall8cd78132009-11-19 22:55:06 +00008098TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008099 DependentScopeDeclRefExpr *E) {
Richard Smithdb2630f2012-10-21 03:28:35 +00008100 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand*/false);
8101}
8102
8103template<typename Derived>
8104ExprResult
8105TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
8106 DependentScopeDeclRefExpr *E,
8107 bool IsAddressOfOperand) {
Reid Kleckner916ac4d2013-10-15 18:38:02 +00008108 assert(E->getQualifierLoc());
Douglas Gregor3a43fd62011-02-25 20:49:16 +00008109 NestedNameSpecifierLoc QualifierLoc
8110 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
8111 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008112 return ExprError();
Abramo Bagnara7945c982012-01-27 09:46:47 +00008113 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00008114
John McCall31f82722010-11-12 08:19:04 +00008115 // TODO: If this is a conversion-function-id, verify that the
8116 // destination type name (if present) resolves the same way after
8117 // instantiation as it did in the local scope.
8118
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008119 DeclarationNameInfo NameInfo
8120 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
8121 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00008122 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008123
John McCalle66edc12009-11-24 19:00:30 +00008124 if (!E->hasExplicitTemplateArgs()) {
8125 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3a43fd62011-02-25 20:49:16 +00008126 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008127 // Note: it is sufficient to compare the Name component of NameInfo:
8128 // if name has not changed, DNLoc has not changed either.
8129 NameInfo.getName() == E->getDeclName())
John McCallc3007a22010-10-26 07:05:15 +00008130 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00008131
Douglas Gregor3a43fd62011-02-25 20:49:16 +00008132 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008133 TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008134 NameInfo,
Richard Smithdb2630f2012-10-21 03:28:35 +00008135 /*TemplateArgs*/ 0,
8136 IsAddressOfOperand);
Douglas Gregord019ff62009-10-22 17:20:55 +00008137 }
John McCall6b51f282009-11-23 01:53:49 +00008138
8139 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008140 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8141 E->getNumTemplateArgs(),
8142 TransArgs))
8143 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008144
Douglas Gregor3a43fd62011-02-25 20:49:16 +00008145 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008146 TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008147 NameInfo,
Richard Smithdb2630f2012-10-21 03:28:35 +00008148 &TransArgs,
8149 IsAddressOfOperand);
Douglas Gregora16548e2009-08-11 05:31:07 +00008150}
8151
8152template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008153ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008154TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithd59b8322012-12-19 01:39:02 +00008155 // CXXConstructExprs other than for list-initialization and
8156 // CXXTemporaryObjectExpr are always implicit, so when we have
8157 // a 1-argument construction we just transform that argument.
Richard Smithdd2ca572012-11-26 08:32:48 +00008158 if ((E->getNumArgs() == 1 ||
8159 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithd59b8322012-12-19 01:39:02 +00008160 (!getDerived().DropCallArgument(E->getArg(0))) &&
8161 !E->isListInitialization())
Douglas Gregordb56b912010-02-03 03:01:57 +00008162 return getDerived().TransformExpr(E->getArg(0));
8163
Douglas Gregora16548e2009-08-11 05:31:07 +00008164 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
8165
8166 QualType T = getDerived().TransformType(E->getType());
8167 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00008168 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008169
8170 CXXConstructorDecl *Constructor
8171 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008172 getDerived().TransformDecl(E->getLocStart(),
8173 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008174 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00008175 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008176
Douglas Gregora16548e2009-08-11 05:31:07 +00008177 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008178 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00008179 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00008180 &ArgumentChanged))
8181 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008182
Douglas Gregora16548e2009-08-11 05:31:07 +00008183 if (!getDerived().AlwaysRebuild() &&
8184 T == E->getType() &&
8185 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00008186 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00008187 // Mark the constructor as referenced.
8188 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00008189 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00008190 return SemaRef.Owned(E);
Douglas Gregorde550352010-02-26 00:01:57 +00008191 }
Mike Stump11289f42009-09-09 15:08:12 +00008192
Douglas Gregordb121ba2009-12-14 16:27:04 +00008193 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
8194 Constructor, E->isElidable(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008195 Args,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00008196 E->hadMultipleCandidates(),
Richard Smithd59b8322012-12-19 01:39:02 +00008197 E->isListInitialization(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00008198 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00008199 E->getConstructionKind(),
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00008200 E->getParenOrBraceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00008201}
Mike Stump11289f42009-09-09 15:08:12 +00008202
Douglas Gregora16548e2009-08-11 05:31:07 +00008203/// \brief Transform a C++ temporary-binding expression.
8204///
Douglas Gregor363b1512009-12-24 18:51:59 +00008205/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
8206/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00008207template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008208ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008209TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00008210 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008211}
Mike Stump11289f42009-09-09 15:08:12 +00008212
John McCall5d413782010-12-06 08:20:24 +00008213/// \brief Transform a C++ expression that contains cleanups that should
8214/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +00008215///
John McCall5d413782010-12-06 08:20:24 +00008216/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +00008217/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00008218template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008219ExprResult
John McCall5d413782010-12-06 08:20:24 +00008220TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00008221 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008222}
Mike Stump11289f42009-09-09 15:08:12 +00008223
Douglas Gregora16548e2009-08-11 05:31:07 +00008224template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008225ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008226TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00008227 CXXTemporaryObjectExpr *E) {
8228 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8229 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00008230 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008231
Douglas Gregora16548e2009-08-11 05:31:07 +00008232 CXXConstructorDecl *Constructor
8233 = cast_or_null<CXXConstructorDecl>(
Chad Rosier1dcde962012-08-08 18:46:20 +00008234 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008235 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008236 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00008237 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008238
Douglas Gregora16548e2009-08-11 05:31:07 +00008239 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008240 SmallVector<Expr*, 8> Args;
Douglas Gregora16548e2009-08-11 05:31:07 +00008241 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +00008242 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00008243 &ArgumentChanged))
8244 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008245
Douglas Gregora16548e2009-08-11 05:31:07 +00008246 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00008247 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008248 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00008249 !ArgumentChanged) {
8250 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00008251 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00008252 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00008253 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008254
Richard Smithd59b8322012-12-19 01:39:02 +00008255 // FIXME: Pass in E->isListInitialization().
Douglas Gregor2b88c112010-09-08 00:15:04 +00008256 return getDerived().RebuildCXXTemporaryObjectExpr(T,
8257 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008258 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00008259 E->getLocEnd());
8260}
Mike Stump11289f42009-09-09 15:08:12 +00008261
Douglas Gregora16548e2009-08-11 05:31:07 +00008262template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008263ExprResult
Douglas Gregore31e6062012-02-07 10:09:13 +00008264TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008265
8266 // Transform any init-capture expressions before entering the scope of the
8267 // lambda body, because they are not semantically within that scope.
8268 SmallVector<InitCaptureInfoTy, 8> InitCaptureExprsAndTypes;
8269 InitCaptureExprsAndTypes.resize(E->explicit_capture_end() -
8270 E->explicit_capture_begin());
8271
8272 for (LambdaExpr::capture_iterator C = E->capture_begin(),
8273 CEnd = E->capture_end();
8274 C != CEnd; ++C) {
8275 if (!C->isInitCapture())
8276 continue;
8277 EnterExpressionEvaluationContext EEEC(getSema(),
8278 Sema::PotentiallyEvaluated);
8279 ExprResult NewExprInitResult = getDerived().TransformInitializer(
8280 C->getCapturedVar()->getInit(),
8281 C->getCapturedVar()->getInitStyle() == VarDecl::CallInit);
8282
8283 if (NewExprInitResult.isInvalid())
8284 return ExprError();
8285 Expr *NewExprInit = NewExprInitResult.get();
8286
8287 VarDecl *OldVD = C->getCapturedVar();
8288 QualType NewInitCaptureType =
8289 getSema().performLambdaInitCaptureInitialization(C->getLocation(),
8290 OldVD->getType()->isReferenceType(), OldVD->getIdentifier(),
8291 NewExprInit);
8292 NewExprInitResult = NewExprInit;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008293 InitCaptureExprsAndTypes[C - E->capture_begin()] =
8294 std::make_pair(NewExprInitResult, NewInitCaptureType);
8295
8296 }
8297
Faisal Vali524ca282013-11-12 01:40:44 +00008298 LambdaScopeInfo *LSI = getSema().PushLambdaScope();
Faisal Vali2cba1332013-10-23 06:44:28 +00008299 // Transform the template parameters, and add them to the current
8300 // instantiation scope. The null case is handled correctly.
8301 LSI->GLTemplateParameterList = getDerived().TransformTemplateParameterList(
8302 E->getTemplateParameterList());
8303
8304 // Check to see if the TypeSourceInfo of the call operator needs to
8305 // be transformed, and if so do the transformation in the
8306 // CurrentInstantiationScope.
8307
8308 TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo();
8309 FunctionProtoTypeLoc OldCallOpFPTL =
8310 OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>();
8311 TypeSourceInfo *NewCallOpTSI = 0;
8312
8313 const bool CallOpWasAlreadyTransformed =
8314 getDerived().AlreadyTransformed(OldCallOpTSI->getType());
8315
8316 // Use the Old Call Operator's TypeSourceInfo if it is already transformed.
8317 if (CallOpWasAlreadyTransformed)
8318 NewCallOpTSI = OldCallOpTSI;
8319 else {
8320 // Transform the TypeSourceInfo of the Original Lambda's Call Operator.
8321 // The transformation MUST be done in the CurrentInstantiationScope since
8322 // it introduces a mapping of the original to the newly created
8323 // transformed parameters.
8324
8325 TypeLocBuilder NewCallOpTLBuilder;
8326 QualType NewCallOpType = TransformFunctionProtoType(NewCallOpTLBuilder,
8327 OldCallOpFPTL,
8328 0, 0);
8329 NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context,
8330 NewCallOpType);
Faisal Vali2b391ab2013-09-26 19:54:12 +00008331 }
Faisal Vali2cba1332013-10-23 06:44:28 +00008332 // Extract the ParmVarDecls from the NewCallOpTSI and add them to
8333 // the vector below - this will be used to synthesize the
8334 // NewCallOperator. Additionally, add the parameters of the untransformed
8335 // lambda call operator to the CurrentInstantiationScope.
8336 SmallVector<ParmVarDecl *, 4> Params;
8337 {
8338 FunctionProtoTypeLoc NewCallOpFPTL =
8339 NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>();
8340 ParmVarDecl **NewParamDeclArray = NewCallOpFPTL.getParmArray();
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00008341 const unsigned NewNumArgs = NewCallOpFPTL.getNumParams();
Faisal Vali2cba1332013-10-23 06:44:28 +00008342
8343 for (unsigned I = 0; I < NewNumArgs; ++I) {
8344 // If this call operator's type does not require transformation,
8345 // the parameters do not get added to the current instantiation scope,
8346 // - so ADD them! This allows the following to compile when the enclosing
8347 // template is specialized and the entire lambda expression has to be
8348 // transformed.
8349 // template<class T> void foo(T t) {
8350 // auto L = [](auto a) {
8351 // auto M = [](char b) { <-- note: non-generic lambda
8352 // auto N = [](auto c) {
8353 // int x = sizeof(a);
8354 // x = sizeof(b); <-- specifically this line
8355 // x = sizeof(c);
8356 // };
8357 // };
8358 // };
8359 // }
8360 // foo('a')
8361 if (CallOpWasAlreadyTransformed)
8362 getDerived().transformedLocalDecl(NewParamDeclArray[I],
8363 NewParamDeclArray[I]);
8364 // Add to Params array, so these parameters can be used to create
8365 // the newly transformed call operator.
8366 Params.push_back(NewParamDeclArray[I]);
8367 }
8368 }
8369
8370 if (!NewCallOpTSI)
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008371 return ExprError();
8372
Eli Friedmand564afb2012-09-19 01:18:11 +00008373 // Create the local class that will describe the lambda.
8374 CXXRecordDecl *Class
8375 = getSema().createLambdaClosureType(E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +00008376 NewCallOpTSI,
Faisal Valic1a6dc42013-10-23 16:10:50 +00008377 /*KnownDependent=*/false,
8378 E->getCaptureDefault());
8379
Eli Friedmand564afb2012-09-19 01:18:11 +00008380 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
8381
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008382 // Build the call operator.
Faisal Vali2cba1332013-10-23 06:44:28 +00008383 CXXMethodDecl *NewCallOperator
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008384 = getSema().startLambdaDefinition(Class, E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +00008385 NewCallOpTSI,
Douglas Gregoradb376e2012-02-14 22:28:59 +00008386 E->getCallOperator()->getLocEnd(),
Richard Smith505df232012-07-22 23:45:10 +00008387 Params);
Faisal Vali2cba1332013-10-23 06:44:28 +00008388 LSI->CallOperator = NewCallOperator;
Rafael Espindola4b35f272013-10-04 14:28:51 +00008389
Faisal Vali2cba1332013-10-23 06:44:28 +00008390 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
8391
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008392 return getDerived().TransformLambdaScope(E, NewCallOperator,
8393 InitCaptureExprsAndTypes);
Richard Smith2589b9802012-07-25 03:56:55 +00008394}
8395
8396template<typename Derived>
8397ExprResult
8398TreeTransform<Derived>::TransformLambdaScope(LambdaExpr *E,
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008399 CXXMethodDecl *CallOperator,
8400 ArrayRef<InitCaptureInfoTy> InitCaptureExprsAndTypes) {
Richard Smithba71c082013-05-16 06:20:58 +00008401 bool Invalid = false;
8402
Douglas Gregorb4328232012-02-14 00:00:48 +00008403 // Introduce the context of the call operator.
Richard Smith7ff2bcb2014-01-24 01:54:52 +00008404 Sema::ContextRAII SavedContext(getSema(), CallOperator,
8405 /*NewThisContext*/false);
Douglas Gregorb4328232012-02-14 00:00:48 +00008406
Faisal Vali2b391ab2013-09-26 19:54:12 +00008407 LambdaScopeInfo *const LSI = getSema().getCurLambda();
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008408 // Enter the scope of the lambda.
Faisal Vali2b391ab2013-09-26 19:54:12 +00008409 getSema().buildLambdaScope(LSI, CallOperator, E->getIntroducerRange(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008410 E->getCaptureDefault(),
James Dennettddd36ff2013-08-09 23:08:25 +00008411 E->getCaptureDefaultLoc(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008412 E->hasExplicitParameters(),
8413 E->hasExplicitResultType(),
8414 E->isMutable());
Chad Rosier1dcde962012-08-08 18:46:20 +00008415
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008416 // Transform captures.
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008417 bool FinishedExplicitCaptures = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00008418 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008419 CEnd = E->capture_end();
8420 C != CEnd; ++C) {
8421 // When we hit the first implicit capture, tell Sema that we've finished
8422 // the list of explicit captures.
8423 if (!FinishedExplicitCaptures && C->isImplicit()) {
8424 getSema().finishLambdaExplicitCaptures(LSI);
8425 FinishedExplicitCaptures = true;
8426 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008427
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008428 // Capturing 'this' is trivial.
8429 if (C->capturesThis()) {
8430 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
8431 continue;
8432 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008433
Richard Smithba71c082013-05-16 06:20:58 +00008434 // Rebuild init-captures, including the implied field declaration.
8435 if (C->isInitCapture()) {
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008436
8437 InitCaptureInfoTy InitExprTypePair =
8438 InitCaptureExprsAndTypes[C - E->capture_begin()];
8439 ExprResult Init = InitExprTypePair.first;
8440 QualType InitQualType = InitExprTypePair.second;
8441 if (Init.isInvalid() || InitQualType.isNull()) {
Richard Smithba71c082013-05-16 06:20:58 +00008442 Invalid = true;
8443 continue;
8444 }
Richard Smithbb13c9a2013-09-28 04:02:39 +00008445 VarDecl *OldVD = C->getCapturedVar();
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008446 VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl(
8447 OldVD->getLocation(), InitExprTypePair.second,
8448 OldVD->getIdentifier(), Init.get());
Richard Smithbb13c9a2013-09-28 04:02:39 +00008449 if (!NewVD)
Richard Smithba71c082013-05-16 06:20:58 +00008450 Invalid = true;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008451 else {
Richard Smithbb13c9a2013-09-28 04:02:39 +00008452 getDerived().transformedLocalDecl(OldVD, NewVD);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008453 }
Richard Smithbb13c9a2013-09-28 04:02:39 +00008454 getSema().buildInitCaptureField(LSI, NewVD);
Richard Smithba71c082013-05-16 06:20:58 +00008455 continue;
8456 }
8457
8458 assert(C->capturesVariable() && "unexpected kind of lambda capture");
8459
Douglas Gregor3e308b12012-02-14 19:27:52 +00008460 // Determine the capture kind for Sema.
8461 Sema::TryCaptureKind Kind
8462 = C->isImplicit()? Sema::TryCapture_Implicit
8463 : C->getCaptureKind() == LCK_ByCopy
8464 ? Sema::TryCapture_ExplicitByVal
8465 : Sema::TryCapture_ExplicitByRef;
8466 SourceLocation EllipsisLoc;
8467 if (C->isPackExpansion()) {
8468 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
8469 bool ShouldExpand = false;
8470 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00008471 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +00008472 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
8473 C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +00008474 Unexpanded,
8475 ShouldExpand, RetainExpansion,
Richard Smithba71c082013-05-16 06:20:58 +00008476 NumExpansions)) {
8477 Invalid = true;
8478 continue;
8479 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008480
Douglas Gregor3e308b12012-02-14 19:27:52 +00008481 if (ShouldExpand) {
8482 // The transform has determined that we should perform an expansion;
8483 // transform and capture each of the arguments.
8484 // expansion of the pattern. Do so.
8485 VarDecl *Pack = C->getCapturedVar();
8486 for (unsigned I = 0; I != *NumExpansions; ++I) {
8487 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8488 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +00008489 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +00008490 Pack));
8491 if (!CapturedVar) {
8492 Invalid = true;
8493 continue;
8494 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008495
Douglas Gregor3e308b12012-02-14 19:27:52 +00008496 // Capture the transformed variable.
Chad Rosier1dcde962012-08-08 18:46:20 +00008497 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
8498 }
Douglas Gregor3e308b12012-02-14 19:27:52 +00008499 continue;
8500 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008501
Douglas Gregor3e308b12012-02-14 19:27:52 +00008502 EllipsisLoc = C->getEllipsisLoc();
8503 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008504
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008505 // Transform the captured variable.
8506 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +00008507 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008508 C->getCapturedVar()));
8509 if (!CapturedVar) {
8510 Invalid = true;
8511 continue;
8512 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008513
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008514 // Capture the transformed variable.
Douglas Gregorfdf598e2012-02-18 09:37:24 +00008515 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008516 }
8517 if (!FinishedExplicitCaptures)
8518 getSema().finishLambdaExplicitCaptures(LSI);
8519
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008520
8521 // Enter a new evaluation context to insulate the lambda from any
8522 // cleanups from the enclosing full-expression.
Chad Rosier1dcde962012-08-08 18:46:20 +00008523 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008524
8525 if (Invalid) {
Chad Rosier1dcde962012-08-08 18:46:20 +00008526 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008527 /*IsInstantiation=*/true);
8528 return ExprError();
8529 }
8530
8531 // Instantiate the body of the lambda expression.
Douglas Gregorb4328232012-02-14 00:00:48 +00008532 StmtResult Body = getDerived().TransformStmt(E->getBody());
8533 if (Body.isInvalid()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00008534 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
Douglas Gregorb4328232012-02-14 00:00:48 +00008535 /*IsInstantiation=*/true);
Chad Rosier1dcde962012-08-08 18:46:20 +00008536 return ExprError();
Douglas Gregorb4328232012-02-14 00:00:48 +00008537 }
Douglas Gregor7fcbd902012-02-21 00:37:24 +00008538
Chad Rosier1dcde962012-08-08 18:46:20 +00008539 return getSema().ActOnLambdaExpr(E->getLocStart(), Body.take(),
Douglas Gregorb61e8092012-04-04 17:40:10 +00008540 /*CurScope=*/0, /*IsInstantiation=*/true);
Douglas Gregore31e6062012-02-07 10:09:13 +00008541}
8542
8543template<typename Derived>
8544ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008545TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008546 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00008547 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8548 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00008549 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008550
Douglas Gregora16548e2009-08-11 05:31:07 +00008551 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008552 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +00008553 Args.reserve(E->arg_size());
Chad Rosier1dcde962012-08-08 18:46:20 +00008554 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00008555 &ArgumentChanged))
8556 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008557
Douglas Gregora16548e2009-08-11 05:31:07 +00008558 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00008559 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008560 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00008561 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00008562
Douglas Gregora16548e2009-08-11 05:31:07 +00008563 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +00008564 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +00008565 E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008566 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00008567 E->getRParenLoc());
8568}
Mike Stump11289f42009-09-09 15:08:12 +00008569
Douglas Gregora16548e2009-08-11 05:31:07 +00008570template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008571ExprResult
John McCall8cd78132009-11-19 22:55:06 +00008572TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008573 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008574 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00008575 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00008576 Expr *OldBase;
8577 QualType BaseType;
8578 QualType ObjectType;
8579 if (!E->isImplicitAccess()) {
8580 OldBase = E->getBase();
8581 Base = getDerived().TransformExpr(OldBase);
8582 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008583 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008584
John McCall2d74de92009-12-01 22:10:20 +00008585 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +00008586 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +00008587 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00008588 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00008589 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00008590 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00008591 ObjectTy,
8592 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00008593 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008594 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00008595
John McCallba7bf592010-08-24 05:47:05 +00008596 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +00008597 BaseType = ((Expr*) Base.get())->getType();
8598 } else {
8599 OldBase = 0;
8600 BaseType = getDerived().TransformType(E->getBaseType());
8601 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
8602 }
Mike Stump11289f42009-09-09 15:08:12 +00008603
Douglas Gregora5cb6da2009-10-20 05:58:46 +00008604 // Transform the first part of the nested-name-specifier that qualifies
8605 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00008606 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00008607 = getDerived().TransformFirstQualifierInScope(
Douglas Gregore16af532011-02-28 18:50:33 +00008608 E->getFirstQualifierFoundInScope(),
8609 E->getQualifierLoc().getBeginLoc());
Mike Stump11289f42009-09-09 15:08:12 +00008610
Douglas Gregore16af532011-02-28 18:50:33 +00008611 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00008612 if (E->getQualifier()) {
Douglas Gregore16af532011-02-28 18:50:33 +00008613 QualifierLoc
8614 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
8615 ObjectType,
8616 FirstQualifierInScope);
8617 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008618 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +00008619 }
Mike Stump11289f42009-09-09 15:08:12 +00008620
Abramo Bagnara7945c982012-01-27 09:46:47 +00008621 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
8622
John McCall31f82722010-11-12 08:19:04 +00008623 // TODO: If this is a conversion-function-id, verify that the
8624 // destination type name (if present) resolves the same way after
8625 // instantiation as it did in the local scope.
8626
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008627 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +00008628 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008629 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00008630 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008631
John McCall2d74de92009-12-01 22:10:20 +00008632 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00008633 // This is a reference to a member without an explicitly-specified
8634 // template argument list. Optimize for this common case.
8635 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00008636 Base.get() == OldBase &&
8637 BaseType == E->getBaseType() &&
Douglas Gregore16af532011-02-28 18:50:33 +00008638 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008639 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00008640 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCallc3007a22010-10-26 07:05:15 +00008641 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00008642
John McCallb268a282010-08-23 23:25:46 +00008643 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00008644 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00008645 E->isArrow(),
8646 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00008647 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008648 TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00008649 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008650 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00008651 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00008652 }
8653
John McCall6b51f282009-11-23 01:53:49 +00008654 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008655 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8656 E->getNumTemplateArgs(),
8657 TransArgs))
8658 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008659
John McCallb268a282010-08-23 23:25:46 +00008660 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00008661 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00008662 E->isArrow(),
8663 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00008664 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008665 TemplateKWLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +00008666 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008667 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00008668 &TransArgs);
8669}
8670
8671template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008672ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008673TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00008674 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00008675 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00008676 QualType BaseType;
8677 if (!Old->isImplicitAccess()) {
8678 Base = getDerived().TransformExpr(Old->getBase());
8679 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008680 return ExprError();
Richard Smithcab9a7d2011-10-26 19:06:56 +00008681 Base = getSema().PerformMemberExprBaseConversion(Base.take(),
8682 Old->isArrow());
8683 if (Base.isInvalid())
8684 return ExprError();
8685 BaseType = Base.get()->getType();
John McCall2d74de92009-12-01 22:10:20 +00008686 } else {
8687 BaseType = getDerived().TransformType(Old->getBaseType());
8688 }
John McCall10eae182009-11-30 22:42:35 +00008689
Douglas Gregor0da1d432011-02-28 20:01:57 +00008690 NestedNameSpecifierLoc QualifierLoc;
8691 if (Old->getQualifierLoc()) {
8692 QualifierLoc
8693 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
8694 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008695 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00008696 }
8697
Abramo Bagnara7945c982012-01-27 09:46:47 +00008698 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
8699
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008700 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +00008701 Sema::LookupOrdinaryName);
8702
8703 // Transform all the decls.
8704 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
8705 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008706 NamedDecl *InstD = static_cast<NamedDecl*>(
8707 getDerived().TransformDecl(Old->getMemberLoc(),
8708 *I));
John McCall84d87672009-12-10 09:41:52 +00008709 if (!InstD) {
8710 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
8711 // This can happen because of dependent hiding.
8712 if (isa<UsingShadowDecl>(*I))
8713 continue;
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00008714 else {
8715 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00008716 return ExprError();
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00008717 }
John McCall84d87672009-12-10 09:41:52 +00008718 }
John McCall10eae182009-11-30 22:42:35 +00008719
8720 // Expand using declarations.
8721 if (isa<UsingDecl>(InstD)) {
8722 UsingDecl *UD = cast<UsingDecl>(InstD);
8723 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
8724 E = UD->shadow_end(); I != E; ++I)
8725 R.addDecl(*I);
8726 continue;
8727 }
8728
8729 R.addDecl(InstD);
8730 }
8731
8732 R.resolveKind();
8733
Douglas Gregor9262f472010-04-27 18:19:34 +00008734 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00008735 if (Old->getNamingClass()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00008736 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00008737 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00008738 Old->getMemberLoc(),
8739 Old->getNamingClass()));
8740 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00008741 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008742
Douglas Gregorda7be082010-04-27 16:10:10 +00008743 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00008744 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008745
John McCall10eae182009-11-30 22:42:35 +00008746 TemplateArgumentListInfo TransArgs;
8747 if (Old->hasExplicitTemplateArgs()) {
8748 TransArgs.setLAngleLoc(Old->getLAngleLoc());
8749 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008750 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
8751 Old->getNumTemplateArgs(),
8752 TransArgs))
8753 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00008754 }
John McCall38836f02010-01-15 08:34:02 +00008755
8756 // FIXME: to do this check properly, we will need to preserve the
8757 // first-qualifier-in-scope here, just in case we had a dependent
8758 // base (and therefore couldn't do the check) and a
8759 // nested-name-qualifier (and therefore could do the lookup).
8760 NamedDecl *FirstQualifierInScope = 0;
Chad Rosier1dcde962012-08-08 18:46:20 +00008761
John McCallb268a282010-08-23 23:25:46 +00008762 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00008763 BaseType,
John McCall10eae182009-11-30 22:42:35 +00008764 Old->getOperatorLoc(),
8765 Old->isArrow(),
Douglas Gregor0da1d432011-02-28 20:01:57 +00008766 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008767 TemplateKWLoc,
John McCall38836f02010-01-15 08:34:02 +00008768 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00008769 R,
8770 (Old->hasExplicitTemplateArgs()
8771 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00008772}
8773
8774template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008775ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +00008776TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Alexis Hunt414e3e32011-05-31 19:54:49 +00008777 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00008778 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
8779 if (SubExpr.isInvalid())
8780 return ExprError();
8781
8782 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCallc3007a22010-10-26 07:05:15 +00008783 return SemaRef.Owned(E);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00008784
8785 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
8786}
8787
8788template<typename Derived>
8789ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +00008790TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +00008791 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
8792 if (Pattern.isInvalid())
8793 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008794
Douglas Gregor0f836ea2011-01-13 00:19:55 +00008795 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
8796 return SemaRef.Owned(E);
8797
Douglas Gregorb8840002011-01-14 21:20:45 +00008798 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
8799 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +00008800}
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008801
8802template<typename Derived>
8803ExprResult
8804TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
8805 // If E is not value-dependent, then nothing will change when we transform it.
8806 // Note: This is an instantiation-centric view.
8807 if (!E->isValueDependent())
8808 return SemaRef.Owned(E);
8809
8810 // Note: None of the implementations of TryExpandParameterPacks can ever
8811 // produce a diagnostic when given only a single unexpanded parameter pack,
Chad Rosier1dcde962012-08-08 18:46:20 +00008812 // so
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008813 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
8814 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00008815 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00008816 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +00008817 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikieb9c168a2011-09-22 02:34:54 +00008818 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00008819 ShouldExpand, RetainExpansion,
8820 NumExpansions))
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008821 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008822
Douglas Gregorab96bcf2011-10-10 18:59:29 +00008823 if (RetainExpansion)
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008824 return SemaRef.Owned(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00008825
Douglas Gregorab96bcf2011-10-10 18:59:29 +00008826 NamedDecl *Pack = E->getPack();
8827 if (!ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00008828 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
Douglas Gregorab96bcf2011-10-10 18:59:29 +00008829 Pack));
8830 if (!Pack)
8831 return ExprError();
8832 }
8833
Chad Rosier1dcde962012-08-08 18:46:20 +00008834
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008835 // We now know the length of the parameter pack, so build a new expression
8836 // that stores that length.
Chad Rosier1dcde962012-08-08 18:46:20 +00008837 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
8838 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregorab96bcf2011-10-10 18:59:29 +00008839 NumExpansions);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008840}
8841
Douglas Gregore8e9dd62011-01-03 17:17:50 +00008842template<typename Derived>
8843ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +00008844TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
8845 SubstNonTypeTemplateParmPackExpr *E) {
8846 // Default behavior is to do nothing with this transformation.
8847 return SemaRef.Owned(E);
8848}
8849
8850template<typename Derived>
8851ExprResult
John McCall7c454bb2011-07-15 05:09:51 +00008852TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
8853 SubstNonTypeTemplateParmExpr *E) {
8854 // Default behavior is to do nothing with this transformation.
8855 return SemaRef.Owned(E);
8856}
8857
8858template<typename Derived>
8859ExprResult
Richard Smithb15fe3a2012-09-12 00:56:43 +00008860TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
8861 // Default behavior is to do nothing with this transformation.
8862 return SemaRef.Owned(E);
8863}
8864
8865template<typename Derived>
8866ExprResult
Douglas Gregorfe314812011-06-21 17:03:29 +00008867TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
8868 MaterializeTemporaryExpr *E) {
8869 return getDerived().TransformExpr(E->GetTemporaryExpr());
8870}
Chad Rosier1dcde962012-08-08 18:46:20 +00008871
Douglas Gregorfe314812011-06-21 17:03:29 +00008872template<typename Derived>
8873ExprResult
Richard Smithcc1b96d2013-06-12 22:31:48 +00008874TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
8875 CXXStdInitializerListExpr *E) {
8876 return getDerived().TransformExpr(E->getSubExpr());
8877}
8878
8879template<typename Derived>
8880ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008881TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00008882 return SemaRef.MaybeBindToTemporary(E);
8883}
8884
8885template<typename Derived>
8886ExprResult
8887TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Jordy Rose8986c5992012-03-12 17:53:02 +00008888 return SemaRef.Owned(E);
Ted Kremeneke65b0862012-03-06 20:05:56 +00008889}
8890
8891template<typename Derived>
8892ExprResult
Patrick Beard0caa3942012-04-19 00:25:12 +00008893TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
8894 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
8895 if (SubExpr.isInvalid())
8896 return ExprError();
8897
8898 if (!getDerived().AlwaysRebuild() &&
8899 SubExpr.get() == E->getSubExpr())
8900 return SemaRef.Owned(E);
8901
8902 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremeneke65b0862012-03-06 20:05:56 +00008903}
8904
8905template<typename Derived>
8906ExprResult
8907TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
8908 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +00008909 SmallVector<Expr *, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +00008910 bool ArgChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00008911 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremeneke65b0862012-03-06 20:05:56 +00008912 /*IsCall=*/false, Elements, &ArgChanged))
8913 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008914
Ted Kremeneke65b0862012-03-06 20:05:56 +00008915 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8916 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00008917
Ted Kremeneke65b0862012-03-06 20:05:56 +00008918 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
8919 Elements.data(),
8920 Elements.size());
8921}
8922
8923template<typename Derived>
8924ExprResult
8925TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier1dcde962012-08-08 18:46:20 +00008926 ObjCDictionaryLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00008927 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +00008928 SmallVector<ObjCDictionaryElement, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +00008929 bool ArgChanged = false;
8930 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
8931 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier1dcde962012-08-08 18:46:20 +00008932
Ted Kremeneke65b0862012-03-06 20:05:56 +00008933 if (OrigElement.isPackExpansion()) {
8934 // This key/value element is a pack expansion.
8935 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
8936 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
8937 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
8938 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
8939
8940 // Determine whether the set of unexpanded parameter packs can
8941 // and should be expanded.
8942 bool Expand = true;
8943 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00008944 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
8945 Optional<unsigned> NumExpansions = OrigNumExpansions;
Ted Kremeneke65b0862012-03-06 20:05:56 +00008946 SourceRange PatternRange(OrigElement.Key->getLocStart(),
8947 OrigElement.Value->getLocEnd());
8948 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
8949 PatternRange,
8950 Unexpanded,
8951 Expand, RetainExpansion,
8952 NumExpansions))
8953 return ExprError();
8954
8955 if (!Expand) {
8956 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00008957 // transformation on the pack expansion, producing another pack
Ted Kremeneke65b0862012-03-06 20:05:56 +00008958 // expansion.
8959 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
8960 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8961 if (Key.isInvalid())
8962 return ExprError();
8963
8964 if (Key.get() != OrigElement.Key)
8965 ArgChanged = true;
8966
8967 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8968 if (Value.isInvalid())
8969 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008970
Ted Kremeneke65b0862012-03-06 20:05:56 +00008971 if (Value.get() != OrigElement.Value)
8972 ArgChanged = true;
8973
Chad Rosier1dcde962012-08-08 18:46:20 +00008974 ObjCDictionaryElement Expansion = {
Ted Kremeneke65b0862012-03-06 20:05:56 +00008975 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
8976 };
8977 Elements.push_back(Expansion);
8978 continue;
8979 }
8980
8981 // Record right away that the argument was changed. This needs
8982 // to happen even if the array expands to nothing.
8983 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00008984
Ted Kremeneke65b0862012-03-06 20:05:56 +00008985 // The transform has determined that we should perform an elementwise
8986 // expansion of the pattern. Do so.
8987 for (unsigned I = 0; I != *NumExpansions; ++I) {
8988 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8989 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8990 if (Key.isInvalid())
8991 return ExprError();
8992
8993 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8994 if (Value.isInvalid())
8995 return ExprError();
8996
Chad Rosier1dcde962012-08-08 18:46:20 +00008997 ObjCDictionaryElement Element = {
Ted Kremeneke65b0862012-03-06 20:05:56 +00008998 Key.get(), Value.get(), SourceLocation(), NumExpansions
8999 };
9000
9001 // If any unexpanded parameter packs remain, we still have a
9002 // pack expansion.
9003 if (Key.get()->containsUnexpandedParameterPack() ||
9004 Value.get()->containsUnexpandedParameterPack())
9005 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier1dcde962012-08-08 18:46:20 +00009006
Ted Kremeneke65b0862012-03-06 20:05:56 +00009007 Elements.push_back(Element);
9008 }
9009
9010 // We've finished with this pack expansion.
9011 continue;
9012 }
9013
9014 // Transform and check key.
9015 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
9016 if (Key.isInvalid())
9017 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009018
Ted Kremeneke65b0862012-03-06 20:05:56 +00009019 if (Key.get() != OrigElement.Key)
9020 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009021
Ted Kremeneke65b0862012-03-06 20:05:56 +00009022 // Transform and check value.
9023 ExprResult Value
9024 = getDerived().TransformExpr(OrigElement.Value);
9025 if (Value.isInvalid())
9026 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009027
Ted Kremeneke65b0862012-03-06 20:05:56 +00009028 if (Value.get() != OrigElement.Value)
9029 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009030
9031 ObjCDictionaryElement Element = {
David Blaikie7a30dc52013-02-21 01:47:18 +00009032 Key.get(), Value.get(), SourceLocation(), None
Ted Kremeneke65b0862012-03-06 20:05:56 +00009033 };
9034 Elements.push_back(Element);
9035 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009036
Ted Kremeneke65b0862012-03-06 20:05:56 +00009037 if (!getDerived().AlwaysRebuild() && !ArgChanged)
9038 return SemaRef.MaybeBindToTemporary(E);
9039
9040 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
9041 Elements.data(),
9042 Elements.size());
Douglas Gregora16548e2009-08-11 05:31:07 +00009043}
9044
Mike Stump11289f42009-09-09 15:08:12 +00009045template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009046ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009047TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00009048 TypeSourceInfo *EncodedTypeInfo
9049 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
9050 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009051 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009052
Douglas Gregora16548e2009-08-11 05:31:07 +00009053 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00009054 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00009055 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009056
9057 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00009058 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00009059 E->getRParenLoc());
9060}
Mike Stump11289f42009-09-09 15:08:12 +00009061
Douglas Gregora16548e2009-08-11 05:31:07 +00009062template<typename Derived>
John McCall31168b02011-06-15 23:02:42 +00009063ExprResult TreeTransform<Derived>::
9064TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
John McCallbc489892013-04-11 02:14:26 +00009065 // This is a kind of implicit conversion, and it needs to get dropped
9066 // and recomputed for the same general reasons that ImplicitCastExprs
9067 // do, as well a more specific one: this expression is only valid when
9068 // it appears *immediately* as an argument expression.
9069 return getDerived().TransformExpr(E->getSubExpr());
John McCall31168b02011-06-15 23:02:42 +00009070}
9071
9072template<typename Derived>
9073ExprResult TreeTransform<Derived>::
9074TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier1dcde962012-08-08 18:46:20 +00009075 TypeSourceInfo *TSInfo
John McCall31168b02011-06-15 23:02:42 +00009076 = getDerived().TransformType(E->getTypeInfoAsWritten());
9077 if (!TSInfo)
9078 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009079
John McCall31168b02011-06-15 23:02:42 +00009080 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier1dcde962012-08-08 18:46:20 +00009081 if (Result.isInvalid())
John McCall31168b02011-06-15 23:02:42 +00009082 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009083
John McCall31168b02011-06-15 23:02:42 +00009084 if (!getDerived().AlwaysRebuild() &&
9085 TSInfo == E->getTypeInfoAsWritten() &&
9086 Result.get() == E->getSubExpr())
9087 return SemaRef.Owned(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009088
John McCall31168b02011-06-15 23:02:42 +00009089 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier1dcde962012-08-08 18:46:20 +00009090 E->getBridgeKeywordLoc(), TSInfo,
John McCall31168b02011-06-15 23:02:42 +00009091 Result.get());
9092}
9093
9094template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009095ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009096TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009097 // Transform arguments.
9098 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009099 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +00009100 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +00009101 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009102 &ArgChanged))
9103 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009104
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009105 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
9106 // Class message: transform the receiver type.
9107 TypeSourceInfo *ReceiverTypeInfo
9108 = getDerived().TransformType(E->getClassReceiverTypeInfo());
9109 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009110 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009111
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009112 // If nothing changed, just retain the existing message send.
9113 if (!getDerived().AlwaysRebuild() &&
9114 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009115 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009116
9117 // Build a new class message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009118 SmallVector<SourceLocation, 16> SelLocs;
9119 E->getSelectorLocs(SelLocs);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009120 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
9121 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009122 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009123 E->getMethodDecl(),
9124 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009125 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009126 E->getRightLoc());
9127 }
9128
9129 // Instance message: transform the receiver
9130 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
9131 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +00009132 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009133 = getDerived().TransformExpr(E->getInstanceReceiver());
9134 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009135 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009136
9137 // If nothing changed, just retain the existing message send.
9138 if (!getDerived().AlwaysRebuild() &&
9139 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009140 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009141
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009142 // Build a new instance message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009143 SmallVector<SourceLocation, 16> SelLocs;
9144 E->getSelectorLocs(SelLocs);
John McCallb268a282010-08-23 23:25:46 +00009145 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009146 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009147 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009148 E->getMethodDecl(),
9149 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009150 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009151 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00009152}
9153
Mike Stump11289f42009-09-09 15:08:12 +00009154template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009155ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009156TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00009157 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009158}
9159
Mike Stump11289f42009-09-09 15:08:12 +00009160template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009161ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009162TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00009163 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009164}
9165
Mike Stump11289f42009-09-09 15:08:12 +00009166template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009167ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009168TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00009169 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00009170 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00009171 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009172 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +00009173
9174 // We don't need to transform the ivar; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +00009175
Douglas Gregord51d90d2010-04-26 20:11:03 +00009176 // If nothing changed, just retain the existing expression.
9177 if (!getDerived().AlwaysRebuild() &&
9178 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00009179 return SemaRef.Owned(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009180
John McCallb268a282010-08-23 23:25:46 +00009181 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00009182 E->getLocation(),
9183 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +00009184}
9185
Mike Stump11289f42009-09-09 15:08:12 +00009186template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009187ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009188TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +00009189 // 'super' and types never change. Property never changes. Just
9190 // retain the existing expression.
9191 if (!E->isObjectReceiver())
John McCallc3007a22010-10-26 07:05:15 +00009192 return SemaRef.Owned(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009193
Douglas Gregor9faee212010-04-26 20:47:02 +00009194 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00009195 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +00009196 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009197 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009198
Douglas Gregor9faee212010-04-26 20:47:02 +00009199 // We don't need to transform the property; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +00009200
Douglas Gregor9faee212010-04-26 20:47:02 +00009201 // If nothing changed, just retain the existing expression.
9202 if (!getDerived().AlwaysRebuild() &&
9203 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00009204 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009205
John McCallb7bd14f2010-12-02 01:19:52 +00009206 if (E->isExplicitProperty())
9207 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
9208 E->getExplicitProperty(),
9209 E->getLocation());
9210
9211 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall526ab472011-10-25 17:37:35 +00009212 SemaRef.Context.PseudoObjectTy,
John McCallb7bd14f2010-12-02 01:19:52 +00009213 E->getImplicitPropertyGetter(),
9214 E->getImplicitPropertySetter(),
9215 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00009216}
9217
Mike Stump11289f42009-09-09 15:08:12 +00009218template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009219ExprResult
Ted Kremeneke65b0862012-03-06 20:05:56 +00009220TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
9221 // Transform the base expression.
9222 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
9223 if (Base.isInvalid())
9224 return ExprError();
9225
9226 // Transform the key expression.
9227 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
9228 if (Key.isInvalid())
9229 return ExprError();
9230
9231 // If nothing changed, just retain the existing expression.
9232 if (!getDerived().AlwaysRebuild() &&
9233 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
9234 return SemaRef.Owned(E);
9235
Chad Rosier1dcde962012-08-08 18:46:20 +00009236 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremeneke65b0862012-03-06 20:05:56 +00009237 Base.get(), Key.get(),
9238 E->getAtIndexMethodDecl(),
9239 E->setAtIndexMethodDecl());
9240}
9241
9242template<typename Derived>
9243ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009244TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00009245 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00009246 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00009247 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009248 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009249
Douglas Gregord51d90d2010-04-26 20:11:03 +00009250 // If nothing changed, just retain the existing expression.
9251 if (!getDerived().AlwaysRebuild() &&
9252 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00009253 return SemaRef.Owned(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009254
John McCallb268a282010-08-23 23:25:46 +00009255 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00009256 E->getOpLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00009257 E->isArrow());
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>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009263 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009264 SmallVector<Expr*, 8> SubExprs;
Douglas Gregora3efea12011-01-03 19:04:46 +00009265 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier1dcde962012-08-08 18:46:20 +00009266 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00009267 SubExprs, &ArgumentChanged))
9268 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009269
Douglas Gregora16548e2009-08-11 05:31:07 +00009270 if (!getDerived().AlwaysRebuild() &&
9271 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00009272 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00009273
Douglas Gregora16548e2009-08-11 05:31:07 +00009274 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009275 SubExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00009276 E->getRParenLoc());
9277}
9278
Mike Stump11289f42009-09-09 15:08:12 +00009279template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009280ExprResult
Hal Finkelc4d7c822013-09-18 03:29:45 +00009281TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) {
9282 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
9283 if (SrcExpr.isInvalid())
9284 return ExprError();
9285
9286 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
9287 if (!Type)
9288 return ExprError();
9289
9290 if (!getDerived().AlwaysRebuild() &&
9291 Type == E->getTypeSourceInfo() &&
9292 SrcExpr.get() == E->getSrcExpr())
9293 return SemaRef.Owned(E);
9294
9295 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
9296 SrcExpr.get(), Type,
9297 E->getRParenLoc());
9298}
9299
9300template<typename Derived>
9301ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009302TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +00009303 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier1dcde962012-08-08 18:46:20 +00009304
John McCall490112f2011-02-04 18:33:18 +00009305 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
9306 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
9307
9308 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahaniandd5eb9d2011-12-03 17:47:53 +00009309 blockScope->TheDecl->setBlockMissingReturnType(
9310 oldBlock->blockMissingReturnType());
Chad Rosier1dcde962012-08-08 18:46:20 +00009311
Chris Lattner01cf8db2011-07-20 06:58:45 +00009312 SmallVector<ParmVarDecl*, 4> params;
9313 SmallVector<QualType, 4> paramTypes;
Chad Rosier1dcde962012-08-08 18:46:20 +00009314
Fariborz Jahanian1babe772010-07-09 18:44:02 +00009315 // Parameter substitution.
John McCall490112f2011-02-04 18:33:18 +00009316 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
9317 oldBlock->param_begin(),
9318 oldBlock->param_size(),
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +00009319 0, paramTypes, &params)) {
9320 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009321 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +00009322 }
John McCall490112f2011-02-04 18:33:18 +00009323
Jordan Rosea0a86be2013-03-08 22:25:36 +00009324 const FunctionProtoType *exprFunctionType = E->getFunctionType();
Eli Friedman34b49062012-01-26 03:00:14 +00009325 QualType exprResultType =
Alp Toker314cc812014-01-25 16:55:45 +00009326 getDerived().TransformType(exprFunctionType->getReturnType());
Douglas Gregor476e3022011-01-19 21:32:01 +00009327
Jordan Rose5c382722013-03-08 21:51:21 +00009328 QualType functionType =
9329 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +00009330 exprFunctionType->getExtProtoInfo());
John McCall490112f2011-02-04 18:33:18 +00009331 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +00009332
9333 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +00009334 if (!params.empty())
David Blaikie9c70e042011-09-21 18:16:56 +00009335 blockScope->TheDecl->setParams(params);
Eli Friedman34b49062012-01-26 03:00:14 +00009336
9337 if (!oldBlock->blockMissingReturnType()) {
9338 blockScope->HasImplicitReturnType = false;
9339 blockScope->ReturnType = exprResultType;
9340 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009341
John McCall3882ace2011-01-05 12:14:39 +00009342 // Transform the body
John McCall490112f2011-02-04 18:33:18 +00009343 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +00009344 if (body.isInvalid()) {
9345 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
John McCall3882ace2011-01-05 12:14:39 +00009346 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +00009347 }
John McCall3882ace2011-01-05 12:14:39 +00009348
John McCall490112f2011-02-04 18:33:18 +00009349#ifndef NDEBUG
9350 // In builds with assertions, make sure that we captured everything we
9351 // captured before.
Douglas Gregor4385d8b2011-05-20 15:32:55 +00009352 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
9353 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
9354 e = oldBlock->capture_end(); i != e; ++i) {
9355 VarDecl *oldCapture = i->getVariable();
John McCall490112f2011-02-04 18:33:18 +00009356
Douglas Gregor4385d8b2011-05-20 15:32:55 +00009357 // Ignore parameter packs.
9358 if (isa<ParmVarDecl>(oldCapture) &&
9359 cast<ParmVarDecl>(oldCapture)->isParameterPack())
9360 continue;
John McCall490112f2011-02-04 18:33:18 +00009361
Douglas Gregor4385d8b2011-05-20 15:32:55 +00009362 VarDecl *newCapture =
9363 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
9364 oldCapture));
9365 assert(blockScope->CaptureMap.count(newCapture));
9366 }
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00009367 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCall490112f2011-02-04 18:33:18 +00009368 }
9369#endif
9370
9371 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
9372 /*Scope=*/0);
Douglas Gregora16548e2009-08-11 05:31:07 +00009373}
9374
Mike Stump11289f42009-09-09 15:08:12 +00009375template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009376ExprResult
Tanya Lattner55808c12011-06-04 00:47:47 +00009377TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikie83d382b2011-09-23 05:06:16 +00009378 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner55808c12011-06-04 00:47:47 +00009379}
Eli Friedmandf14b3a2011-10-11 02:20:01 +00009380
9381template<typename Derived>
9382ExprResult
9383TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedman8d3e43f2011-10-14 22:48:56 +00009384 QualType RetTy = getDerived().TransformType(E->getType());
9385 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009386 SmallVector<Expr*, 8> SubExprs;
Eli Friedman8d3e43f2011-10-14 22:48:56 +00009387 SubExprs.reserve(E->getNumSubExprs());
9388 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
9389 SubExprs, &ArgumentChanged))
9390 return ExprError();
9391
9392 if (!getDerived().AlwaysRebuild() &&
9393 !ArgumentChanged)
9394 return SemaRef.Owned(E);
9395
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009396 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedman8d3e43f2011-10-14 22:48:56 +00009397 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedmandf14b3a2011-10-11 02:20:01 +00009398}
Chad Rosier1dcde962012-08-08 18:46:20 +00009399
Douglas Gregora16548e2009-08-11 05:31:07 +00009400//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00009401// Type reconstruction
9402//===----------------------------------------------------------------------===//
9403
Mike Stump11289f42009-09-09 15:08:12 +00009404template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00009405QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
9406 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00009407 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009408 getDerived().getBaseEntity());
9409}
9410
Mike Stump11289f42009-09-09 15:08:12 +00009411template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00009412QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
9413 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00009414 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009415 getDerived().getBaseEntity());
9416}
9417
Mike Stump11289f42009-09-09 15:08:12 +00009418template<typename Derived>
9419QualType
John McCall70dd5f62009-10-30 00:06:24 +00009420TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
9421 bool WrittenAsLValue,
9422 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00009423 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +00009424 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00009425}
9426
9427template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009428QualType
John McCall70dd5f62009-10-30 00:06:24 +00009429TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
9430 QualType ClassType,
9431 SourceLocation Sigil) {
Reid Kleckner0503a872013-12-05 01:23:43 +00009432 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil,
9433 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00009434}
9435
9436template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009437QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00009438TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
9439 ArrayType::ArraySizeModifier SizeMod,
9440 const llvm::APInt *Size,
9441 Expr *SizeExpr,
9442 unsigned IndexTypeQuals,
9443 SourceRange BracketsRange) {
9444 if (SizeExpr || !Size)
9445 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
9446 IndexTypeQuals, BracketsRange,
9447 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00009448
9449 QualType Types[] = {
9450 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
9451 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
9452 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00009453 };
Craig Toppere5ce8312013-07-15 03:38:40 +00009454 const unsigned NumTypes = llvm::array_lengthof(Types);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009455 QualType SizeType;
9456 for (unsigned I = 0; I != NumTypes; ++I)
9457 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
9458 SizeType = Types[I];
9459 break;
9460 }
Mike Stump11289f42009-09-09 15:08:12 +00009461
Eli Friedman9562f392012-01-25 23:20:27 +00009462 // Note that we can return a VariableArrayType here in the case where
9463 // the element type was a dependent VariableArrayType.
9464 IntegerLiteral *ArraySize
9465 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
9466 /*FIXME*/BracketsRange.getBegin());
9467 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009468 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00009469 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00009470}
Mike Stump11289f42009-09-09 15:08:12 +00009471
Douglas Gregord6ff3322009-08-04 16:50:30 +00009472template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009473QualType
9474TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009475 ArrayType::ArraySizeModifier SizeMod,
9476 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00009477 unsigned IndexTypeQuals,
9478 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00009479 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00009480 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009481}
9482
9483template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009484QualType
Mike Stump11289f42009-09-09 15:08:12 +00009485TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009486 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00009487 unsigned IndexTypeQuals,
9488 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00009489 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00009490 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009491}
Mike Stump11289f42009-09-09 15:08:12 +00009492
Douglas Gregord6ff3322009-08-04 16:50:30 +00009493template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009494QualType
9495TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009496 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00009497 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009498 unsigned IndexTypeQuals,
9499 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00009500 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00009501 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009502 IndexTypeQuals, BracketsRange);
9503}
9504
9505template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009506QualType
9507TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009508 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00009509 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009510 unsigned IndexTypeQuals,
9511 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00009512 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00009513 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009514 IndexTypeQuals, BracketsRange);
9515}
9516
9517template<typename Derived>
9518QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +00009519 unsigned NumElements,
9520 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00009521 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +00009522 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009523}
Mike Stump11289f42009-09-09 15:08:12 +00009524
Douglas Gregord6ff3322009-08-04 16:50:30 +00009525template<typename Derived>
9526QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
9527 unsigned NumElements,
9528 SourceLocation AttributeLoc) {
9529 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
9530 NumElements, true);
9531 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00009532 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
9533 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +00009534 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009535}
Mike Stump11289f42009-09-09 15:08:12 +00009536
Douglas Gregord6ff3322009-08-04 16:50:30 +00009537template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009538QualType
9539TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +00009540 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009541 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +00009542 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009543}
Mike Stump11289f42009-09-09 15:08:12 +00009544
Douglas Gregord6ff3322009-08-04 16:50:30 +00009545template<typename Derived>
Jordan Rose5c382722013-03-08 21:51:21 +00009546QualType TreeTransform<Derived>::RebuildFunctionProtoType(
9547 QualType T,
9548 llvm::MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +00009549 const FunctionProtoType::ExtProtoInfo &EPI) {
9550 return SemaRef.BuildFunctionType(T, ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009551 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +00009552 getDerived().getBaseEntity(),
Jordan Rosea0a86be2013-03-08 22:25:36 +00009553 EPI);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009554}
Mike Stump11289f42009-09-09 15:08:12 +00009555
Douglas Gregord6ff3322009-08-04 16:50:30 +00009556template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00009557QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
9558 return SemaRef.Context.getFunctionNoProtoType(T);
9559}
9560
9561template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00009562QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
9563 assert(D && "no decl found");
9564 if (D->isInvalidDecl()) return QualType();
9565
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009566 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +00009567 TypeDecl *Ty;
9568 if (isa<UsingDecl>(D)) {
9569 UsingDecl *Using = cast<UsingDecl>(D);
Enea Zaffanellae05a3cf2013-07-22 10:54:09 +00009570 assert(Using->hasTypename() &&
John McCallb96ec562009-12-04 22:46:56 +00009571 "UnresolvedUsingTypenameDecl transformed to non-typename using");
9572
9573 // A valid resolved using typename decl points to exactly one type decl.
9574 assert(++Using->shadow_begin() == Using->shadow_end());
9575 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +00009576
John McCallb96ec562009-12-04 22:46:56 +00009577 } else {
9578 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
9579 "UnresolvedUsingTypenameDecl transformed to non-using decl");
9580 Ty = cast<UnresolvedUsingTypenameDecl>(D);
9581 }
9582
9583 return SemaRef.Context.getTypeDeclType(Ty);
9584}
9585
9586template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00009587QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
9588 SourceLocation Loc) {
9589 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009590}
9591
9592template<typename Derived>
9593QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
9594 return SemaRef.Context.getTypeOfType(Underlying);
9595}
9596
9597template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00009598QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
9599 SourceLocation Loc) {
9600 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009601}
9602
9603template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00009604QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
9605 UnaryTransformType::UTTKind UKind,
9606 SourceLocation Loc) {
9607 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
9608}
9609
9610template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00009611QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00009612 TemplateName Template,
9613 SourceLocation TemplateNameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +00009614 TemplateArgumentListInfo &TemplateArgs) {
John McCall6b51f282009-11-23 01:53:49 +00009615 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009616}
Mike Stump11289f42009-09-09 15:08:12 +00009617
Douglas Gregor1135c352009-08-06 05:28:30 +00009618template<typename Derived>
Eli Friedman0dfb8892011-10-06 23:00:33 +00009619QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
9620 SourceLocation KWLoc) {
9621 return SemaRef.BuildAtomicType(ValueType, KWLoc);
9622}
9623
9624template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009625TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00009626TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +00009627 bool TemplateKW,
9628 TemplateDecl *Template) {
Douglas Gregor9db53502011-03-02 18:07:45 +00009629 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00009630 Template);
9631}
9632
9633template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009634TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00009635TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
9636 const IdentifierInfo &Name,
9637 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +00009638 QualType ObjectType,
9639 NamedDecl *FirstQualifierInScope) {
Douglas Gregor9db53502011-03-02 18:07:45 +00009640 UnqualifiedId TemplateName;
9641 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregorbb119652010-06-16 23:00:59 +00009642 Sema::TemplateTy Template;
Abramo Bagnara7945c982012-01-27 09:46:47 +00009643 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregorbb119652010-06-16 23:00:59 +00009644 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009645 SS, TemplateKWLoc, TemplateName,
John McCallba7bf592010-08-24 05:47:05 +00009646 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00009647 /*EnteringContext=*/false,
9648 Template);
John McCall31f82722010-11-12 08:19:04 +00009649 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +00009650}
Mike Stump11289f42009-09-09 15:08:12 +00009651
Douglas Gregora16548e2009-08-11 05:31:07 +00009652template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00009653TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00009654TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +00009655 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +00009656 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +00009657 QualType ObjectType) {
Douglas Gregor71395fa2009-11-04 00:56:37 +00009658 UnqualifiedId Name;
Douglas Gregor9db53502011-03-02 18:07:45 +00009659 // FIXME: Bogus location information.
Abramo Bagnara7945c982012-01-27 09:46:47 +00009660 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregor9db53502011-03-02 18:07:45 +00009661 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnara7945c982012-01-27 09:46:47 +00009662 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregorbb119652010-06-16 23:00:59 +00009663 Sema::TemplateTy Template;
9664 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009665 SS, TemplateKWLoc, Name,
John McCallba7bf592010-08-24 05:47:05 +00009666 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00009667 /*EnteringContext=*/false,
9668 Template);
Serge Pavlov9ddb76e2013-08-27 13:15:56 +00009669 return Template.get();
Douglas Gregor71395fa2009-11-04 00:56:37 +00009670}
Chad Rosier1dcde962012-08-08 18:46:20 +00009671
Douglas Gregor71395fa2009-11-04 00:56:37 +00009672template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009673ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009674TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
9675 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00009676 Expr *OrigCallee,
9677 Expr *First,
9678 Expr *Second) {
9679 Expr *Callee = OrigCallee->IgnoreParenCasts();
9680 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00009681
Douglas Gregora16548e2009-08-11 05:31:07 +00009682 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00009683 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +00009684 if (!First->getType()->isOverloadableType() &&
9685 !Second->getType()->isOverloadableType())
9686 return getSema().CreateBuiltinArraySubscriptExpr(First,
9687 Callee->getLocStart(),
9688 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00009689 } else if (Op == OO_Arrow) {
9690 // -> is never a builtin operation.
John McCallb268a282010-08-23 23:25:46 +00009691 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
9692 } else if (Second == 0 || isPostIncDec) {
9693 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009694 // The argument is not of overloadable type, so try to create a
9695 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +00009696 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00009697 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00009698
John McCallb268a282010-08-23 23:25:46 +00009699 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00009700 }
9701 } else {
John McCallb268a282010-08-23 23:25:46 +00009702 if (!First->getType()->isOverloadableType() &&
9703 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009704 // Neither of the arguments is an overloadable type, so try to
9705 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +00009706 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00009707 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00009708 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +00009709 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009710 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009711
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009712 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00009713 }
9714 }
Mike Stump11289f42009-09-09 15:08:12 +00009715
9716 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00009717 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00009718 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00009719
John McCallb268a282010-08-23 23:25:46 +00009720 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +00009721 assert(ULE->requiresADL());
9722
9723 // FIXME: Do we have to check
9724 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall4c4c1df2010-01-26 03:27:55 +00009725 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00009726 } else {
Richard Smith58db83d2012-11-28 21:47:39 +00009727 // If we've resolved this to a particular non-member function, just call
9728 // that function. If we resolved it to a member function,
9729 // CreateOverloaded* will find that function for us.
9730 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
9731 if (!isa<CXXMethodDecl>(ND))
9732 Functions.addDecl(ND);
John McCalld14a8642009-11-21 08:51:07 +00009733 }
Mike Stump11289f42009-09-09 15:08:12 +00009734
Douglas Gregora16548e2009-08-11 05:31:07 +00009735 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +00009736 Expr *Args[2] = { First, Second };
9737 unsigned NumArgs = 1 + (Second != 0);
Mike Stump11289f42009-09-09 15:08:12 +00009738
Douglas Gregora16548e2009-08-11 05:31:07 +00009739 // Create the overloaded operator invocation for unary operators.
9740 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +00009741 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00009742 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +00009743 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00009744 }
Mike Stump11289f42009-09-09 15:08:12 +00009745
Douglas Gregore9d62932011-07-15 16:25:15 +00009746 if (Op == OO_Subscript) {
9747 SourceLocation LBrace;
9748 SourceLocation RBrace;
9749
9750 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
9751 DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
9752 LBrace = SourceLocation::getFromRawEncoding(
9753 NameLoc.CXXOperatorName.BeginOpNameLoc);
9754 RBrace = SourceLocation::getFromRawEncoding(
9755 NameLoc.CXXOperatorName.EndOpNameLoc);
9756 } else {
9757 LBrace = Callee->getLocStart();
9758 RBrace = OpLoc;
9759 }
9760
9761 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
9762 First, Second);
9763 }
Sebastian Redladba46e2009-10-29 20:17:01 +00009764
Douglas Gregora16548e2009-08-11 05:31:07 +00009765 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +00009766 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00009767 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00009768 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
9769 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009770 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009771
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009772 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00009773}
Mike Stump11289f42009-09-09 15:08:12 +00009774
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009775template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00009776ExprResult
John McCallb268a282010-08-23 23:25:46 +00009777TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009778 SourceLocation OperatorLoc,
9779 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +00009780 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009781 TypeSourceInfo *ScopeType,
9782 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00009783 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00009784 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +00009785 QualType BaseType = Base->getType();
9786 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009787 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier1dcde962012-08-08 18:46:20 +00009788 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +00009789 !BaseType->getAs<PointerType>()->getPointeeType()
9790 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009791 // This pseudo-destructor expression is still a pseudo-destructor.
John McCallb268a282010-08-23 23:25:46 +00009792 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009793 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00009794 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00009795 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009796 /*FIXME?*/true);
9797 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009798
Douglas Gregor678f90d2010-02-25 01:56:36 +00009799 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009800 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
9801 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
9802 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
9803 NameInfo.setNamedTypeInfo(DestroyedType);
9804
Richard Smith8e4a3862012-05-15 06:15:11 +00009805 // The scope type is now known to be a valid nested name specifier
9806 // component. Tack it on to the end of the nested name specifier.
9807 if (ScopeType)
9808 SS.Extend(SemaRef.Context, SourceLocation(),
9809 ScopeType->getTypeLoc(), CCLoc);
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009810
Abramo Bagnara7945c982012-01-27 09:46:47 +00009811 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCallb268a282010-08-23 23:25:46 +00009812 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009813 OperatorLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009814 SS, TemplateKWLoc,
9815 /*FIXME: FirstQualifier*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009816 NameInfo,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009817 /*TemplateArgs*/ 0);
9818}
9819
Tareq A. Siraj24110cc2013-04-16 18:53:08 +00009820template<typename Derived>
9821StmtResult
9822TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
Wei Pan17fbf6e2013-05-04 03:59:06 +00009823 SourceLocation Loc = S->getLocStart();
9824 unsigned NumParams = S->getCapturedDecl()->getNumParams();
9825 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/0,
9826 S->getCapturedRegionKind(), NumParams);
9827 StmtResult Body = getDerived().TransformStmt(S->getCapturedStmt());
9828
9829 if (Body.isInvalid()) {
9830 getSema().ActOnCapturedRegionError();
9831 return StmtError();
9832 }
9833
9834 return getSema().ActOnCapturedRegionEnd(Body.take());
Tareq A. Siraj24110cc2013-04-16 18:53:08 +00009835}
9836
Douglas Gregord6ff3322009-08-04 16:50:30 +00009837} // end namespace clang
9838
9839#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H