blob: 5000d280981a3e2663d0834fe072a760d8b869cd [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:
Nick Lewycky0c438082011-01-24 19:01:04 +0000955 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
Stephan Tolksdorfeb7708d2014-03-13 20:34:03 +0000956 << Kind << Id << DC << QualifierLoc.getSourceRange();
Nick Lewycky0c438082011-01-24 19:01:04 +0000957 break;
958 }
Douglas Gregore677daf2010-03-31 22:19:08 +0000959 return QualType();
960 }
Abramo Bagnara6150c882010-05-11 21:36:43 +0000961
Richard Trieucaa33d32011-06-10 03:11:26 +0000962 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
963 IdLoc, *Id)) {
Abramo Bagnarad7548482010-05-19 21:37:53 +0000964 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregore677daf2010-03-31 22:19:08 +0000965 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
966 return QualType();
967 }
968
969 // Build the elaborated-type-specifier type.
970 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Chad Rosier1dcde962012-08-08 18:46:20 +0000971 return SemaRef.Context.getElaboratedType(Keyword,
972 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000973 T);
Douglas Gregor1135c352009-08-06 05:28:30 +0000974 }
Mike Stump11289f42009-09-09 15:08:12 +0000975
Douglas Gregor822d0302011-01-12 17:07:58 +0000976 /// \brief Build a new pack expansion type.
977 ///
978 /// By default, builds a new PackExpansionType type from the given pattern.
979 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000980 QualType RebuildPackExpansionType(QualType Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +0000981 SourceRange PatternRange,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000982 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +0000983 Optional<unsigned> NumExpansions) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000984 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
985 NumExpansions);
Douglas Gregor822d0302011-01-12 17:07:58 +0000986 }
987
Eli Friedman0dfb8892011-10-06 23:00:33 +0000988 /// \brief Build a new atomic type given its value type.
989 ///
990 /// By default, performs semantic analysis when building the atomic type.
991 /// Subclasses may override this routine to provide different behavior.
992 QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
993
Douglas Gregor71dc5092009-08-06 06:41:21 +0000994 /// \brief Build a new template name given a nested name specifier, a flag
995 /// indicating whether the "template" keyword was provided, and the template
996 /// that the template name refers to.
997 ///
998 /// By default, builds the new template name directly. Subclasses may override
999 /// this routine to provide different behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001000 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +00001001 bool TemplateKW,
1002 TemplateDecl *Template);
1003
Douglas Gregor71dc5092009-08-06 06:41:21 +00001004 /// \brief Build a new template name given a nested name specifier and the
1005 /// name that is referred to as a template.
1006 ///
1007 /// By default, performs semantic analysis to determine whether the name can
1008 /// be resolved to a specific template, then builds the appropriate kind of
1009 /// template name. Subclasses may override this routine to provide different
1010 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001011 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
1012 const IdentifierInfo &Name,
1013 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +00001014 QualType ObjectType,
1015 NamedDecl *FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00001016
Douglas Gregor71395fa2009-11-04 00:56:37 +00001017 /// \brief Build a new template name given a nested name specifier and the
1018 /// overloaded operator name that is referred to as a template.
1019 ///
1020 /// By default, performs semantic analysis to determine whether the name can
1021 /// be resolved to a specific template, then builds the appropriate kind of
1022 /// template name. Subclasses may override this routine to provide different
1023 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001024 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +00001025 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +00001026 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +00001027 QualType ObjectType);
Douglas Gregor5590be02011-01-15 06:45:20 +00001028
1029 /// \brief Build a new template name given a template template parameter pack
Chad Rosier1dcde962012-08-08 18:46:20 +00001030 /// and the
Douglas Gregor5590be02011-01-15 06:45:20 +00001031 ///
1032 /// By default, performs semantic analysis to determine whether the name can
1033 /// be resolved to a specific template, then builds the appropriate kind of
1034 /// template name. Subclasses may override this routine to provide different
1035 /// behavior.
1036 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
1037 const TemplateArgument &ArgPack) {
1038 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
1039 }
1040
Douglas Gregorebe10102009-08-20 07:17:43 +00001041 /// \brief Build a new compound statement.
1042 ///
1043 /// By default, performs semantic analysis to build the new statement.
1044 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001045 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001046 MultiStmtArg Statements,
1047 SourceLocation RBraceLoc,
1048 bool IsStmtExpr) {
John McCallb268a282010-08-23 23:25:46 +00001049 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00001050 IsStmtExpr);
1051 }
1052
1053 /// \brief Build a new case statement.
1054 ///
1055 /// By default, performs semantic analysis to build the new statement.
1056 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001057 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCallb268a282010-08-23 23:25:46 +00001058 Expr *LHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001059 SourceLocation EllipsisLoc,
John McCallb268a282010-08-23 23:25:46 +00001060 Expr *RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001061 SourceLocation ColonLoc) {
John McCallb268a282010-08-23 23:25:46 +00001062 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001063 ColonLoc);
1064 }
Mike Stump11289f42009-09-09 15:08:12 +00001065
Douglas Gregorebe10102009-08-20 07:17:43 +00001066 /// \brief Attach the body to a new case statement.
1067 ///
1068 /// By default, performs semantic analysis to build the new statement.
1069 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001070 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001071 getSema().ActOnCaseStmtBody(S, Body);
1072 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00001073 }
Mike Stump11289f42009-09-09 15:08:12 +00001074
Douglas Gregorebe10102009-08-20 07:17:43 +00001075 /// \brief Build a new default statement.
1076 ///
1077 /// By default, performs semantic analysis to build the new statement.
1078 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001079 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001080 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +00001081 Stmt *SubStmt) {
1082 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregorebe10102009-08-20 07:17:43 +00001083 /*CurScope=*/0);
1084 }
Mike Stump11289f42009-09-09 15:08:12 +00001085
Douglas Gregorebe10102009-08-20 07:17:43 +00001086 /// \brief Build a new label statement.
1087 ///
1088 /// By default, performs semantic analysis to build the new statement.
1089 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001090 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1091 SourceLocation ColonLoc, Stmt *SubStmt) {
1092 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregorebe10102009-08-20 07:17:43 +00001093 }
Mike Stump11289f42009-09-09 15:08:12 +00001094
Richard Smithc202b282012-04-14 00:33:13 +00001095 /// \brief Build a new label statement.
1096 ///
1097 /// By default, performs semantic analysis to build the new statement.
1098 /// Subclasses may override this routine to provide different behavior.
Alexander Kornienko20f6fc62012-07-09 10:04:07 +00001099 StmtResult RebuildAttributedStmt(SourceLocation AttrLoc,
1100 ArrayRef<const Attr*> Attrs,
Richard Smithc202b282012-04-14 00:33:13 +00001101 Stmt *SubStmt) {
1102 return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt);
1103 }
1104
Douglas Gregorebe10102009-08-20 07:17:43 +00001105 /// \brief Build a new "if" statement.
1106 ///
1107 /// By default, performs semantic analysis to build the new statement.
1108 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001109 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Chad Rosier1dcde962012-08-08 18:46:20 +00001110 VarDecl *CondVar, Stmt *Then,
Chris Lattnercab02a62011-02-17 20:34:02 +00001111 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00001112 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregorebe10102009-08-20 07:17:43 +00001113 }
Mike Stump11289f42009-09-09 15:08:12 +00001114
Douglas Gregorebe10102009-08-20 07:17:43 +00001115 /// \brief Start building a new switch statement.
1116 ///
1117 /// By default, performs semantic analysis to build the new statement.
1118 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001119 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001120 Expr *Cond, VarDecl *CondVar) {
Chad Rosier1dcde962012-08-08 18:46:20 +00001121 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCall48871652010-08-21 09:40:31 +00001122 CondVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00001123 }
Mike Stump11289f42009-09-09 15:08:12 +00001124
Douglas Gregorebe10102009-08-20 07:17:43 +00001125 /// \brief Attach the body to the switch statement.
1126 ///
1127 /// By default, performs semantic analysis to build the new statement.
1128 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001129 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001130 Stmt *Switch, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001131 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001132 }
1133
1134 /// \brief Build a new while statement.
1135 ///
1136 /// By default, performs semantic analysis to build the new statement.
1137 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001138 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1139 VarDecl *CondVar, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001140 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001141 }
Mike Stump11289f42009-09-09 15:08:12 +00001142
Douglas Gregorebe10102009-08-20 07:17:43 +00001143 /// \brief Build a new do-while statement.
1144 ///
1145 /// By default, performs semantic analysis to build the new statement.
1146 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001147 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001148 SourceLocation WhileLoc, SourceLocation LParenLoc,
1149 Expr *Cond, SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001150 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1151 Cond, RParenLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001152 }
1153
1154 /// \brief Build a new for statement.
1155 ///
1156 /// By default, performs semantic analysis to build the new statement.
1157 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001158 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
Chad Rosier1dcde962012-08-08 18:46:20 +00001159 Stmt *Init, Sema::FullExprArg Cond,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001160 VarDecl *CondVar, Sema::FullExprArg Inc,
1161 SourceLocation RParenLoc, Stmt *Body) {
Chad Rosier1dcde962012-08-08 18:46:20 +00001162 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001163 CondVar, Inc, RParenLoc, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001164 }
Mike Stump11289f42009-09-09 15:08:12 +00001165
Douglas Gregorebe10102009-08-20 07:17:43 +00001166 /// \brief Build a new goto statement.
1167 ///
1168 /// By default, performs semantic analysis to build the new statement.
1169 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001170 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1171 LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001172 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregorebe10102009-08-20 07:17:43 +00001173 }
1174
1175 /// \brief Build a new indirect goto statement.
1176 ///
1177 /// By default, performs semantic analysis to build the new statement.
1178 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001179 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001180 SourceLocation StarLoc,
1181 Expr *Target) {
John McCallb268a282010-08-23 23:25:46 +00001182 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregorebe10102009-08-20 07:17:43 +00001183 }
Mike Stump11289f42009-09-09 15:08:12 +00001184
Douglas Gregorebe10102009-08-20 07:17:43 +00001185 /// \brief Build a new return statement.
1186 ///
1187 /// By default, performs semantic analysis to build the new statement.
1188 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001189 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
John McCallb268a282010-08-23 23:25:46 +00001190 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregorebe10102009-08-20 07:17:43 +00001191 }
Mike Stump11289f42009-09-09 15:08:12 +00001192
Douglas Gregorebe10102009-08-20 07:17:43 +00001193 /// \brief Build a new declaration statement.
1194 ///
1195 /// By default, performs semantic analysis to build the new statement.
1196 /// Subclasses may override this routine to provide different behavior.
Rafael Espindolaab417692013-07-09 12:05:01 +00001197 StmtResult RebuildDeclStmt(llvm::MutableArrayRef<Decl *> Decls,
1198 SourceLocation StartLoc, SourceLocation EndLoc) {
1199 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls);
Richard Smith2abf6762011-02-23 00:37:57 +00001200 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001201 }
Mike Stump11289f42009-09-09 15:08:12 +00001202
Anders Carlssonaaeef072010-01-24 05:50:09 +00001203 /// \brief Build a new inline asm statement.
1204 ///
1205 /// By default, performs semantic analysis to build the new statement.
1206 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001207 StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
1208 bool IsVolatile, unsigned NumOutputs,
1209 unsigned NumInputs, IdentifierInfo **Names,
1210 MultiExprArg Constraints, MultiExprArg Exprs,
1211 Expr *AsmString, MultiExprArg Clobbers,
1212 SourceLocation RParenLoc) {
1213 return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1214 NumInputs, Names, Constraints, Exprs,
1215 AsmString, Clobbers, RParenLoc);
Anders Carlssonaaeef072010-01-24 05:50:09 +00001216 }
Douglas Gregor306de2f2010-04-22 23:59:56 +00001217
Chad Rosier32503022012-06-11 20:47:18 +00001218 /// \brief Build a new MS style inline asm statement.
1219 ///
1220 /// By default, performs semantic analysis to build the new statement.
1221 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001222 StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc,
John McCallf413f5e2013-05-03 00:10:13 +00001223 ArrayRef<Token> AsmToks,
1224 StringRef AsmString,
1225 unsigned NumOutputs, unsigned NumInputs,
1226 ArrayRef<StringRef> Constraints,
1227 ArrayRef<StringRef> Clobbers,
1228 ArrayRef<Expr*> Exprs,
1229 SourceLocation EndLoc) {
1230 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString,
1231 NumOutputs, NumInputs,
1232 Constraints, Clobbers, Exprs, EndLoc);
Chad Rosier32503022012-06-11 20:47:18 +00001233 }
1234
James Dennett2a4d13c2012-06-15 07:13:21 +00001235 /// \brief Build a new Objective-C \@try statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001236 ///
1237 /// By default, performs semantic analysis to build the new statement.
1238 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001239 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001240 Stmt *TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +00001241 MultiStmtArg CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001242 Stmt *Finally) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001243 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001244 Finally);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001245 }
1246
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001247 /// \brief Rebuild an Objective-C exception declaration.
1248 ///
1249 /// By default, performs semantic analysis to build the new declaration.
1250 /// Subclasses may override this routine to provide different behavior.
1251 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1252 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaradff19302011-03-08 08:55:46 +00001253 return getSema().BuildObjCExceptionDecl(TInfo, T,
1254 ExceptionDecl->getInnerLocStart(),
1255 ExceptionDecl->getLocation(),
1256 ExceptionDecl->getIdentifier());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001257 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001258
James Dennett2a4d13c2012-06-15 07:13:21 +00001259 /// \brief Build a new Objective-C \@catch statement.
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001260 ///
1261 /// By default, performs semantic analysis to build the new statement.
1262 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001263 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001264 SourceLocation RParenLoc,
1265 VarDecl *Var,
John McCallb268a282010-08-23 23:25:46 +00001266 Stmt *Body) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001267 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001268 Var, Body);
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001269 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001270
James Dennett2a4d13c2012-06-15 07:13:21 +00001271 /// \brief Build a new Objective-C \@finally statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001272 ///
1273 /// By default, performs semantic analysis to build the new statement.
1274 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001275 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001276 Stmt *Body) {
1277 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001278 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001279
James Dennett2a4d13c2012-06-15 07:13:21 +00001280 /// \brief Build a new Objective-C \@throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +00001281 ///
1282 /// By default, performs semantic analysis to build the new statement.
1283 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001284 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001285 Expr *Operand) {
1286 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregor2900c162010-04-22 21:44:01 +00001287 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001288
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001289 /// \brief Build a new OpenMP executable directive.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001290 ///
1291 /// By default, performs semantic analysis to build the new statement.
1292 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001293 StmtResult RebuildOMPExecutableDirective(OpenMPDirectiveKind Kind,
1294 ArrayRef<OMPClause *> Clauses,
1295 Stmt *AStmt,
1296 SourceLocation StartLoc,
1297 SourceLocation EndLoc) {
1298 return getSema().ActOnOpenMPExecutableDirective(Kind, Clauses, AStmt,
1299 StartLoc, EndLoc);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001300 }
1301
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001302 /// \brief Build a new OpenMP 'if' clause.
1303 ///
1304 /// By default, performs semantic analysis to build the new statement.
1305 /// Subclasses may override this routine to provide different behavior.
1306 OMPClause *RebuildOMPIfClause(Expr *Condition,
1307 SourceLocation StartLoc,
1308 SourceLocation LParenLoc,
1309 SourceLocation EndLoc) {
1310 return getSema().ActOnOpenMPIfClause(Condition, StartLoc,
1311 LParenLoc, EndLoc);
1312 }
1313
Alexey Bataev568a8332014-03-06 06:15:19 +00001314 /// \brief Build a new OpenMP 'num_threads' clause.
1315 ///
1316 /// By default, performs semantic analysis to build the new statement.
1317 /// Subclasses may override this routine to provide different behavior.
1318 OMPClause *RebuildOMPNumThreadsClause(Expr *NumThreads,
1319 SourceLocation StartLoc,
1320 SourceLocation LParenLoc,
1321 SourceLocation EndLoc) {
1322 return getSema().ActOnOpenMPNumThreadsClause(NumThreads, StartLoc,
1323 LParenLoc, EndLoc);
1324 }
1325
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001326 /// \brief Build a new OpenMP 'default' clause.
1327 ///
1328 /// By default, performs semantic analysis to build the new statement.
1329 /// Subclasses may override this routine to provide different behavior.
1330 OMPClause *RebuildOMPDefaultClause(OpenMPDefaultClauseKind Kind,
1331 SourceLocation KindKwLoc,
1332 SourceLocation StartLoc,
1333 SourceLocation LParenLoc,
1334 SourceLocation EndLoc) {
1335 return getSema().ActOnOpenMPDefaultClause(Kind, KindKwLoc,
1336 StartLoc, LParenLoc, EndLoc);
1337 }
1338
1339 /// \brief Build a new OpenMP 'private' clause.
1340 ///
1341 /// By default, performs semantic analysis to build the new statement.
1342 /// Subclasses may override this routine to provide different behavior.
1343 OMPClause *RebuildOMPPrivateClause(ArrayRef<Expr *> VarList,
1344 SourceLocation StartLoc,
1345 SourceLocation LParenLoc,
1346 SourceLocation EndLoc) {
1347 return getSema().ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc,
1348 EndLoc);
1349 }
1350
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001351 /// \brief Build a new OpenMP 'firstprivate' clause.
1352 ///
1353 /// By default, performs semantic analysis to build the new statement.
1354 /// Subclasses may override this routine to provide different behavior.
1355 OMPClause *RebuildOMPFirstprivateClause(ArrayRef<Expr *> VarList,
1356 SourceLocation StartLoc,
1357 SourceLocation LParenLoc,
1358 SourceLocation EndLoc) {
1359 return getSema().ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc,
1360 EndLoc);
1361 }
1362
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001363 /// \brief Build a new OpenMP 'shared' clause.
1364 ///
1365 /// By default, performs semantic analysis to build the new statement.
1366 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev758e55e2013-09-06 18:03:48 +00001367 OMPClause *RebuildOMPSharedClause(ArrayRef<Expr *> VarList,
1368 SourceLocation StartLoc,
1369 SourceLocation LParenLoc,
1370 SourceLocation EndLoc) {
1371 return getSema().ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc,
1372 EndLoc);
1373 }
1374
James Dennett2a4d13c2012-06-15 07:13:21 +00001375 /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
John McCalld9bb7432011-07-27 21:50:02 +00001376 ///
1377 /// By default, performs semantic analysis to build the new statement.
1378 /// Subclasses may override this routine to provide different behavior.
1379 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1380 Expr *object) {
1381 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1382 }
1383
James Dennett2a4d13c2012-06-15 07:13:21 +00001384 /// \brief Build a new Objective-C \@synchronized statement.
Douglas Gregor6148de72010-04-22 22:01:21 +00001385 ///
Douglas Gregor6148de72010-04-22 22:01:21 +00001386 /// By default, performs semantic analysis to build the new statement.
1387 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001388 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCalld9bb7432011-07-27 21:50:02 +00001389 Expr *Object, Stmt *Body) {
1390 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor6148de72010-04-22 22:01:21 +00001391 }
Douglas Gregorf68a5082010-04-22 23:10:45 +00001392
James Dennett2a4d13c2012-06-15 07:13:21 +00001393 /// \brief Build a new Objective-C \@autoreleasepool statement.
John McCall31168b02011-06-15 23:02:42 +00001394 ///
1395 /// By default, performs semantic analysis to build the new statement.
1396 /// Subclasses may override this routine to provide different behavior.
1397 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1398 Stmt *Body) {
1399 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1400 }
John McCall53848232011-07-27 01:07:15 +00001401
Douglas Gregorf68a5082010-04-22 23:10:45 +00001402 /// \brief Build a new Objective-C fast enumeration statement.
1403 ///
1404 /// By default, performs semantic analysis to build the new statement.
1405 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001406 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001407 Stmt *Element,
1408 Expr *Collection,
1409 SourceLocation RParenLoc,
1410 Stmt *Body) {
Sam Panzer2c4ca0f2012-08-16 21:47:25 +00001411 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001412 Element,
John McCallb268a282010-08-23 23:25:46 +00001413 Collection,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001414 RParenLoc);
1415 if (ForEachStmt.isInvalid())
1416 return StmtError();
1417
1418 return getSema().FinishObjCForCollectionStmt(ForEachStmt.take(), Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +00001419 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001420
Douglas Gregorebe10102009-08-20 07:17:43 +00001421 /// \brief Build a new C++ exception declaration.
1422 ///
1423 /// By default, performs semantic analysis to build the new decaration.
1424 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaradff19302011-03-08 08:55:46 +00001425 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +00001426 TypeSourceInfo *Declarator,
Abramo Bagnaradff19302011-03-08 08:55:46 +00001427 SourceLocation StartLoc,
1428 SourceLocation IdLoc,
1429 IdentifierInfo *Id) {
Douglas Gregor40965fa2011-04-14 22:32:28 +00001430 VarDecl *Var = getSema().BuildExceptionDeclaration(0, Declarator,
1431 StartLoc, IdLoc, Id);
1432 if (Var)
1433 getSema().CurContext->addDecl(Var);
1434 return Var;
Douglas Gregorebe10102009-08-20 07:17:43 +00001435 }
1436
1437 /// \brief Build a new C++ catch statement.
1438 ///
1439 /// By default, performs semantic analysis to build the new statement.
1440 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001441 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001442 VarDecl *ExceptionDecl,
1443 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00001444 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1445 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00001446 }
Mike Stump11289f42009-09-09 15:08:12 +00001447
Douglas Gregorebe10102009-08-20 07:17:43 +00001448 /// \brief Build a new C++ try statement.
1449 ///
1450 /// By default, performs semantic analysis to build the new statement.
1451 /// Subclasses may override this routine to provide different behavior.
Robert Wilhelmcafda822013-08-22 09:20:03 +00001452 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock,
1453 ArrayRef<Stmt *> Handlers) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001454 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00001455 }
Mike Stump11289f42009-09-09 15:08:12 +00001456
Richard Smith02e85f32011-04-14 22:09:26 +00001457 /// \brief Build a new C++0x range-based for statement.
1458 ///
1459 /// By default, performs semantic analysis to build the new statement.
1460 /// Subclasses may override this routine to provide different behavior.
1461 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1462 SourceLocation ColonLoc,
1463 Stmt *Range, Stmt *BeginEnd,
1464 Expr *Cond, Expr *Inc,
1465 Stmt *LoopVar,
1466 SourceLocation RParenLoc) {
Douglas Gregorf7106af2013-04-08 18:40:13 +00001467 // If we've just learned that the range is actually an Objective-C
1468 // collection, treat this as an Objective-C fast enumeration loop.
1469 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
1470 if (RangeStmt->isSingleDecl()) {
1471 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
Douglas Gregor39aaeef2013-05-02 18:35:56 +00001472 if (RangeVar->isInvalidDecl())
1473 return StmtError();
1474
Douglas Gregorf7106af2013-04-08 18:40:13 +00001475 Expr *RangeExpr = RangeVar->getInit();
1476 if (!RangeExpr->isTypeDependent() &&
1477 RangeExpr->getType()->isObjCObjectPointerType())
1478 return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, RangeExpr,
1479 RParenLoc);
1480 }
1481 }
1482 }
1483
Richard Smith02e85f32011-04-14 22:09:26 +00001484 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
Richard Smitha05b3b52012-09-20 21:52:32 +00001485 Cond, Inc, LoopVar, RParenLoc,
1486 Sema::BFRK_Rebuild);
Richard Smith02e85f32011-04-14 22:09:26 +00001487 }
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001488
1489 /// \brief Build a new C++0x range-based for statement.
1490 ///
1491 /// By default, performs semantic analysis to build the new statement.
1492 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00001493 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001494 bool IsIfExists,
1495 NestedNameSpecifierLoc QualifierLoc,
1496 DeclarationNameInfo NameInfo,
1497 Stmt *Nested) {
1498 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1499 QualifierLoc, NameInfo, Nested);
1500 }
1501
Richard Smith02e85f32011-04-14 22:09:26 +00001502 /// \brief Attach body to a C++0x range-based for statement.
1503 ///
1504 /// By default, performs semantic analysis to finish the new statement.
1505 /// Subclasses may override this routine to provide different behavior.
1506 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1507 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1508 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001509
David Majnemerfad8f482013-10-15 09:33:02 +00001510 StmtResult RebuildSEHTryStmt(bool IsCXXTry, SourceLocation TryLoc,
1511 Stmt *TryBlock, Stmt *Handler) {
1512 return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +00001513 }
1514
David Majnemerfad8f482013-10-15 09:33:02 +00001515 StmtResult RebuildSEHExceptStmt(SourceLocation Loc, Expr *FilterExpr,
John Wiegley1c0675e2011-04-28 01:08:34 +00001516 Stmt *Block) {
David Majnemerfad8f482013-10-15 09:33:02 +00001517 return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001518 }
1519
David Majnemerfad8f482013-10-15 09:33:02 +00001520 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, Stmt *Block) {
1521 return getSema().ActOnSEHFinallyBlock(Loc, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001522 }
1523
Douglas Gregora16548e2009-08-11 05:31:07 +00001524 /// \brief Build a new expression that references a declaration.
1525 ///
1526 /// By default, performs semantic analysis to build the new expression.
1527 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001528 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00001529 LookupResult &R,
1530 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00001531 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1532 }
1533
1534
1535 /// \brief Build a new expression that references a declaration.
1536 ///
1537 /// By default, performs semantic analysis to build the new expression.
1538 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorea972d32011-02-28 21:54:11 +00001539 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001540 ValueDecl *VD,
1541 const DeclarationNameInfo &NameInfo,
1542 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001543 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001544 SS.Adopt(QualifierLoc);
John McCallce546572009-12-08 09:08:17 +00001545
1546 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001547
1548 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001549 }
Mike Stump11289f42009-09-09 15:08:12 +00001550
Douglas Gregora16548e2009-08-11 05:31:07 +00001551 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001552 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001553 /// By default, performs semantic analysis to build the new expression.
1554 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001555 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00001556 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00001557 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001558 }
1559
Douglas Gregorad8a3362009-09-04 17:36:40 +00001560 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001561 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001562 /// By default, performs semantic analysis to build the new expression.
1563 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001564 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora6ce6082011-02-25 18:19:59 +00001565 SourceLocation OperatorLoc,
1566 bool isArrow,
1567 CXXScopeSpec &SS,
1568 TypeSourceInfo *ScopeType,
1569 SourceLocation CCLoc,
1570 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001571 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001572
Douglas Gregora16548e2009-08-11 05:31:07 +00001573 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001574 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001575 /// By default, performs semantic analysis to build the new expression.
1576 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001577 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001578 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001579 Expr *SubExpr) {
1580 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001581 }
Mike Stump11289f42009-09-09 15:08:12 +00001582
Douglas Gregor882211c2010-04-28 22:16:22 +00001583 /// \brief Build a new builtin offsetof expression.
1584 ///
1585 /// By default, performs semantic analysis to build the new expression.
1586 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001587 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor882211c2010-04-28 22:16:22 +00001588 TypeSourceInfo *Type,
John McCallfaf5fb42010-08-26 23:41:50 +00001589 Sema::OffsetOfComponent *Components,
Douglas Gregor882211c2010-04-28 22:16:22 +00001590 unsigned NumComponents,
1591 SourceLocation RParenLoc) {
1592 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1593 NumComponents, RParenLoc);
1594 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001595
1596 /// \brief Build a new sizeof, alignof or vec_step expression with a
Peter Collingbournee190dee2011-03-11 19:24:49 +00001597 /// type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001598 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001599 /// By default, performs semantic analysis to build the new expression.
1600 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001601 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1602 SourceLocation OpLoc,
1603 UnaryExprOrTypeTrait ExprKind,
1604 SourceRange R) {
1605 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001606 }
1607
Peter Collingbournee190dee2011-03-11 19:24:49 +00001608 /// \brief Build a new sizeof, alignof or vec step expression with an
1609 /// expression argument.
Mike Stump11289f42009-09-09 15:08:12 +00001610 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001611 /// By default, performs semantic analysis to build the new expression.
1612 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001613 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1614 UnaryExprOrTypeTrait ExprKind,
1615 SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00001616 ExprResult Result
Chandler Carrutha923fb22011-05-29 07:32:14 +00001617 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregora16548e2009-08-11 05:31:07 +00001618 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001619 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001620
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001621 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001622 }
Mike Stump11289f42009-09-09 15:08:12 +00001623
Douglas Gregora16548e2009-08-11 05:31:07 +00001624 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001625 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001626 /// By default, performs semantic analysis to build the new expression.
1627 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001628 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001629 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00001630 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001631 SourceLocation RBracketLoc) {
John McCallb268a282010-08-23 23:25:46 +00001632 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1633 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001634 RBracketLoc);
1635 }
1636
1637 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00001638 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001639 /// By default, performs semantic analysis to build the new expression.
1640 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001641 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001642 MultiExprArg Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00001643 SourceLocation RParenLoc,
1644 Expr *ExecConfig = 0) {
John McCallb268a282010-08-23 23:25:46 +00001645 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001646 Args, RParenLoc, ExecConfig);
Douglas Gregora16548e2009-08-11 05:31:07 +00001647 }
1648
1649 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001650 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001651 /// By default, performs semantic analysis to build the new expression.
1652 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001653 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001654 bool isArrow,
Douglas Gregorea972d32011-02-28 21:54:11 +00001655 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001656 SourceLocation TemplateKWLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001657 const DeclarationNameInfo &MemberNameInfo,
1658 ValueDecl *Member,
1659 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001660 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00001661 NamedDecl *FirstQualifierInScope) {
Richard Smithcab9a7d2011-10-26 19:06:56 +00001662 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
1663 isArrow);
Anders Carlsson5da84842009-09-01 04:26:58 +00001664 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00001665 // We have a reference to an unnamed field. This is always the
1666 // base of an anonymous struct/union member access, i.e. the
1667 // field is always of record type.
Douglas Gregorea972d32011-02-28 21:54:11 +00001668 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCall7decc9e2010-11-18 06:31:45 +00001669 assert(Member->getType()->isRecordType() &&
1670 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00001671
Richard Smithcab9a7d2011-10-26 19:06:56 +00001672 BaseResult =
1673 getSema().PerformObjectMemberConversion(BaseResult.take(),
John Wiegley01296292011-04-08 18:41:53 +00001674 QualifierLoc.getNestedNameSpecifier(),
1675 FoundDecl, Member);
1676 if (BaseResult.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001677 return ExprError();
John Wiegley01296292011-04-08 18:41:53 +00001678 Base = BaseResult.take();
John McCall7decc9e2010-11-18 06:31:45 +00001679 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump11289f42009-09-09 15:08:12 +00001680 MemberExpr *ME =
John McCallb268a282010-08-23 23:25:46 +00001681 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001682 Member, MemberNameInfo,
John McCall7decc9e2010-11-18 06:31:45 +00001683 cast<FieldDecl>(Member)->getType(),
1684 VK, OK_Ordinary);
Anders Carlsson5da84842009-09-01 04:26:58 +00001685 return getSema().Owned(ME);
1686 }
Mike Stump11289f42009-09-09 15:08:12 +00001687
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001688 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001689 SS.Adopt(QualifierLoc);
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001690
John Wiegley01296292011-04-08 18:41:53 +00001691 Base = BaseResult.take();
John McCallb268a282010-08-23 23:25:46 +00001692 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00001693
John McCall16df1e52010-03-30 21:47:33 +00001694 // FIXME: this involves duplicating earlier analysis in a lot of
1695 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001696 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001697 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001698 R.resolveKind();
1699
John McCallb268a282010-08-23 23:25:46 +00001700 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001701 SS, TemplateKWLoc,
1702 FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001703 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001704 }
Mike Stump11289f42009-09-09 15:08:12 +00001705
Douglas Gregora16548e2009-08-11 05:31:07 +00001706 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001707 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001708 /// By default, performs semantic analysis to build the new expression.
1709 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001710 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001711 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001712 Expr *LHS, Expr *RHS) {
1713 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001714 }
1715
1716 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001717 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001718 /// By default, performs semantic analysis to build the new expression.
1719 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001720 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCallc07a0c72011-02-17 10:25:35 +00001721 SourceLocation QuestionLoc,
1722 Expr *LHS,
1723 SourceLocation ColonLoc,
1724 Expr *RHS) {
John McCallb268a282010-08-23 23:25:46 +00001725 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1726 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001727 }
1728
Douglas Gregora16548e2009-08-11 05:31:07 +00001729 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001730 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001731 /// By default, performs semantic analysis to build the new expression.
1732 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001733 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00001734 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001735 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001736 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001737 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001738 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001739 }
Mike Stump11289f42009-09-09 15:08:12 +00001740
Douglas Gregora16548e2009-08-11 05:31:07 +00001741 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001742 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001743 /// By default, performs semantic analysis to build the new expression.
1744 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001745 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001746 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001747 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001748 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001749 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001750 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001751 }
Mike Stump11289f42009-09-09 15:08:12 +00001752
Douglas Gregora16548e2009-08-11 05:31:07 +00001753 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001754 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001755 /// By default, performs semantic analysis to build the new expression.
1756 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001757 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001758 SourceLocation OpLoc,
1759 SourceLocation AccessorLoc,
1760 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001761
John McCall10eae182009-11-30 22:42:35 +00001762 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001763 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00001764 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00001765 OpLoc, /*IsArrow*/ false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001766 SS, SourceLocation(),
1767 /*FirstQualifierInScope*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001768 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00001769 /* TemplateArgs */ 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00001770 }
Mike Stump11289f42009-09-09 15:08:12 +00001771
Douglas Gregora16548e2009-08-11 05:31:07 +00001772 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001773 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001774 /// By default, performs semantic analysis to build the new expression.
1775 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001776 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCall542e7c62011-07-06 07:30:07 +00001777 MultiExprArg Inits,
1778 SourceLocation RBraceLoc,
1779 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00001780 ExprResult Result
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001781 = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
Douglas Gregord3d93062009-11-09 17:16:50 +00001782 if (Result.isInvalid() || ResultTy->isDependentType())
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001783 return Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00001784
Douglas Gregord3d93062009-11-09 17:16:50 +00001785 // Patch in the result type we were given, which may have been computed
1786 // when the initial InitListExpr was built.
1787 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1788 ILE->setType(ResultTy);
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001789 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001790 }
Mike Stump11289f42009-09-09 15:08:12 +00001791
Douglas Gregora16548e2009-08-11 05:31:07 +00001792 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001793 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001794 /// By default, performs semantic analysis to build the new expression.
1795 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001796 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00001797 MultiExprArg ArrayExprs,
1798 SourceLocation EqualOrColonLoc,
1799 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001800 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00001801 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001802 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001803 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001804 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001805 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001806
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001807 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001808 }
Mike Stump11289f42009-09-09 15:08:12 +00001809
Douglas Gregora16548e2009-08-11 05:31:07 +00001810 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001811 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001812 /// By default, builds the implicit value initialization without performing
1813 /// any semantic analysis. Subclasses may override this routine to provide
1814 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001815 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001816 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1817 }
Mike Stump11289f42009-09-09 15:08:12 +00001818
Douglas Gregora16548e2009-08-11 05:31:07 +00001819 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001820 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001821 /// By default, performs semantic analysis to build the new expression.
1822 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001823 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001824 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001825 SourceLocation RParenLoc) {
1826 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001827 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001828 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001829 }
1830
1831 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001832 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001833 /// By default, performs semantic analysis to build the new expression.
1834 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001835 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redla9351792012-02-11 23:51:47 +00001836 MultiExprArg SubExprs,
1837 SourceLocation RParenLoc) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001838 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001839 }
Mike Stump11289f42009-09-09 15:08:12 +00001840
Douglas Gregora16548e2009-08-11 05:31:07 +00001841 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001842 ///
1843 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00001844 /// rather than attempting to map the label statement itself.
1845 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001846 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001847 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001848 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregora16548e2009-08-11 05:31:07 +00001849 }
Mike Stump11289f42009-09-09 15:08:12 +00001850
Douglas Gregora16548e2009-08-11 05:31:07 +00001851 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00001852 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001853 /// By default, performs semantic analysis to build the new expression.
1854 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001855 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001856 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00001857 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001858 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001859 }
Mike Stump11289f42009-09-09 15:08:12 +00001860
Douglas Gregora16548e2009-08-11 05:31:07 +00001861 /// \brief Build a new __builtin_choose_expr expression.
1862 ///
1863 /// By default, performs semantic analysis to build the new expression.
1864 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001865 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001866 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001867 SourceLocation RParenLoc) {
1868 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001869 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001870 RParenLoc);
1871 }
Mike Stump11289f42009-09-09 15:08:12 +00001872
Peter Collingbourne91147592011-04-15 00:35:48 +00001873 /// \brief Build a new generic selection expression.
1874 ///
1875 /// By default, performs semantic analysis to build the new expression.
1876 /// Subclasses may override this routine to provide different behavior.
1877 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
1878 SourceLocation DefaultLoc,
1879 SourceLocation RParenLoc,
1880 Expr *ControllingExpr,
Dmitri Gribenko82360372013-05-10 13:06:58 +00001881 ArrayRef<TypeSourceInfo *> Types,
1882 ArrayRef<Expr *> Exprs) {
Peter Collingbourne91147592011-04-15 00:35:48 +00001883 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
Dmitri Gribenko82360372013-05-10 13:06:58 +00001884 ControllingExpr, Types, Exprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00001885 }
1886
Douglas Gregora16548e2009-08-11 05:31:07 +00001887 /// \brief Build a new overloaded operator call expression.
1888 ///
1889 /// By default, performs semantic analysis to build the new expression.
1890 /// The semantic analysis provides the behavior of template instantiation,
1891 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00001892 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00001893 /// argument-dependent lookup, etc. Subclasses may override this routine to
1894 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001895 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00001896 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00001897 Expr *Callee,
1898 Expr *First,
1899 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00001900
1901 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00001902 /// reinterpret_cast.
1903 ///
1904 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00001905 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00001906 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001907 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001908 Stmt::StmtClass Class,
1909 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001910 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001911 SourceLocation RAngleLoc,
1912 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001913 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001914 SourceLocation RParenLoc) {
1915 switch (Class) {
1916 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001917 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001918 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001919 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001920
1921 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001922 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001923 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001924 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001925
Douglas Gregora16548e2009-08-11 05:31:07 +00001926 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001927 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001928 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001929 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001930 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001931
Douglas Gregora16548e2009-08-11 05:31:07 +00001932 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001933 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001934 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001935 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001936
Douglas Gregora16548e2009-08-11 05:31:07 +00001937 default:
David Blaikie83d382b2011-09-23 05:06:16 +00001938 llvm_unreachable("Invalid C++ named cast");
Douglas Gregora16548e2009-08-11 05:31:07 +00001939 }
Douglas Gregora16548e2009-08-11 05:31:07 +00001940 }
Mike Stump11289f42009-09-09 15:08:12 +00001941
Douglas Gregora16548e2009-08-11 05:31:07 +00001942 /// \brief Build a new C++ static_cast expression.
1943 ///
1944 /// By default, performs semantic analysis to build the new expression.
1945 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001946 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001947 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001948 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001949 SourceLocation RAngleLoc,
1950 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001951 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001952 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001953 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00001954 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001955 SourceRange(LAngleLoc, RAngleLoc),
1956 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001957 }
1958
1959 /// \brief Build a new C++ dynamic_cast expression.
1960 ///
1961 /// By default, performs semantic analysis to build the new expression.
1962 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001963 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001964 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001965 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001966 SourceLocation RAngleLoc,
1967 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001968 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001969 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001970 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00001971 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001972 SourceRange(LAngleLoc, RAngleLoc),
1973 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001974 }
1975
1976 /// \brief Build a new C++ reinterpret_cast expression.
1977 ///
1978 /// By default, performs semantic analysis to build the new expression.
1979 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001980 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001981 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001982 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001983 SourceLocation RAngleLoc,
1984 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001985 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001986 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001987 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00001988 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001989 SourceRange(LAngleLoc, RAngleLoc),
1990 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001991 }
1992
1993 /// \brief Build a new C++ const_cast expression.
1994 ///
1995 /// By default, performs semantic analysis to build the new expression.
1996 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001997 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001998 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001999 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002000 SourceLocation RAngleLoc,
2001 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002002 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002003 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002004 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00002005 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002006 SourceRange(LAngleLoc, RAngleLoc),
2007 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002008 }
Mike Stump11289f42009-09-09 15:08:12 +00002009
Douglas Gregora16548e2009-08-11 05:31:07 +00002010 /// \brief Build a new C++ functional-style cast expression.
2011 ///
2012 /// By default, performs semantic analysis to build the new expression.
2013 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002014 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
2015 SourceLocation LParenLoc,
2016 Expr *Sub,
2017 SourceLocation RParenLoc) {
2018 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00002019 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00002020 RParenLoc);
2021 }
Mike Stump11289f42009-09-09 15:08:12 +00002022
Douglas Gregora16548e2009-08-11 05:31:07 +00002023 /// \brief Build a new C++ typeid(type) expression.
2024 ///
2025 /// By default, performs semantic analysis to build the new expression.
2026 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002027 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002028 SourceLocation TypeidLoc,
2029 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002030 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002031 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002032 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002033 }
Mike Stump11289f42009-09-09 15:08:12 +00002034
Francois Pichet9f4f2072010-09-08 12:20:18 +00002035
Douglas Gregora16548e2009-08-11 05:31:07 +00002036 /// \brief Build a new C++ typeid(expr) expression.
2037 ///
2038 /// By default, performs semantic analysis to build the new expression.
2039 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002040 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002041 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00002042 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002043 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002044 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002045 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002046 }
2047
Francois Pichet9f4f2072010-09-08 12:20:18 +00002048 /// \brief Build a new C++ __uuidof(type) expression.
2049 ///
2050 /// By default, performs semantic analysis to build the new expression.
2051 /// Subclasses may override this routine to provide different behavior.
2052 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2053 SourceLocation TypeidLoc,
2054 TypeSourceInfo *Operand,
2055 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002056 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
Francois Pichet9f4f2072010-09-08 12:20:18 +00002057 RParenLoc);
2058 }
2059
2060 /// \brief Build a new C++ __uuidof(expr) expression.
2061 ///
2062 /// By default, performs semantic analysis to build the new expression.
2063 /// Subclasses may override this routine to provide different behavior.
2064 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2065 SourceLocation TypeidLoc,
2066 Expr *Operand,
2067 SourceLocation RParenLoc) {
2068 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
2069 RParenLoc);
2070 }
2071
Douglas Gregora16548e2009-08-11 05:31:07 +00002072 /// \brief Build a new C++ "this" expression.
2073 ///
2074 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00002075 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00002076 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002077 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00002078 QualType ThisType,
2079 bool isImplicit) {
Eli Friedman20139d32012-01-11 02:36:31 +00002080 getSema().CheckCXXThisCapture(ThisLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002081 return getSema().Owned(
Douglas Gregorb15af892010-01-07 23:12:05 +00002082 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
2083 isImplicit));
Douglas Gregora16548e2009-08-11 05:31:07 +00002084 }
2085
2086 /// \brief Build a new C++ throw expression.
2087 ///
2088 /// By default, performs semantic analysis to build the new expression.
2089 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor53e191ed2011-07-06 22:04:06 +00002090 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
2091 bool IsThrownVariableInScope) {
2092 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00002093 }
2094
2095 /// \brief Build a new C++ default-argument expression.
2096 ///
2097 /// By default, builds a new default-argument expression, which does not
2098 /// require any semantic analysis. Subclasses may override this routine to
2099 /// provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002100 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00002101 ParmVarDecl *Param) {
2102 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
2103 Param));
Douglas Gregora16548e2009-08-11 05:31:07 +00002104 }
2105
Richard Smith852c9db2013-04-20 22:23:05 +00002106 /// \brief Build a new C++11 default-initialization expression.
2107 ///
2108 /// By default, builds a new default field initialization expression, which
2109 /// does not require any semantic analysis. Subclasses may override this
2110 /// routine to provide different behavior.
2111 ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc,
2112 FieldDecl *Field) {
2113 return getSema().Owned(CXXDefaultInitExpr::Create(getSema().Context, Loc,
2114 Field));
2115 }
2116
Douglas Gregora16548e2009-08-11 05:31:07 +00002117 /// \brief Build a new C++ zero-initialization expression.
2118 ///
2119 /// By default, performs semantic analysis to build the new expression.
2120 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002121 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
2122 SourceLocation LParenLoc,
2123 SourceLocation RParenLoc) {
2124 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002125 None, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002126 }
Mike Stump11289f42009-09-09 15:08:12 +00002127
Douglas Gregora16548e2009-08-11 05:31:07 +00002128 /// \brief Build a new C++ "new" expression.
2129 ///
2130 /// By default, performs semantic analysis to build the new expression.
2131 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002132 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002133 bool UseGlobal,
2134 SourceLocation PlacementLParen,
2135 MultiExprArg PlacementArgs,
2136 SourceLocation PlacementRParen,
2137 SourceRange TypeIdParens,
2138 QualType AllocatedType,
2139 TypeSourceInfo *AllocatedTypeInfo,
2140 Expr *ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002141 SourceRange DirectInitRange,
2142 Expr *Initializer) {
Mike Stump11289f42009-09-09 15:08:12 +00002143 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00002144 PlacementLParen,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002145 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00002146 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00002147 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002148 AllocatedType,
2149 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00002150 ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002151 DirectInitRange,
2152 Initializer);
Douglas Gregora16548e2009-08-11 05:31:07 +00002153 }
Mike Stump11289f42009-09-09 15:08:12 +00002154
Douglas Gregora16548e2009-08-11 05:31:07 +00002155 /// \brief Build a new C++ "delete" expression.
2156 ///
2157 /// By default, performs semantic analysis to build the new expression.
2158 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002159 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002160 bool IsGlobalDelete,
2161 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002162 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002163 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002164 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00002165 }
Mike Stump11289f42009-09-09 15:08:12 +00002166
Douglas Gregor29c42f22012-02-24 07:38:34 +00002167 /// \brief Build a new type trait expression.
2168 ///
2169 /// By default, performs semantic analysis to build the new expression.
2170 /// Subclasses may override this routine to provide different behavior.
2171 ExprResult RebuildTypeTrait(TypeTrait Trait,
2172 SourceLocation StartLoc,
2173 ArrayRef<TypeSourceInfo *> Args,
2174 SourceLocation RParenLoc) {
2175 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2176 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002177
John Wiegley6242b6a2011-04-28 00:16:57 +00002178 /// \brief Build a new array type trait expression.
2179 ///
2180 /// By default, performs semantic analysis to build the new expression.
2181 /// Subclasses may override this routine to provide different behavior.
2182 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2183 SourceLocation StartLoc,
2184 TypeSourceInfo *TSInfo,
2185 Expr *DimExpr,
2186 SourceLocation RParenLoc) {
2187 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2188 }
2189
John Wiegleyf9f65842011-04-25 06:54:41 +00002190 /// \brief Build a new expression trait expression.
2191 ///
2192 /// By default, performs semantic analysis to build the new expression.
2193 /// Subclasses may override this routine to provide different behavior.
2194 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2195 SourceLocation StartLoc,
2196 Expr *Queried,
2197 SourceLocation RParenLoc) {
2198 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2199 }
2200
Mike Stump11289f42009-09-09 15:08:12 +00002201 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00002202 /// expression.
2203 ///
2204 /// By default, performs semantic analysis to build the new expression.
2205 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002206 ExprResult RebuildDependentScopeDeclRefExpr(
2207 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002208 SourceLocation TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002209 const DeclarationNameInfo &NameInfo,
Richard Smithdb2630f2012-10-21 03:28:35 +00002210 const TemplateArgumentListInfo *TemplateArgs,
2211 bool IsAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002212 CXXScopeSpec SS;
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002213 SS.Adopt(QualifierLoc);
John McCalle66edc12009-11-24 19:00:30 +00002214
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002215 if (TemplateArgs || TemplateKWLoc.isValid())
Abramo Bagnara7945c982012-01-27 09:46:47 +00002216 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002217 NameInfo, TemplateArgs);
John McCalle66edc12009-11-24 19:00:30 +00002218
Richard Smithdb2630f2012-10-21 03:28:35 +00002219 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo,
2220 IsAddressOfOperand);
Douglas Gregora16548e2009-08-11 05:31:07 +00002221 }
2222
2223 /// \brief Build a new template-id expression.
2224 ///
2225 /// By default, performs semantic analysis to build the new expression.
2226 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002227 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002228 SourceLocation TemplateKWLoc,
2229 LookupResult &R,
2230 bool RequiresADL,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002231 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnara7945c982012-01-27 09:46:47 +00002232 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2233 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002234 }
2235
2236 /// \brief Build a new object-construction expression.
2237 ///
2238 /// By default, performs semantic analysis to build the new expression.
2239 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002240 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002241 SourceLocation Loc,
2242 CXXConstructorDecl *Constructor,
2243 bool IsElidable,
2244 MultiExprArg Args,
2245 bool HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002246 bool ListInitialization,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002247 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00002248 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002249 SourceRange ParenRange) {
Benjamin Kramerf0623432012-08-23 22:51:59 +00002250 SmallVector<Expr*, 8> ConvertedArgs;
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002251 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00002252 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00002253 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002254
Douglas Gregordb121ba2009-12-14 16:27:04 +00002255 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002256 ConvertedArgs,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002257 HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002258 ListInitialization,
Chandler Carruth01718152010-10-25 08:47:36 +00002259 RequiresZeroInit, ConstructKind,
2260 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00002261 }
2262
2263 /// \brief Build a new object-construction expression.
2264 ///
2265 /// By default, performs semantic analysis to build the new expression.
2266 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002267 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2268 SourceLocation LParenLoc,
2269 MultiExprArg Args,
2270 SourceLocation RParenLoc) {
2271 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002272 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002273 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002274 RParenLoc);
2275 }
2276
2277 /// \brief Build a new object-construction expression.
2278 ///
2279 /// By default, performs semantic analysis to build the new expression.
2280 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002281 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2282 SourceLocation LParenLoc,
2283 MultiExprArg Args,
2284 SourceLocation RParenLoc) {
2285 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002286 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002287 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002288 RParenLoc);
2289 }
Mike Stump11289f42009-09-09 15:08:12 +00002290
Douglas Gregora16548e2009-08-11 05:31:07 +00002291 /// \brief Build a new member reference expression.
2292 ///
2293 /// By default, performs semantic analysis to build the new expression.
2294 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002295 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregore16af532011-02-28 18:50:33 +00002296 QualType BaseType,
2297 bool IsArrow,
2298 SourceLocation OperatorLoc,
2299 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002300 SourceLocation TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00002301 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002302 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00002303 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002304 CXXScopeSpec SS;
Douglas Gregore16af532011-02-28 18:50:33 +00002305 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002306
John McCallb268a282010-08-23 23:25:46 +00002307 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002308 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002309 SS, TemplateKWLoc,
2310 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002311 MemberNameInfo,
2312 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002313 }
2314
John McCall10eae182009-11-30 22:42:35 +00002315 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00002316 ///
2317 /// By default, performs semantic analysis to build the new expression.
2318 /// Subclasses may override this routine to provide different behavior.
Richard Smithcab9a7d2011-10-26 19:06:56 +00002319 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2320 SourceLocation OperatorLoc,
2321 bool IsArrow,
2322 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002323 SourceLocation TemplateKWLoc,
Richard Smithcab9a7d2011-10-26 19:06:56 +00002324 NamedDecl *FirstQualifierInScope,
2325 LookupResult &R,
John McCall10eae182009-11-30 22:42:35 +00002326 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00002327 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00002328 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002329
John McCallb268a282010-08-23 23:25:46 +00002330 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002331 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002332 SS, TemplateKWLoc,
2333 FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00002334 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00002335 }
Mike Stump11289f42009-09-09 15:08:12 +00002336
Sebastian Redl4202c0f2010-09-10 20:55:43 +00002337 /// \brief Build a new noexcept expression.
2338 ///
2339 /// By default, performs semantic analysis to build the new expression.
2340 /// Subclasses may override this routine to provide different behavior.
2341 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2342 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2343 }
2344
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002345 /// \brief Build a new expression to compute the length of a parameter pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00002346 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2347 SourceLocation PackLoc,
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002348 SourceLocation RParenLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002349 Optional<unsigned> Length) {
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002350 if (Length)
Chad Rosier1dcde962012-08-08 18:46:20 +00002351 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2352 OperatorLoc, Pack, PackLoc,
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002353 RParenLoc, *Length);
Chad Rosier1dcde962012-08-08 18:46:20 +00002354
2355 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2356 OperatorLoc, Pack, PackLoc,
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002357 RParenLoc);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002358 }
Ted Kremeneke65b0862012-03-06 20:05:56 +00002359
Patrick Beard0caa3942012-04-19 00:25:12 +00002360 /// \brief Build a new Objective-C boxed expression.
2361 ///
2362 /// By default, performs semantic analysis to build the new expression.
2363 /// Subclasses may override this routine to provide different behavior.
2364 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2365 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2366 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002367
Ted Kremeneke65b0862012-03-06 20:05:56 +00002368 /// \brief Build a new Objective-C array literal.
2369 ///
2370 /// By default, performs semantic analysis to build the new expression.
2371 /// Subclasses may override this routine to provide different behavior.
2372 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2373 Expr **Elements, unsigned NumElements) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002374 return getSema().BuildObjCArrayLiteral(Range,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002375 MultiExprArg(Elements, NumElements));
2376 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002377
2378 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002379 Expr *Base, Expr *Key,
2380 ObjCMethodDecl *getterMethod,
2381 ObjCMethodDecl *setterMethod) {
2382 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2383 getterMethod, setterMethod);
2384 }
2385
2386 /// \brief Build a new Objective-C dictionary literal.
2387 ///
2388 /// By default, performs semantic analysis to build the new expression.
2389 /// Subclasses may override this routine to provide different behavior.
2390 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
2391 ObjCDictionaryElement *Elements,
2392 unsigned NumElements) {
2393 return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements);
2394 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002395
James Dennett2a4d13c2012-06-15 07:13:21 +00002396 /// \brief Build a new Objective-C \@encode expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002397 ///
2398 /// By default, performs semantic analysis to build the new expression.
2399 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002400 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00002401 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002402 SourceLocation RParenLoc) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00002403 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002404 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00002405 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002406
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002407 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00002408 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002409 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002410 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002411 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002412 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002413 MultiExprArg Args,
2414 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002415 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2416 ReceiverTypeInfo->getType(),
2417 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002418 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002419 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002420 }
2421
2422 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00002423 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002424 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002425 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002426 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002427 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002428 MultiExprArg Args,
2429 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00002430 return SemaRef.BuildInstanceMessage(Receiver,
2431 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002432 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002433 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002434 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002435 }
2436
Douglas Gregord51d90d2010-04-26 20:11:03 +00002437 /// \brief Build a new Objective-C ivar reference expression.
2438 ///
2439 /// By default, performs semantic analysis to build the new expression.
2440 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002441 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002442 SourceLocation IvarLoc,
2443 bool IsArrow, bool IsFreeIvar) {
2444 // FIXME: We lose track of the IsFreeIvar bit.
2445 CXXScopeSpec SS;
John Wiegley01296292011-04-08 18:41:53 +00002446 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002447 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2448 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00002449 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002450 /*FIME:*/IvarLoc,
John McCall48871652010-08-21 09:40:31 +00002451 SS, 0,
John McCalle9cccd82010-06-16 08:42:20 +00002452 false);
John Wiegley01296292011-04-08 18:41:53 +00002453 if (Result.isInvalid() || Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002454 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002455
Douglas Gregord51d90d2010-04-26 20:11:03 +00002456 if (Result.get())
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002457 return Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00002458
John Wiegley01296292011-04-08 18:41:53 +00002459 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Abramo Bagnara7945c982012-01-27 09:46:47 +00002460 /*FIXME:*/IvarLoc, IsArrow,
2461 SS, SourceLocation(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00002462 /*FirstQualifierInScope=*/0,
Chad Rosier1dcde962012-08-08 18:46:20 +00002463 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002464 /*TemplateArgs=*/0);
2465 }
Douglas Gregor9faee212010-04-26 20:47:02 +00002466
2467 /// \brief Build a new Objective-C property reference expression.
2468 ///
2469 /// By default, performs semantic analysis to build the new expression.
2470 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002471 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall526ab472011-10-25 17:37:35 +00002472 ObjCPropertyDecl *Property,
2473 SourceLocation PropertyLoc) {
Douglas Gregor9faee212010-04-26 20:47:02 +00002474 CXXScopeSpec SS;
John Wiegley01296292011-04-08 18:41:53 +00002475 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregor9faee212010-04-26 20:47:02 +00002476 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2477 Sema::LookupMemberName);
2478 bool IsArrow = false;
John McCalldadc5752010-08-24 06:29:42 +00002479 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregor9faee212010-04-26 20:47:02 +00002480 /*FIME:*/PropertyLoc,
John McCall48871652010-08-21 09:40:31 +00002481 SS, 0, false);
John Wiegley01296292011-04-08 18:41:53 +00002482 if (Result.isInvalid() || Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002483 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002484
Douglas Gregor9faee212010-04-26 20:47:02 +00002485 if (Result.get())
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002486 return Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00002487
John Wiegley01296292011-04-08 18:41:53 +00002488 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Chad Rosier1dcde962012-08-08 18:46:20 +00002489 /*FIXME:*/PropertyLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002490 SS, SourceLocation(),
Douglas Gregor9faee212010-04-26 20:47:02 +00002491 /*FirstQualifierInScope=*/0,
Chad Rosier1dcde962012-08-08 18:46:20 +00002492 R,
Douglas Gregor9faee212010-04-26 20:47:02 +00002493 /*TemplateArgs=*/0);
2494 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002495
John McCallb7bd14f2010-12-02 01:19:52 +00002496 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002497 ///
2498 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00002499 /// Subclasses may override this routine to provide different behavior.
2500 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2501 ObjCMethodDecl *Getter,
2502 ObjCMethodDecl *Setter,
2503 SourceLocation PropertyLoc) {
2504 // Since these expressions can only be value-dependent, we do not
2505 // need to perform semantic analysis again.
2506 return Owned(
2507 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2508 VK_LValue, OK_ObjCProperty,
2509 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002510 }
2511
Douglas Gregord51d90d2010-04-26 20:11:03 +00002512 /// \brief Build a new Objective-C "isa" expression.
2513 ///
2514 /// By default, performs semantic analysis to build the new expression.
2515 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002516 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00002517 SourceLocation OpLoc,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002518 bool IsArrow) {
2519 CXXScopeSpec SS;
John Wiegley01296292011-04-08 18:41:53 +00002520 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002521 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2522 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00002523 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00002524 OpLoc,
John McCall48871652010-08-21 09:40:31 +00002525 SS, 0, false);
John Wiegley01296292011-04-08 18:41:53 +00002526 if (Result.isInvalid() || Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002527 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002528
Douglas Gregord51d90d2010-04-26 20:11:03 +00002529 if (Result.get())
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002530 return Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00002531
John Wiegley01296292011-04-08 18:41:53 +00002532 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00002533 OpLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002534 SS, SourceLocation(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00002535 /*FirstQualifierInScope=*/0,
Chad Rosier1dcde962012-08-08 18:46:20 +00002536 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002537 /*TemplateArgs=*/0);
2538 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002539
Douglas Gregora16548e2009-08-11 05:31:07 +00002540 /// \brief Build a new shuffle vector expression.
2541 ///
2542 /// By default, performs semantic analysis to build the new expression.
2543 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002544 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002545 MultiExprArg SubExprs,
2546 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002547 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00002548 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00002549 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2550 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2551 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
David Blaikieff7d47a2012-12-19 00:45:41 +00002552 assert(!Lookup.empty() && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00002553
Douglas Gregora16548e2009-08-11 05:31:07 +00002554 // Build a reference to the __builtin_shufflevector builtin
David Blaikieff7d47a2012-12-19 00:45:41 +00002555 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
Eli Friedman34866c72012-08-31 00:14:07 +00002556 Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false,
2557 SemaRef.Context.BuiltinFnTy,
2558 VK_RValue, BuiltinLoc);
2559 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
2560 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
2561 CK_BuiltinFnToFnPtr).take();
Mike Stump11289f42009-09-09 15:08:12 +00002562
2563 // Build the CallExpr
Alp Toker314cc812014-01-25 16:55:45 +00002564 ExprResult TheCall = SemaRef.Owned(new (SemaRef.Context) CallExpr(
2565 SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(),
2566 Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00002567
Douglas Gregora16548e2009-08-11 05:31:07 +00002568 // Type-check the __builtin_shufflevector expression.
John Wiegley01296292011-04-08 18:41:53 +00002569 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.take()));
Douglas Gregora16548e2009-08-11 05:31:07 +00002570 }
John McCall31f82722010-11-12 08:19:04 +00002571
Hal Finkelc4d7c822013-09-18 03:29:45 +00002572 /// \brief Build a new convert vector expression.
2573 ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc,
2574 Expr *SrcExpr, TypeSourceInfo *DstTInfo,
2575 SourceLocation RParenLoc) {
2576 return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo,
2577 BuiltinLoc, RParenLoc);
2578 }
2579
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002580 /// \brief Build a new template argument pack expansion.
2581 ///
2582 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00002583 /// for a template argument. Subclasses may override this routine to provide
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002584 /// different behavior.
2585 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002586 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002587 Optional<unsigned> NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002588 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00002589 case TemplateArgument::Expression: {
2590 ExprResult Result
Douglas Gregorb8840002011-01-14 21:20:45 +00002591 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2592 EllipsisLoc, NumExpansions);
Douglas Gregor98318c22011-01-03 21:37:45 +00002593 if (Result.isInvalid())
2594 return TemplateArgumentLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00002595
Douglas Gregor98318c22011-01-03 21:37:45 +00002596 return TemplateArgumentLoc(Result.get(), Result.get());
2597 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002598
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002599 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002600 return TemplateArgumentLoc(TemplateArgument(
2601 Pattern.getArgument().getAsTemplate(),
Douglas Gregore1d60df2011-01-14 23:41:42 +00002602 NumExpansions),
Douglas Gregor9d802122011-03-02 17:09:35 +00002603 Pattern.getTemplateQualifierLoc(),
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002604 Pattern.getTemplateNameLoc(),
2605 EllipsisLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00002606
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002607 case TemplateArgument::Null:
2608 case TemplateArgument::Integral:
2609 case TemplateArgument::Declaration:
2610 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002611 case TemplateArgument::TemplateExpansion:
Eli Friedmanb826a002012-09-26 02:36:12 +00002612 case TemplateArgument::NullPtr:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002613 llvm_unreachable("Pack expansion pattern has no parameter packs");
Chad Rosier1dcde962012-08-08 18:46:20 +00002614
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002615 case TemplateArgument::Type:
Chad Rosier1dcde962012-08-08 18:46:20 +00002616 if (TypeSourceInfo *Expansion
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002617 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002618 EllipsisLoc,
2619 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002620 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2621 Expansion);
2622 break;
2623 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002624
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002625 return TemplateArgumentLoc();
2626 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002627
Douglas Gregor968f23a2011-01-03 19:31:53 +00002628 /// \brief Build a new expression pack expansion.
2629 ///
2630 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00002631 /// for an expression. Subclasses may override this routine to provide
Douglas Gregor968f23a2011-01-03 19:31:53 +00002632 /// different behavior.
Douglas Gregorb8840002011-01-14 21:20:45 +00002633 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002634 Optional<unsigned> NumExpansions) {
Douglas Gregorb8840002011-01-14 21:20:45 +00002635 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002636 }
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002637
2638 /// \brief Build a new atomic operation expression.
2639 ///
2640 /// By default, performs semantic analysis to build the new expression.
2641 /// Subclasses may override this routine to provide different behavior.
2642 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2643 MultiExprArg SubExprs,
2644 QualType RetTy,
2645 AtomicExpr::AtomicOp Op,
2646 SourceLocation RParenLoc) {
2647 // Just create the expression; there is not any interesting semantic
2648 // analysis here because we can't actually build an AtomicExpr until
2649 // we are sure it is semantically sound.
Benjamin Kramerc215e762012-08-24 11:54:20 +00002650 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002651 RParenLoc);
2652 }
2653
John McCall31f82722010-11-12 08:19:04 +00002654private:
Douglas Gregor14454802011-02-25 02:25:35 +00002655 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2656 QualType ObjectType,
2657 NamedDecl *FirstQualifierInScope,
2658 CXXScopeSpec &SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00002659
2660 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2661 QualType ObjectType,
2662 NamedDecl *FirstQualifierInScope,
2663 CXXScopeSpec &SS);
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00002664
2665 TypeSourceInfo *TransformTSIInObjectScope(TypeLoc TL, QualType ObjectType,
2666 NamedDecl *FirstQualifierInScope,
2667 CXXScopeSpec &SS);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002668};
Douglas Gregora16548e2009-08-11 05:31:07 +00002669
Douglas Gregorebe10102009-08-20 07:17:43 +00002670template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002671StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002672 if (!S)
2673 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00002674
Douglas Gregorebe10102009-08-20 07:17:43 +00002675 switch (S->getStmtClass()) {
2676 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00002677
Douglas Gregorebe10102009-08-20 07:17:43 +00002678 // Transform individual statement nodes
2679#define STMT(Node, Parent) \
2680 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCallbd066782011-02-09 08:16:59 +00002681#define ABSTRACT_STMT(Node)
Douglas Gregorebe10102009-08-20 07:17:43 +00002682#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00002683#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002684
Douglas Gregorebe10102009-08-20 07:17:43 +00002685 // Transform expressions by calling TransformExpr.
2686#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00002687#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00002688#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00002689#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00002690 {
John McCalldadc5752010-08-24 06:29:42 +00002691 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00002692 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002693 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002694
Richard Smith945f8d32013-01-14 22:39:08 +00002695 return getSema().ActOnExprStmt(E);
Douglas Gregorebe10102009-08-20 07:17:43 +00002696 }
Mike Stump11289f42009-09-09 15:08:12 +00002697 }
2698
John McCallc3007a22010-10-26 07:05:15 +00002699 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00002700}
Mike Stump11289f42009-09-09 15:08:12 +00002701
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00002702template<typename Derived>
2703OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) {
2704 if (!S)
2705 return S;
2706
2707 switch (S->getClauseKind()) {
2708 default: break;
2709 // Transform individual clause nodes
2710#define OPENMP_CLAUSE(Name, Class) \
2711 case OMPC_ ## Name : \
2712 return getDerived().Transform ## Class(cast<Class>(S));
2713#include "clang/Basic/OpenMPKinds.def"
2714 }
2715
2716 return S;
2717}
2718
Mike Stump11289f42009-09-09 15:08:12 +00002719
Douglas Gregore922c772009-08-04 22:27:00 +00002720template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002721ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002722 if (!E)
2723 return SemaRef.Owned(E);
2724
2725 switch (E->getStmtClass()) {
2726 case Stmt::NoStmtClass: break;
2727#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00002728#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00002729#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00002730 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00002731#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002732 }
2733
John McCallc3007a22010-10-26 07:05:15 +00002734 return SemaRef.Owned(E);
Douglas Gregor766b0bb2009-08-06 22:17:10 +00002735}
2736
2737template<typename Derived>
Richard Smithd59b8322012-12-19 01:39:02 +00002738ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
2739 bool CXXDirectInit) {
2740 // Initializers are instantiated like expressions, except that various outer
2741 // layers are stripped.
2742 if (!Init)
2743 return SemaRef.Owned(Init);
2744
2745 if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init))
2746 Init = ExprTemp->getSubExpr();
2747
Richard Smithe6ca4752013-05-30 22:40:16 +00002748 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
2749 Init = MTE->GetTemporaryExpr();
2750
Richard Smithd59b8322012-12-19 01:39:02 +00002751 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
2752 Init = Binder->getSubExpr();
2753
2754 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
2755 Init = ICE->getSubExprAsWritten();
2756
Richard Smithcc1b96d2013-06-12 22:31:48 +00002757 if (CXXStdInitializerListExpr *ILE =
2758 dyn_cast<CXXStdInitializerListExpr>(Init))
2759 return TransformInitializer(ILE->getSubExpr(), CXXDirectInit);
2760
Richard Smith38a549b2012-12-21 08:13:35 +00002761 // If this is not a direct-initializer, we only need to reconstruct
2762 // InitListExprs. Other forms of copy-initialization will be a no-op if
2763 // the initializer is already the right type.
2764 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
2765 if (!CXXDirectInit && !(Construct && Construct->isListInitialization()))
2766 return getDerived().TransformExpr(Init);
2767
2768 // Revert value-initialization back to empty parens.
2769 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
2770 SourceRange Parens = VIE->getSourceRange();
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002771 return getDerived().RebuildParenListExpr(Parens.getBegin(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00002772 Parens.getEnd());
2773 }
2774
2775 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
2776 if (isa<ImplicitValueInitExpr>(Init))
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002777 return getDerived().RebuildParenListExpr(SourceLocation(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00002778 SourceLocation());
2779
2780 // Revert initialization by constructor back to a parenthesized or braced list
2781 // of expressions. Any other form of initializer can just be reused directly.
2782 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
Richard Smithd59b8322012-12-19 01:39:02 +00002783 return getDerived().TransformExpr(Init);
2784
2785 SmallVector<Expr*, 8> NewArgs;
2786 bool ArgChanged = false;
2787 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
2788 /*IsCall*/true, NewArgs, &ArgChanged))
2789 return ExprError();
2790
2791 // If this was list initialization, revert to list form.
2792 if (Construct->isListInitialization())
2793 return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs,
2794 Construct->getLocEnd(),
2795 Construct->getType());
2796
Richard Smithd59b8322012-12-19 01:39:02 +00002797 // Build a ParenListExpr to represent anything else.
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00002798 SourceRange Parens = Construct->getParenOrBraceRange();
Richard Smithd59b8322012-12-19 01:39:02 +00002799 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
2800 Parens.getEnd());
2801}
2802
2803template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00002804bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2805 unsigned NumInputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00002806 bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +00002807 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00002808 bool *ArgChanged) {
2809 for (unsigned I = 0; I != NumInputs; ++I) {
2810 // If requested, drop call arguments that need to be dropped.
2811 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2812 if (ArgChanged)
2813 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002814
Douglas Gregora3efea12011-01-03 19:04:46 +00002815 break;
2816 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002817
Douglas Gregor968f23a2011-01-03 19:31:53 +00002818 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2819 Expr *Pattern = Expansion->getPattern();
Chad Rosier1dcde962012-08-08 18:46:20 +00002820
Chris Lattner01cf8db2011-07-20 06:58:45 +00002821 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor968f23a2011-01-03 19:31:53 +00002822 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2823 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00002824
Douglas Gregor968f23a2011-01-03 19:31:53 +00002825 // Determine whether the set of unexpanded parameter packs can and should
2826 // be expanded.
2827 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002828 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00002829 Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
2830 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor968f23a2011-01-03 19:31:53 +00002831 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2832 Pattern->getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00002833 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002834 Expand, RetainExpansion,
2835 NumExpansions))
Douglas Gregor968f23a2011-01-03 19:31:53 +00002836 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002837
Douglas Gregor968f23a2011-01-03 19:31:53 +00002838 if (!Expand) {
2839 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00002840 // transformation on the pack expansion, producing another pack
Douglas Gregor968f23a2011-01-03 19:31:53 +00002841 // expansion.
2842 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2843 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2844 if (OutPattern.isInvalid())
2845 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002846
2847 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregorb8840002011-01-14 21:20:45 +00002848 Expansion->getEllipsisLoc(),
2849 NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002850 if (Out.isInvalid())
2851 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002852
Douglas Gregor968f23a2011-01-03 19:31:53 +00002853 if (ArgChanged)
2854 *ArgChanged = true;
2855 Outputs.push_back(Out.get());
2856 continue;
2857 }
John McCall542e7c62011-07-06 07:30:07 +00002858
2859 // Record right away that the argument was changed. This needs
2860 // to happen even if the array expands to nothing.
2861 if (ArgChanged) *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002862
Douglas Gregor968f23a2011-01-03 19:31:53 +00002863 // The transform has determined that we should perform an elementwise
2864 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002865 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor968f23a2011-01-03 19:31:53 +00002866 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2867 ExprResult Out = getDerived().TransformExpr(Pattern);
2868 if (Out.isInvalid())
2869 return true;
2870
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002871 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregorb8840002011-01-14 21:20:45 +00002872 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2873 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002874 if (Out.isInvalid())
2875 return true;
2876 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002877
Douglas Gregor968f23a2011-01-03 19:31:53 +00002878 Outputs.push_back(Out.get());
2879 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002880
Douglas Gregor968f23a2011-01-03 19:31:53 +00002881 continue;
2882 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002883
Richard Smithd59b8322012-12-19 01:39:02 +00002884 ExprResult Result =
2885 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
2886 : getDerived().TransformExpr(Inputs[I]);
Douglas Gregora3efea12011-01-03 19:04:46 +00002887 if (Result.isInvalid())
2888 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002889
Douglas Gregora3efea12011-01-03 19:04:46 +00002890 if (Result.get() != Inputs[I] && ArgChanged)
2891 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002892
2893 Outputs.push_back(Result.get());
Douglas Gregora3efea12011-01-03 19:04:46 +00002894 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002895
Douglas Gregora3efea12011-01-03 19:04:46 +00002896 return false;
2897}
2898
2899template<typename Derived>
Douglas Gregor14454802011-02-25 02:25:35 +00002900NestedNameSpecifierLoc
2901TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2902 NestedNameSpecifierLoc NNS,
2903 QualType ObjectType,
2904 NamedDecl *FirstQualifierInScope) {
Chris Lattner01cf8db2011-07-20 06:58:45 +00002905 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier1dcde962012-08-08 18:46:20 +00002906 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregor14454802011-02-25 02:25:35 +00002907 Qualifier = Qualifier.getPrefix())
2908 Qualifiers.push_back(Qualifier);
2909
2910 CXXScopeSpec SS;
2911 while (!Qualifiers.empty()) {
2912 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2913 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier1dcde962012-08-08 18:46:20 +00002914
Douglas Gregor14454802011-02-25 02:25:35 +00002915 switch (QNNS->getKind()) {
2916 case NestedNameSpecifier::Identifier:
Chad Rosier1dcde962012-08-08 18:46:20 +00002917 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
Douglas Gregor14454802011-02-25 02:25:35 +00002918 *QNNS->getAsIdentifier(),
Chad Rosier1dcde962012-08-08 18:46:20 +00002919 Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00002920 Q.getLocalEndLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00002921 ObjectType, false, SS,
Douglas Gregor14454802011-02-25 02:25:35 +00002922 FirstQualifierInScope, false))
2923 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00002924
Douglas Gregor14454802011-02-25 02:25:35 +00002925 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00002926
Douglas Gregor14454802011-02-25 02:25:35 +00002927 case NestedNameSpecifier::Namespace: {
2928 NamespaceDecl *NS
2929 = cast_or_null<NamespaceDecl>(
2930 getDerived().TransformDecl(
2931 Q.getLocalBeginLoc(),
2932 QNNS->getAsNamespace()));
2933 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2934 break;
2935 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002936
Douglas Gregor14454802011-02-25 02:25:35 +00002937 case NestedNameSpecifier::NamespaceAlias: {
2938 NamespaceAliasDecl *Alias
2939 = cast_or_null<NamespaceAliasDecl>(
2940 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2941 QNNS->getAsNamespaceAlias()));
Chad Rosier1dcde962012-08-08 18:46:20 +00002942 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00002943 Q.getLocalEndLoc());
2944 break;
2945 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002946
Douglas Gregor14454802011-02-25 02:25:35 +00002947 case NestedNameSpecifier::Global:
2948 // There is no meaningful transformation that one could perform on the
2949 // global scope.
2950 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2951 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00002952
Douglas Gregor14454802011-02-25 02:25:35 +00002953 case NestedNameSpecifier::TypeSpecWithTemplate:
2954 case NestedNameSpecifier::TypeSpec: {
2955 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2956 FirstQualifierInScope, SS);
Chad Rosier1dcde962012-08-08 18:46:20 +00002957
Douglas Gregor14454802011-02-25 02:25:35 +00002958 if (!TL)
2959 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00002960
Douglas Gregor14454802011-02-25 02:25:35 +00002961 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Richard Smith2bf7fdb2013-01-02 11:42:31 +00002962 (SemaRef.getLangOpts().CPlusPlus11 &&
Douglas Gregor14454802011-02-25 02:25:35 +00002963 TL.getType()->isEnumeralType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002964 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregor14454802011-02-25 02:25:35 +00002965 "Can't get cv-qualifiers here");
Richard Smith91c7bbd2011-10-20 03:28:47 +00002966 if (TL.getType()->isEnumeralType())
2967 SemaRef.Diag(TL.getBeginLoc(),
2968 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregor14454802011-02-25 02:25:35 +00002969 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2970 Q.getLocalEndLoc());
2971 break;
2972 }
Richard Trieude756fb2011-05-07 01:36:37 +00002973 // If the nested-name-specifier is an invalid type def, don't emit an
2974 // error because a previous error should have already been emitted.
David Blaikie6adc78e2013-02-18 22:06:02 +00002975 TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
2976 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002977 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieude756fb2011-05-07 01:36:37 +00002978 << TL.getType() << SS.getRange();
2979 }
Douglas Gregor14454802011-02-25 02:25:35 +00002980 return NestedNameSpecifierLoc();
2981 }
Douglas Gregore16af532011-02-28 18:50:33 +00002982 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002983
Douglas Gregore16af532011-02-28 18:50:33 +00002984 // The qualifier-in-scope and object type only apply to the leftmost entity.
Douglas Gregor14454802011-02-25 02:25:35 +00002985 FirstQualifierInScope = 0;
Douglas Gregore16af532011-02-28 18:50:33 +00002986 ObjectType = QualType();
Douglas Gregor14454802011-02-25 02:25:35 +00002987 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002988
Douglas Gregor14454802011-02-25 02:25:35 +00002989 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier1dcde962012-08-08 18:46:20 +00002990 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregor14454802011-02-25 02:25:35 +00002991 !getDerived().AlwaysRebuild())
2992 return NNS;
Chad Rosier1dcde962012-08-08 18:46:20 +00002993
2994 // If we can re-use the source-location data from the original
Douglas Gregor14454802011-02-25 02:25:35 +00002995 // nested-name-specifier, do so.
2996 if (SS.location_size() == NNS.getDataLength() &&
2997 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2998 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
2999
3000 // Allocate new nested-name-specifier location information.
3001 return SS.getWithLocInContext(SemaRef.Context);
3002}
3003
3004template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003005DeclarationNameInfo
3006TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00003007::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003008 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003009 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003010 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003011
3012 switch (Name.getNameKind()) {
3013 case DeclarationName::Identifier:
3014 case DeclarationName::ObjCZeroArgSelector:
3015 case DeclarationName::ObjCOneArgSelector:
3016 case DeclarationName::ObjCMultiArgSelector:
3017 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00003018 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00003019 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003020 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00003021
Douglas Gregorf816bd72009-09-03 22:13:48 +00003022 case DeclarationName::CXXConstructorName:
3023 case DeclarationName::CXXDestructorName:
3024 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003025 TypeSourceInfo *NewTInfo;
3026 CanQualType NewCanTy;
3027 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00003028 NewTInfo = getDerived().TransformType(OldTInfo);
3029 if (!NewTInfo)
3030 return DeclarationNameInfo();
3031 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003032 }
3033 else {
3034 NewTInfo = 0;
3035 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00003036 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003037 if (NewT.isNull())
3038 return DeclarationNameInfo();
3039 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
3040 }
Mike Stump11289f42009-09-09 15:08:12 +00003041
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003042 DeclarationName NewName
3043 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
3044 NewCanTy);
3045 DeclarationNameInfo NewNameInfo(NameInfo);
3046 NewNameInfo.setName(NewName);
3047 NewNameInfo.setNamedTypeInfo(NewTInfo);
3048 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00003049 }
Mike Stump11289f42009-09-09 15:08:12 +00003050 }
3051
David Blaikie83d382b2011-09-23 05:06:16 +00003052 llvm_unreachable("Unknown name kind.");
Douglas Gregorf816bd72009-09-03 22:13:48 +00003053}
3054
3055template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003056TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00003057TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
3058 TemplateName Name,
3059 SourceLocation NameLoc,
3060 QualType ObjectType,
3061 NamedDecl *FirstQualifierInScope) {
3062 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
3063 TemplateDecl *Template = QTN->getTemplateDecl();
3064 assert(Template && "qualified template name must refer to a template");
Chad Rosier1dcde962012-08-08 18:46:20 +00003065
Douglas Gregor9db53502011-03-02 18:07:45 +00003066 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003067 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003068 Template));
3069 if (!TransTemplate)
3070 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003071
Douglas Gregor9db53502011-03-02 18:07:45 +00003072 if (!getDerived().AlwaysRebuild() &&
3073 SS.getScopeRep() == QTN->getQualifier() &&
3074 TransTemplate == Template)
3075 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003076
Douglas Gregor9db53502011-03-02 18:07:45 +00003077 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
3078 TransTemplate);
3079 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003080
Douglas Gregor9db53502011-03-02 18:07:45 +00003081 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
3082 if (SS.getScopeRep()) {
3083 // These apply to the scope specifier, not the template.
3084 ObjectType = QualType();
3085 FirstQualifierInScope = 0;
Chad Rosier1dcde962012-08-08 18:46:20 +00003086 }
3087
Douglas Gregor9db53502011-03-02 18:07:45 +00003088 if (!getDerived().AlwaysRebuild() &&
3089 SS.getScopeRep() == DTN->getQualifier() &&
3090 ObjectType.isNull())
3091 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003092
Douglas Gregor9db53502011-03-02 18:07:45 +00003093 if (DTN->isIdentifier()) {
3094 return getDerived().RebuildTemplateName(SS,
Chad Rosier1dcde962012-08-08 18:46:20 +00003095 *DTN->getIdentifier(),
Douglas Gregor9db53502011-03-02 18:07:45 +00003096 NameLoc,
3097 ObjectType,
3098 FirstQualifierInScope);
3099 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003100
Douglas Gregor9db53502011-03-02 18:07:45 +00003101 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
3102 ObjectType);
3103 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003104
Douglas Gregor9db53502011-03-02 18:07:45 +00003105 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
3106 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003107 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003108 Template));
3109 if (!TransTemplate)
3110 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003111
Douglas Gregor9db53502011-03-02 18:07:45 +00003112 if (!getDerived().AlwaysRebuild() &&
3113 TransTemplate == Template)
3114 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003115
Douglas Gregor9db53502011-03-02 18:07:45 +00003116 return TemplateName(TransTemplate);
3117 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003118
Douglas Gregor9db53502011-03-02 18:07:45 +00003119 if (SubstTemplateTemplateParmPackStorage *SubstPack
3120 = Name.getAsSubstTemplateTemplateParmPack()) {
3121 TemplateTemplateParmDecl *TransParam
3122 = cast_or_null<TemplateTemplateParmDecl>(
3123 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
3124 if (!TransParam)
3125 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003126
Douglas Gregor9db53502011-03-02 18:07:45 +00003127 if (!getDerived().AlwaysRebuild() &&
3128 TransParam == SubstPack->getParameterPack())
3129 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003130
3131 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregor9db53502011-03-02 18:07:45 +00003132 SubstPack->getArgumentPack());
3133 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003134
Douglas Gregor9db53502011-03-02 18:07:45 +00003135 // These should be getting filtered out before they reach the AST.
3136 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregor9db53502011-03-02 18:07:45 +00003137}
3138
3139template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003140void TreeTransform<Derived>::InventTemplateArgumentLoc(
3141 const TemplateArgument &Arg,
3142 TemplateArgumentLoc &Output) {
3143 SourceLocation Loc = getDerived().getBaseLocation();
3144 switch (Arg.getKind()) {
3145 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003146 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00003147 break;
3148
3149 case TemplateArgument::Type:
3150 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00003151 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier1dcde962012-08-08 18:46:20 +00003152
John McCall0ad16662009-10-29 08:12:44 +00003153 break;
3154
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003155 case TemplateArgument::Template:
Douglas Gregor9d802122011-03-02 17:09:35 +00003156 case TemplateArgument::TemplateExpansion: {
3157 NestedNameSpecifierLocBuilder Builder;
3158 TemplateName Template = Arg.getAsTemplate();
3159 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3160 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3161 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3162 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003163
Douglas Gregor9d802122011-03-02 17:09:35 +00003164 if (Arg.getKind() == TemplateArgument::Template)
Chad Rosier1dcde962012-08-08 18:46:20 +00003165 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003166 Builder.getWithLocInContext(SemaRef.Context),
3167 Loc);
3168 else
Chad Rosier1dcde962012-08-08 18:46:20 +00003169 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003170 Builder.getWithLocInContext(SemaRef.Context),
3171 Loc, Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003172
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003173 break;
Douglas Gregor9d802122011-03-02 17:09:35 +00003174 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003175
John McCall0ad16662009-10-29 08:12:44 +00003176 case TemplateArgument::Expression:
3177 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3178 break;
3179
3180 case TemplateArgument::Declaration:
3181 case TemplateArgument::Integral:
3182 case TemplateArgument::Pack:
Eli Friedmanb826a002012-09-26 02:36:12 +00003183 case TemplateArgument::NullPtr:
John McCall0d07eb32009-10-29 18:45:58 +00003184 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00003185 break;
3186 }
3187}
3188
3189template<typename Derived>
3190bool TreeTransform<Derived>::TransformTemplateArgument(
3191 const TemplateArgumentLoc &Input,
3192 TemplateArgumentLoc &Output) {
3193 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00003194 switch (Arg.getKind()) {
3195 case TemplateArgument::Null:
3196 case TemplateArgument::Integral:
Eli Friedmancda3db82012-09-25 01:02:42 +00003197 case TemplateArgument::Pack:
3198 case TemplateArgument::Declaration:
Eli Friedmanb826a002012-09-26 02:36:12 +00003199 case TemplateArgument::NullPtr:
3200 llvm_unreachable("Unexpected TemplateArgument");
Mike Stump11289f42009-09-09 15:08:12 +00003201
Douglas Gregore922c772009-08-04 22:27:00 +00003202 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00003203 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall0ad16662009-10-29 08:12:44 +00003204 if (DI == NULL)
John McCallbcd03502009-12-07 02:54:59 +00003205 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00003206
3207 DI = getDerived().TransformType(DI);
3208 if (!DI) return true;
3209
3210 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3211 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003212 }
Mike Stump11289f42009-09-09 15:08:12 +00003213
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003214 case TemplateArgument::Template: {
Douglas Gregor9d802122011-03-02 17:09:35 +00003215 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3216 if (QualifierLoc) {
3217 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3218 if (!QualifierLoc)
3219 return true;
3220 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003221
Douglas Gregordf846d12011-03-02 18:46:51 +00003222 CXXScopeSpec SS;
3223 SS.Adopt(QualifierLoc);
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003224 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00003225 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3226 Input.getTemplateNameLoc());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003227 if (Template.isNull())
3228 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003229
Douglas Gregor9d802122011-03-02 17:09:35 +00003230 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003231 Input.getTemplateNameLoc());
3232 return false;
3233 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003234
3235 case TemplateArgument::TemplateExpansion:
3236 llvm_unreachable("Caller should expand pack expansions");
3237
Douglas Gregore922c772009-08-04 22:27:00 +00003238 case TemplateArgument::Expression: {
Richard Smith764d2fe2011-12-20 02:08:33 +00003239 // Template argument expressions are constant expressions.
Mike Stump11289f42009-09-09 15:08:12 +00003240 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smith764d2fe2011-12-20 02:08:33 +00003241 Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003242
John McCall0ad16662009-10-29 08:12:44 +00003243 Expr *InputExpr = Input.getSourceExpression();
3244 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3245
Chris Lattnercdb591a2011-04-25 20:37:58 +00003246 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanc6237c62012-02-29 03:16:56 +00003247 E = SemaRef.ActOnConstantExpression(E);
John McCall0ad16662009-10-29 08:12:44 +00003248 if (E.isInvalid()) return true;
John McCallb268a282010-08-23 23:25:46 +00003249 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall0ad16662009-10-29 08:12:44 +00003250 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003251 }
Douglas Gregore922c772009-08-04 22:27:00 +00003252 }
Mike Stump11289f42009-09-09 15:08:12 +00003253
Douglas Gregore922c772009-08-04 22:27:00 +00003254 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00003255 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00003256}
3257
Douglas Gregorfe921a72010-12-20 23:36:19 +00003258/// \brief Iterator adaptor that invents template argument location information
3259/// for each of the template arguments in its underlying iterator.
3260template<typename Derived, typename InputIterator>
3261class TemplateArgumentLocInventIterator {
3262 TreeTransform<Derived> &Self;
3263 InputIterator Iter;
Chad Rosier1dcde962012-08-08 18:46:20 +00003264
Douglas Gregorfe921a72010-12-20 23:36:19 +00003265public:
3266 typedef TemplateArgumentLoc value_type;
3267 typedef TemplateArgumentLoc reference;
3268 typedef typename std::iterator_traits<InputIterator>::difference_type
3269 difference_type;
3270 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00003271
Douglas Gregorfe921a72010-12-20 23:36:19 +00003272 class pointer {
3273 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00003274
Douglas Gregorfe921a72010-12-20 23:36:19 +00003275 public:
3276 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003277
Douglas Gregorfe921a72010-12-20 23:36:19 +00003278 const TemplateArgumentLoc *operator->() const { return &Arg; }
3279 };
Chad Rosier1dcde962012-08-08 18:46:20 +00003280
Douglas Gregorfe921a72010-12-20 23:36:19 +00003281 TemplateArgumentLocInventIterator() { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003282
Douglas Gregorfe921a72010-12-20 23:36:19 +00003283 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3284 InputIterator Iter)
3285 : Self(Self), Iter(Iter) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003286
Douglas Gregorfe921a72010-12-20 23:36:19 +00003287 TemplateArgumentLocInventIterator &operator++() {
3288 ++Iter;
3289 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00003290 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003291
Douglas Gregorfe921a72010-12-20 23:36:19 +00003292 TemplateArgumentLocInventIterator operator++(int) {
3293 TemplateArgumentLocInventIterator Old(*this);
3294 ++(*this);
3295 return Old;
3296 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003297
Douglas Gregorfe921a72010-12-20 23:36:19 +00003298 reference operator*() const {
3299 TemplateArgumentLoc Result;
3300 Self.InventTemplateArgumentLoc(*Iter, Result);
3301 return Result;
3302 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003303
Douglas Gregorfe921a72010-12-20 23:36:19 +00003304 pointer operator->() const { return pointer(**this); }
Chad Rosier1dcde962012-08-08 18:46:20 +00003305
Douglas Gregorfe921a72010-12-20 23:36:19 +00003306 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3307 const TemplateArgumentLocInventIterator &Y) {
3308 return X.Iter == Y.Iter;
3309 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00003310
Douglas Gregorfe921a72010-12-20 23:36:19 +00003311 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3312 const TemplateArgumentLocInventIterator &Y) {
3313 return X.Iter != Y.Iter;
3314 }
3315};
Chad Rosier1dcde962012-08-08 18:46:20 +00003316
Douglas Gregor42cafa82010-12-20 17:42:22 +00003317template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00003318template<typename InputIterator>
3319bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3320 InputIterator Last,
Douglas Gregor42cafa82010-12-20 17:42:22 +00003321 TemplateArgumentListInfo &Outputs) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00003322 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00003323 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00003324 TemplateArgumentLoc In = *First;
Chad Rosier1dcde962012-08-08 18:46:20 +00003325
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003326 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3327 // Unpack argument packs, which we translate them into separate
3328 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00003329 // FIXME: We could do much better if we could guarantee that the
3330 // TemplateArgumentLocInfo for the pack expansion would be usable for
3331 // all of the template arguments in the argument pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00003332 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003333 TemplateArgument::pack_iterator>
3334 PackLocIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00003335 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003336 In.getArgument().pack_begin()),
3337 PackLocIterator(*this,
3338 In.getArgument().pack_end()),
3339 Outputs))
3340 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003341
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003342 continue;
3343 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003344
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003345 if (In.getArgument().isPackExpansion()) {
3346 // We have a pack expansion, for which we will be substituting into
3347 // the pattern.
3348 SourceLocation Ellipsis;
David Blaikie05785d12013-02-20 22:23:23 +00003349 Optional<unsigned> OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003350 TemplateArgumentLoc Pattern
Eli Friedman94e9eaa2013-06-20 04:11:21 +00003351 = getSema().getTemplateArgumentPackExpansionPattern(
3352 In, Ellipsis, OrigNumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00003353
Chris Lattner01cf8db2011-07-20 06:58:45 +00003354 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003355 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3356 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00003357
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003358 // Determine whether the set of unexpanded parameter packs can and should
3359 // be expanded.
3360 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003361 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00003362 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003363 if (getDerived().TryExpandParameterPacks(Ellipsis,
3364 Pattern.getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003365 Unexpanded,
Chad Rosier1dcde962012-08-08 18:46:20 +00003366 Expand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003367 RetainExpansion,
3368 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003369 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003370
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003371 if (!Expand) {
3372 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00003373 // transformation on the pack expansion, producing another pack
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003374 // expansion.
3375 TemplateArgumentLoc OutPattern;
3376 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3377 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3378 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003379
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003380 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3381 NumExpansions);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003382 if (Out.getArgument().isNull())
3383 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003384
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003385 Outputs.addArgument(Out);
3386 continue;
3387 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003388
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003389 // The transform has determined that we should perform an elementwise
3390 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003391 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003392 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3393
3394 if (getDerived().TransformTemplateArgument(Pattern, Out))
3395 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003396
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003397 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003398 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3399 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003400 if (Out.getArgument().isNull())
3401 return true;
3402 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003403
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003404 Outputs.addArgument(Out);
3405 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003406
Douglas Gregor48d24112011-01-10 20:53:55 +00003407 // If we're supposed to retain a pack expansion, do so by temporarily
3408 // forgetting the partially-substituted parameter pack.
3409 if (RetainExpansion) {
3410 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00003411
Douglas Gregor48d24112011-01-10 20:53:55 +00003412 if (getDerived().TransformTemplateArgument(Pattern, Out))
3413 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003414
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003415 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3416 OrigNumExpansions);
Douglas Gregor48d24112011-01-10 20:53:55 +00003417 if (Out.getArgument().isNull())
3418 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003419
Douglas Gregor48d24112011-01-10 20:53:55 +00003420 Outputs.addArgument(Out);
3421 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003422
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003423 continue;
3424 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003425
3426 // The simple case:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003427 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor42cafa82010-12-20 17:42:22 +00003428 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003429
Douglas Gregor42cafa82010-12-20 17:42:22 +00003430 Outputs.addArgument(Out);
3431 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003432
Douglas Gregor42cafa82010-12-20 17:42:22 +00003433 return false;
3434
3435}
3436
Douglas Gregord6ff3322009-08-04 16:50:30 +00003437//===----------------------------------------------------------------------===//
3438// Type transformation
3439//===----------------------------------------------------------------------===//
3440
3441template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003442QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00003443 if (getDerived().AlreadyTransformed(T))
3444 return T;
Mike Stump11289f42009-09-09 15:08:12 +00003445
John McCall550e0c22009-10-21 00:40:46 +00003446 // Temporary workaround. All of these transformations should
3447 // eventually turn into transformations on TypeLocs.
Douglas Gregor2d525f02011-01-25 19:13:18 +00003448 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3449 getDerived().getBaseLocation());
Chad Rosier1dcde962012-08-08 18:46:20 +00003450
John McCall31f82722010-11-12 08:19:04 +00003451 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00003452
John McCall550e0c22009-10-21 00:40:46 +00003453 if (!NewDI)
3454 return QualType();
3455
3456 return NewDI->getType();
3457}
3458
3459template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003460TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smith764d2fe2011-12-20 02:08:33 +00003461 // Refine the base location to the type's location.
3462 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3463 getDerived().getBaseEntity());
John McCall550e0c22009-10-21 00:40:46 +00003464 if (getDerived().AlreadyTransformed(DI->getType()))
3465 return DI;
3466
3467 TypeLocBuilder TLB;
3468
3469 TypeLoc TL = DI->getTypeLoc();
3470 TLB.reserve(TL.getFullDataSize());
3471
John McCall31f82722010-11-12 08:19:04 +00003472 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00003473 if (Result.isNull())
3474 return 0;
3475
John McCallbcd03502009-12-07 02:54:59 +00003476 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00003477}
3478
3479template<typename Derived>
3480QualType
John McCall31f82722010-11-12 08:19:04 +00003481TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003482 switch (T.getTypeLocClass()) {
3483#define ABSTRACT_TYPELOC(CLASS, PARENT)
David Blaikie6adc78e2013-02-18 22:06:02 +00003484#define TYPELOC(CLASS, PARENT) \
3485 case TypeLoc::CLASS: \
3486 return getDerived().Transform##CLASS##Type(TLB, \
3487 T.castAs<CLASS##TypeLoc>());
John McCall550e0c22009-10-21 00:40:46 +00003488#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00003489 }
Mike Stump11289f42009-09-09 15:08:12 +00003490
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003491 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00003492}
3493
3494/// FIXME: By default, this routine adds type qualifiers only to types
3495/// that can have qualifiers, and silently suppresses those qualifiers
3496/// that are not permitted (e.g., qualifiers on reference or function
3497/// types). This is the right thing for template instantiation, but
3498/// probably not for other clients.
3499template<typename Derived>
3500QualType
3501TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003502 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00003503 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00003504
John McCall31f82722010-11-12 08:19:04 +00003505 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00003506 if (Result.isNull())
3507 return QualType();
3508
3509 // Silently suppress qualifiers if the result type can't be qualified.
3510 // FIXME: this is the right thing for template instantiation, but
3511 // probably not for other clients.
3512 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00003513 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00003514
John McCall31168b02011-06-15 23:02:42 +00003515 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore46db902011-06-17 22:11:49 +00003516 // resulting type.
3517 if (Quals.hasObjCLifetime()) {
3518 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3519 Quals.removeObjCLifetime();
Douglas Gregord7357a92011-06-17 23:16:24 +00003520 else if (Result.getObjCLifetime()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003521 // Objective-C ARC:
Douglas Gregore46db902011-06-17 22:11:49 +00003522 // A lifetime qualifier applied to a substituted template parameter
3523 // overrides the lifetime qualifier from the template argument.
Douglas Gregorf4e43312013-01-17 23:59:28 +00003524 const AutoType *AutoTy;
Chad Rosier1dcde962012-08-08 18:46:20 +00003525 if (const SubstTemplateTypeParmType *SubstTypeParam
Douglas Gregore46db902011-06-17 22:11:49 +00003526 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3527 QualType Replacement = SubstTypeParam->getReplacementType();
3528 Qualifiers Qs = Replacement.getQualifiers();
3529 Qs.removeObjCLifetime();
Chad Rosier1dcde962012-08-08 18:46:20 +00003530 Replacement
Douglas Gregore46db902011-06-17 22:11:49 +00003531 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3532 Qs);
3533 Result = SemaRef.Context.getSubstTemplateTypeParmType(
Chad Rosier1dcde962012-08-08 18:46:20 +00003534 SubstTypeParam->getReplacedParameter(),
Douglas Gregore46db902011-06-17 22:11:49 +00003535 Replacement);
3536 TLB.TypeWasModifiedSafely(Result);
Douglas Gregorf4e43312013-01-17 23:59:28 +00003537 } else if ((AutoTy = dyn_cast<AutoType>(Result)) && AutoTy->isDeduced()) {
3538 // 'auto' types behave the same way as template parameters.
3539 QualType Deduced = AutoTy->getDeducedType();
3540 Qualifiers Qs = Deduced.getQualifiers();
3541 Qs.removeObjCLifetime();
3542 Deduced = SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(),
3543 Qs);
Faisal Vali2b391ab2013-09-26 19:54:12 +00003544 Result = SemaRef.Context.getAutoType(Deduced, AutoTy->isDecltypeAuto(),
3545 AutoTy->isDependentType());
Douglas Gregorf4e43312013-01-17 23:59:28 +00003546 TLB.TypeWasModifiedSafely(Result);
Douglas Gregore46db902011-06-17 22:11:49 +00003547 } else {
Douglas Gregord7357a92011-06-17 23:16:24 +00003548 // Otherwise, complain about the addition of a qualifier to an
3549 // already-qualified type.
Eli Friedman7152fbe2013-06-07 20:31:48 +00003550 SourceRange R = T.getUnqualifiedLoc().getSourceRange();
Argyrios Kyrtzidiscff00d92011-06-24 00:08:59 +00003551 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregord7357a92011-06-17 23:16:24 +00003552 << Result << R;
Chad Rosier1dcde962012-08-08 18:46:20 +00003553
Douglas Gregore46db902011-06-17 22:11:49 +00003554 Quals.removeObjCLifetime();
3555 }
3556 }
3557 }
John McCallcb0f89a2010-06-05 06:41:15 +00003558 if (!Quals.empty()) {
3559 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
Richard Smithdeec0742013-03-27 23:36:39 +00003560 // BuildQualifiedType might not add qualifiers if they are invalid.
3561 if (Result.hasLocalQualifiers())
3562 TLB.push<QualifiedTypeLoc>(Result);
John McCallcb0f89a2010-06-05 06:41:15 +00003563 // No location information to preserve.
3564 }
John McCall550e0c22009-10-21 00:40:46 +00003565
3566 return Result;
3567}
3568
Douglas Gregor14454802011-02-25 02:25:35 +00003569template<typename Derived>
3570TypeLoc
3571TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3572 QualType ObjectType,
3573 NamedDecl *UnqualLookup,
3574 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003575 if (getDerived().AlreadyTransformed(TL.getType()))
Douglas Gregor14454802011-02-25 02:25:35 +00003576 return TL;
Chad Rosier1dcde962012-08-08 18:46:20 +00003577
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003578 TypeSourceInfo *TSI =
3579 TransformTSIInObjectScope(TL, ObjectType, UnqualLookup, SS);
3580 if (TSI)
3581 return TSI->getTypeLoc();
3582 return TypeLoc();
Douglas Gregor14454802011-02-25 02:25:35 +00003583}
3584
Douglas Gregor579c15f2011-03-02 18:32:08 +00003585template<typename Derived>
3586TypeSourceInfo *
3587TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3588 QualType ObjectType,
3589 NamedDecl *UnqualLookup,
3590 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003591 if (getDerived().AlreadyTransformed(TSInfo->getType()))
Douglas Gregor579c15f2011-03-02 18:32:08 +00003592 return TSInfo;
Chad Rosier1dcde962012-08-08 18:46:20 +00003593
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003594 return TransformTSIInObjectScope(TSInfo->getTypeLoc(), ObjectType,
3595 UnqualLookup, SS);
3596}
3597
3598template <typename Derived>
3599TypeSourceInfo *TreeTransform<Derived>::TransformTSIInObjectScope(
3600 TypeLoc TL, QualType ObjectType, NamedDecl *UnqualLookup,
3601 CXXScopeSpec &SS) {
3602 QualType T = TL.getType();
3603 assert(!getDerived().AlreadyTransformed(T));
3604
Douglas Gregor579c15f2011-03-02 18:32:08 +00003605 TypeLocBuilder TLB;
3606 QualType Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00003607
Douglas Gregor579c15f2011-03-02 18:32:08 +00003608 if (isa<TemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00003609 TemplateSpecializationTypeLoc SpecTL =
3610 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00003611
Douglas Gregor579c15f2011-03-02 18:32:08 +00003612 TemplateName Template
3613 = getDerived().TransformTemplateName(SS,
3614 SpecTL.getTypePtr()->getTemplateName(),
3615 SpecTL.getTemplateNameLoc(),
3616 ObjectType, UnqualLookup);
Chad Rosier1dcde962012-08-08 18:46:20 +00003617 if (Template.isNull())
Douglas Gregor579c15f2011-03-02 18:32:08 +00003618 return 0;
Chad Rosier1dcde962012-08-08 18:46:20 +00003619
3620 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregor579c15f2011-03-02 18:32:08 +00003621 Template);
3622 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00003623 DependentTemplateSpecializationTypeLoc SpecTL =
3624 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00003625
Douglas Gregor579c15f2011-03-02 18:32:08 +00003626 TemplateName Template
Chad Rosier1dcde962012-08-08 18:46:20 +00003627 = getDerived().RebuildTemplateName(SS,
3628 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00003629 SpecTL.getTemplateNameLoc(),
Douglas Gregor579c15f2011-03-02 18:32:08 +00003630 ObjectType, UnqualLookup);
3631 if (Template.isNull())
3632 return 0;
Chad Rosier1dcde962012-08-08 18:46:20 +00003633
3634 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregor579c15f2011-03-02 18:32:08 +00003635 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00003636 Template,
3637 SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00003638 } else {
3639 // Nothing special needs to be done for these.
3640 Result = getDerived().TransformType(TLB, TL);
3641 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003642
3643 if (Result.isNull())
Douglas Gregor579c15f2011-03-02 18:32:08 +00003644 return 0;
Chad Rosier1dcde962012-08-08 18:46:20 +00003645
Douglas Gregor579c15f2011-03-02 18:32:08 +00003646 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3647}
3648
John McCall550e0c22009-10-21 00:40:46 +00003649template <class TyLoc> static inline
3650QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3651 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3652 NewT.setNameLoc(T.getNameLoc());
3653 return T.getType();
3654}
3655
John McCall550e0c22009-10-21 00:40:46 +00003656template<typename Derived>
3657QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003658 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00003659 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3660 NewT.setBuiltinLoc(T.getBuiltinLoc());
3661 if (T.needsExtraLocalData())
3662 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3663 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003664}
Mike Stump11289f42009-09-09 15:08:12 +00003665
Douglas Gregord6ff3322009-08-04 16:50:30 +00003666template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003667QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003668 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003669 // FIXME: recurse?
3670 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003671}
Mike Stump11289f42009-09-09 15:08:12 +00003672
Reid Kleckner0503a872013-12-05 01:23:43 +00003673template <typename Derived>
3674QualType TreeTransform<Derived>::TransformAdjustedType(TypeLocBuilder &TLB,
3675 AdjustedTypeLoc TL) {
3676 // Adjustments applied during transformation are handled elsewhere.
3677 return getDerived().TransformType(TLB, TL.getOriginalLoc());
3678}
3679
Douglas Gregord6ff3322009-08-04 16:50:30 +00003680template<typename Derived>
Reid Kleckner8a365022013-06-24 17:51:48 +00003681QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
3682 DecayedTypeLoc TL) {
3683 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
3684 if (OriginalType.isNull())
3685 return QualType();
3686
3687 QualType Result = TL.getType();
3688 if (getDerived().AlwaysRebuild() ||
3689 OriginalType != TL.getOriginalLoc().getType())
3690 Result = SemaRef.Context.getDecayedType(OriginalType);
3691 TLB.push<DecayedTypeLoc>(Result);
3692 // Nothing to set for DecayedTypeLoc.
3693 return Result;
3694}
3695
3696template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003697QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003698 PointerTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003699 QualType PointeeType
3700 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003701 if (PointeeType.isNull())
3702 return QualType();
3703
3704 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00003705 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003706 // A dependent pointer type 'T *' has is being transformed such
3707 // that an Objective-C class type is being replaced for 'T'. The
3708 // resulting pointer type is an ObjCObjectPointerType, not a
3709 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00003710 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier1dcde962012-08-08 18:46:20 +00003711
John McCall8b07ec22010-05-15 11:32:37 +00003712 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3713 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003714 return Result;
3715 }
John McCall31f82722010-11-12 08:19:04 +00003716
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003717 if (getDerived().AlwaysRebuild() ||
3718 PointeeType != TL.getPointeeLoc().getType()) {
3719 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3720 if (Result.isNull())
3721 return QualType();
3722 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003723
John McCall31168b02011-06-15 23:02:42 +00003724 // Objective-C ARC can add lifetime qualifiers to the type that we're
3725 // pointing to.
3726 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier1dcde962012-08-08 18:46:20 +00003727
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003728 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3729 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00003730 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003731}
Mike Stump11289f42009-09-09 15:08:12 +00003732
3733template<typename Derived>
3734QualType
John McCall550e0c22009-10-21 00:40:46 +00003735TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003736 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00003737 QualType PointeeType
Chad Rosier1dcde962012-08-08 18:46:20 +00003738 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3739 if (PointeeType.isNull())
3740 return QualType();
3741
3742 QualType Result = TL.getType();
3743 if (getDerived().AlwaysRebuild() ||
3744 PointeeType != TL.getPointeeLoc().getType()) {
3745 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00003746 TL.getSigilLoc());
3747 if (Result.isNull())
3748 return QualType();
3749 }
3750
Douglas Gregor049211a2010-04-22 16:50:51 +00003751 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00003752 NewT.setSigilLoc(TL.getSigilLoc());
3753 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003754}
3755
John McCall70dd5f62009-10-30 00:06:24 +00003756/// Transforms a reference type. Note that somewhat paradoxically we
3757/// don't care whether the type itself is an l-value type or an r-value
3758/// type; we only care if the type was *written* as an l-value type
3759/// or an r-value type.
3760template<typename Derived>
3761QualType
3762TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003763 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00003764 const ReferenceType *T = TL.getTypePtr();
3765
3766 // Note that this works with the pointee-as-written.
3767 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3768 if (PointeeType.isNull())
3769 return QualType();
3770
3771 QualType Result = TL.getType();
3772 if (getDerived().AlwaysRebuild() ||
3773 PointeeType != T->getPointeeTypeAsWritten()) {
3774 Result = getDerived().RebuildReferenceType(PointeeType,
3775 T->isSpelledAsLValue(),
3776 TL.getSigilLoc());
3777 if (Result.isNull())
3778 return QualType();
3779 }
3780
John McCall31168b02011-06-15 23:02:42 +00003781 // Objective-C ARC can add lifetime qualifiers to the type that we're
3782 // referring to.
3783 TLB.TypeWasModifiedSafely(
3784 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3785
John McCall70dd5f62009-10-30 00:06:24 +00003786 // r-value references can be rebuilt as l-value references.
3787 ReferenceTypeLoc NewTL;
3788 if (isa<LValueReferenceType>(Result))
3789 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3790 else
3791 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3792 NewTL.setSigilLoc(TL.getSigilLoc());
3793
3794 return Result;
3795}
3796
Mike Stump11289f42009-09-09 15:08:12 +00003797template<typename Derived>
3798QualType
John McCall550e0c22009-10-21 00:40:46 +00003799TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003800 LValueReferenceTypeLoc TL) {
3801 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003802}
3803
Mike Stump11289f42009-09-09 15:08:12 +00003804template<typename Derived>
3805QualType
John McCall550e0c22009-10-21 00:40:46 +00003806TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003807 RValueReferenceTypeLoc TL) {
3808 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003809}
Mike Stump11289f42009-09-09 15:08:12 +00003810
Douglas Gregord6ff3322009-08-04 16:50:30 +00003811template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003812QualType
John McCall550e0c22009-10-21 00:40:46 +00003813TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003814 MemberPointerTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003815 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003816 if (PointeeType.isNull())
3817 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003818
Abramo Bagnara509357842011-03-05 14:42:21 +00003819 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
3820 TypeSourceInfo* NewClsTInfo = 0;
3821 if (OldClsTInfo) {
3822 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3823 if (!NewClsTInfo)
3824 return QualType();
3825 }
3826
3827 const MemberPointerType *T = TL.getTypePtr();
3828 QualType OldClsType = QualType(T->getClass(), 0);
3829 QualType NewClsType;
3830 if (NewClsTInfo)
3831 NewClsType = NewClsTInfo->getType();
3832 else {
3833 NewClsType = getDerived().TransformType(OldClsType);
3834 if (NewClsType.isNull())
3835 return QualType();
3836 }
Mike Stump11289f42009-09-09 15:08:12 +00003837
John McCall550e0c22009-10-21 00:40:46 +00003838 QualType Result = TL.getType();
3839 if (getDerived().AlwaysRebuild() ||
3840 PointeeType != T->getPointeeType() ||
Abramo Bagnara509357842011-03-05 14:42:21 +00003841 NewClsType != OldClsType) {
3842 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall70dd5f62009-10-30 00:06:24 +00003843 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00003844 if (Result.isNull())
3845 return QualType();
3846 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00003847
Reid Kleckner0503a872013-12-05 01:23:43 +00003848 // If we had to adjust the pointee type when building a member pointer, make
3849 // sure to push TypeLoc info for it.
3850 const MemberPointerType *MPT = Result->getAs<MemberPointerType>();
3851 if (MPT && PointeeType != MPT->getPointeeType()) {
3852 assert(isa<AdjustedType>(MPT->getPointeeType()));
3853 TLB.push<AdjustedTypeLoc>(MPT->getPointeeType());
3854 }
3855
John McCall550e0c22009-10-21 00:40:46 +00003856 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3857 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnara509357842011-03-05 14:42:21 +00003858 NewTL.setClassTInfo(NewClsTInfo);
John McCall550e0c22009-10-21 00:40:46 +00003859
3860 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003861}
3862
Mike Stump11289f42009-09-09 15:08:12 +00003863template<typename Derived>
3864QualType
John McCall550e0c22009-10-21 00:40:46 +00003865TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003866 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003867 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003868 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003869 if (ElementType.isNull())
3870 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003871
John McCall550e0c22009-10-21 00:40:46 +00003872 QualType Result = TL.getType();
3873 if (getDerived().AlwaysRebuild() ||
3874 ElementType != T->getElementType()) {
3875 Result = getDerived().RebuildConstantArrayType(ElementType,
3876 T->getSizeModifier(),
3877 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00003878 T->getIndexTypeCVRQualifiers(),
3879 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003880 if (Result.isNull())
3881 return QualType();
3882 }
Eli Friedmanf7f102f2012-01-25 22:19:07 +00003883
3884 // We might have either a ConstantArrayType or a VariableArrayType now:
3885 // a ConstantArrayType is allowed to have an element type which is a
3886 // VariableArrayType if the type is dependent. Fortunately, all array
3887 // types have the same location layout.
3888 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00003889 NewTL.setLBracketLoc(TL.getLBracketLoc());
3890 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00003891
John McCall550e0c22009-10-21 00:40:46 +00003892 Expr *Size = TL.getSizeExpr();
3893 if (Size) {
Richard Smith764d2fe2011-12-20 02:08:33 +00003894 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3895 Sema::ConstantEvaluated);
John McCall550e0c22009-10-21 00:40:46 +00003896 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
Eli Friedmanc6237c62012-02-29 03:16:56 +00003897 Size = SemaRef.ActOnConstantExpression(Size).take();
John McCall550e0c22009-10-21 00:40:46 +00003898 }
3899 NewTL.setSizeExpr(Size);
3900
3901 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003902}
Mike Stump11289f42009-09-09 15:08:12 +00003903
Douglas Gregord6ff3322009-08-04 16:50:30 +00003904template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003905QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00003906 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003907 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003908 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003909 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003910 if (ElementType.isNull())
3911 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003912
John McCall550e0c22009-10-21 00:40:46 +00003913 QualType Result = TL.getType();
3914 if (getDerived().AlwaysRebuild() ||
3915 ElementType != T->getElementType()) {
3916 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00003917 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00003918 T->getIndexTypeCVRQualifiers(),
3919 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003920 if (Result.isNull())
3921 return QualType();
3922 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003923
John McCall550e0c22009-10-21 00:40:46 +00003924 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3925 NewTL.setLBracketLoc(TL.getLBracketLoc());
3926 NewTL.setRBracketLoc(TL.getRBracketLoc());
3927 NewTL.setSizeExpr(0);
3928
3929 return Result;
3930}
3931
3932template<typename Derived>
3933QualType
3934TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003935 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003936 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003937 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3938 if (ElementType.isNull())
3939 return QualType();
3940
John McCalldadc5752010-08-24 06:29:42 +00003941 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00003942 = getDerived().TransformExpr(T->getSizeExpr());
3943 if (SizeResult.isInvalid())
3944 return QualType();
3945
John McCallb268a282010-08-23 23:25:46 +00003946 Expr *Size = SizeResult.take();
John McCall550e0c22009-10-21 00:40:46 +00003947
3948 QualType Result = TL.getType();
3949 if (getDerived().AlwaysRebuild() ||
3950 ElementType != T->getElementType() ||
3951 Size != T->getSizeExpr()) {
3952 Result = getDerived().RebuildVariableArrayType(ElementType,
3953 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00003954 Size,
John McCall550e0c22009-10-21 00:40:46 +00003955 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00003956 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003957 if (Result.isNull())
3958 return QualType();
3959 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003960
Serge Pavlov774c6d02014-02-06 03:49:11 +00003961 // We might have constant size array now, but fortunately it has the same
3962 // location layout.
3963 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00003964 NewTL.setLBracketLoc(TL.getLBracketLoc());
3965 NewTL.setRBracketLoc(TL.getRBracketLoc());
3966 NewTL.setSizeExpr(Size);
3967
3968 return Result;
3969}
3970
3971template<typename Derived>
3972QualType
3973TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003974 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003975 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003976 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3977 if (ElementType.isNull())
3978 return QualType();
3979
Richard Smith764d2fe2011-12-20 02:08:33 +00003980 // Array bounds are constant expressions.
3981 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3982 Sema::ConstantEvaluated);
John McCall550e0c22009-10-21 00:40:46 +00003983
John McCall33ddac02011-01-19 10:06:00 +00003984 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3985 Expr *origSize = TL.getSizeExpr();
3986 if (!origSize) origSize = T->getSizeExpr();
3987
3988 ExprResult sizeResult
3989 = getDerived().TransformExpr(origSize);
Eli Friedmanc6237c62012-02-29 03:16:56 +00003990 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall33ddac02011-01-19 10:06:00 +00003991 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00003992 return QualType();
3993
John McCall33ddac02011-01-19 10:06:00 +00003994 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00003995
3996 QualType Result = TL.getType();
3997 if (getDerived().AlwaysRebuild() ||
3998 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00003999 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00004000 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
4001 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00004002 size,
John McCall550e0c22009-10-21 00:40:46 +00004003 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004004 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004005 if (Result.isNull())
4006 return QualType();
4007 }
John McCall550e0c22009-10-21 00:40:46 +00004008
4009 // We might have any sort of array type now, but fortunately they
4010 // all have the same location layout.
4011 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4012 NewTL.setLBracketLoc(TL.getLBracketLoc());
4013 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00004014 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00004015
4016 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004017}
Mike Stump11289f42009-09-09 15:08:12 +00004018
4019template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004020QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00004021 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004022 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004023 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004024
4025 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00004026 QualType ElementType = getDerived().TransformType(T->getElementType());
4027 if (ElementType.isNull())
4028 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004029
Richard Smith764d2fe2011-12-20 02:08:33 +00004030 // Vector sizes are constant expressions.
4031 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4032 Sema::ConstantEvaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00004033
John McCalldadc5752010-08-24 06:29:42 +00004034 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanc6237c62012-02-29 03:16:56 +00004035 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004036 if (Size.isInvalid())
4037 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004038
John McCall550e0c22009-10-21 00:40:46 +00004039 QualType Result = TL.getType();
4040 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00004041 ElementType != T->getElementType() ||
4042 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00004043 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCallb268a282010-08-23 23:25:46 +00004044 Size.take(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00004045 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00004046 if (Result.isNull())
4047 return QualType();
4048 }
John McCall550e0c22009-10-21 00:40:46 +00004049
4050 // Result might be dependent or not.
4051 if (isa<DependentSizedExtVectorType>(Result)) {
4052 DependentSizedExtVectorTypeLoc NewTL
4053 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
4054 NewTL.setNameLoc(TL.getNameLoc());
4055 } else {
4056 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4057 NewTL.setNameLoc(TL.getNameLoc());
4058 }
4059
4060 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004061}
Mike Stump11289f42009-09-09 15:08:12 +00004062
4063template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004064QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004065 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004066 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004067 QualType ElementType = getDerived().TransformType(T->getElementType());
4068 if (ElementType.isNull())
4069 return QualType();
4070
John McCall550e0c22009-10-21 00:40:46 +00004071 QualType Result = TL.getType();
4072 if (getDerived().AlwaysRebuild() ||
4073 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00004074 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00004075 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00004076 if (Result.isNull())
4077 return QualType();
4078 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004079
John McCall550e0c22009-10-21 00:40:46 +00004080 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
4081 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004082
John McCall550e0c22009-10-21 00:40:46 +00004083 return Result;
4084}
4085
4086template<typename Derived>
4087QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004088 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004089 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004090 QualType ElementType = getDerived().TransformType(T->getElementType());
4091 if (ElementType.isNull())
4092 return QualType();
4093
4094 QualType Result = TL.getType();
4095 if (getDerived().AlwaysRebuild() ||
4096 ElementType != T->getElementType()) {
4097 Result = getDerived().RebuildExtVectorType(ElementType,
4098 T->getNumElements(),
4099 /*FIXME*/ SourceLocation());
4100 if (Result.isNull())
4101 return QualType();
4102 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004103
John McCall550e0c22009-10-21 00:40:46 +00004104 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4105 NewTL.setNameLoc(TL.getNameLoc());
4106
4107 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004108}
Mike Stump11289f42009-09-09 15:08:12 +00004109
David Blaikie05785d12013-02-20 22:23:23 +00004110template <typename Derived>
4111ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
4112 ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
4113 bool ExpectParameterPack) {
John McCall58f10c32010-03-11 09:03:00 +00004114 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor715e4612011-01-14 22:40:04 +00004115 TypeSourceInfo *NewDI = 0;
Chad Rosier1dcde962012-08-08 18:46:20 +00004116
Douglas Gregor715e4612011-01-14 22:40:04 +00004117 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004118 // If we're substituting into a pack expansion type and we know the
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004119 // length we want to expand to, just substitute for the pattern.
Douglas Gregor715e4612011-01-14 22:40:04 +00004120 TypeLoc OldTL = OldDI->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004121 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004122
Douglas Gregor715e4612011-01-14 22:40:04 +00004123 TypeLocBuilder TLB;
4124 TypeLoc NewTL = OldDI->getTypeLoc();
4125 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00004126
4127 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor715e4612011-01-14 22:40:04 +00004128 OldExpansionTL.getPatternLoc());
4129 if (Result.isNull())
4130 return 0;
Chad Rosier1dcde962012-08-08 18:46:20 +00004131
4132 Result = RebuildPackExpansionType(Result,
4133 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor715e4612011-01-14 22:40:04 +00004134 OldExpansionTL.getEllipsisLoc(),
4135 NumExpansions);
4136 if (Result.isNull())
4137 return 0;
Chad Rosier1dcde962012-08-08 18:46:20 +00004138
Douglas Gregor715e4612011-01-14 22:40:04 +00004139 PackExpansionTypeLoc NewExpansionTL
4140 = TLB.push<PackExpansionTypeLoc>(Result);
4141 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
4142 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
4143 } else
4144 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00004145 if (!NewDI)
4146 return 0;
4147
John McCall8fb0d9d2011-05-01 22:35:37 +00004148 if (NewDI == OldDI && indexAdjustment == 0)
John McCall58f10c32010-03-11 09:03:00 +00004149 return OldParm;
John McCall8fb0d9d2011-05-01 22:35:37 +00004150
4151 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
4152 OldParm->getDeclContext(),
4153 OldParm->getInnerLocStart(),
4154 OldParm->getLocation(),
4155 OldParm->getIdentifier(),
4156 NewDI->getType(),
4157 NewDI,
4158 OldParm->getStorageClass(),
John McCall8fb0d9d2011-05-01 22:35:37 +00004159 /* DefArg */ NULL);
4160 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
4161 OldParm->getFunctionScopeIndex() + indexAdjustment);
4162 return newParm;
John McCall58f10c32010-03-11 09:03:00 +00004163}
4164
4165template<typename Derived>
4166bool TreeTransform<Derived>::
Douglas Gregordd472162011-01-07 00:20:55 +00004167 TransformFunctionTypeParams(SourceLocation Loc,
4168 ParmVarDecl **Params, unsigned NumParams,
4169 const QualType *ParamTypes,
Chris Lattner01cf8db2011-07-20 06:58:45 +00004170 SmallVectorImpl<QualType> &OutParamTypes,
4171 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004172 int indexAdjustment = 0;
4173
Douglas Gregordd472162011-01-07 00:20:55 +00004174 for (unsigned i = 0; i != NumParams; ++i) {
4175 if (ParmVarDecl *OldParm = Params[i]) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004176 assert(OldParm->getFunctionScopeIndex() == i);
4177
David Blaikie05785d12013-02-20 22:23:23 +00004178 Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004179 ParmVarDecl *NewParm = 0;
Douglas Gregor5499af42011-01-05 23:12:31 +00004180 if (OldParm->isParameterPack()) {
4181 // We have a function parameter pack that may need to be expanded.
Chris Lattner01cf8db2011-07-20 06:58:45 +00004182 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00004183
Douglas Gregor5499af42011-01-05 23:12:31 +00004184 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004185 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004186 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004187 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4188 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004189 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4190
Douglas Gregor5499af42011-01-05 23:12:31 +00004191 // Determine whether we should expand the parameter packs.
4192 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004193 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004194 Optional<unsigned> OrigNumExpansions =
4195 ExpansionTL.getTypePtr()->getNumExpansions();
Douglas Gregor715e4612011-01-14 22:40:04 +00004196 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004197 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4198 Pattern.getSourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004199 Unexpanded,
4200 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004201 RetainExpansion,
4202 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004203 return true;
4204 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004205
Douglas Gregor5499af42011-01-05 23:12:31 +00004206 if (ShouldExpand) {
4207 // Expand the function parameter pack into multiple, separate
4208 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00004209 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004210 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004211 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier1dcde962012-08-08 18:46:20 +00004212 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004213 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004214 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004215 OrigNumExpansions,
4216 /*ExpectParameterPack=*/false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004217 if (!NewParm)
4218 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004219
Douglas Gregordd472162011-01-07 00:20:55 +00004220 OutParamTypes.push_back(NewParm->getType());
4221 if (PVars)
4222 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004223 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004224
4225 // If we're supposed to retain a pack expansion, do so by temporarily
4226 // forgetting the partially-substituted parameter pack.
4227 if (RetainExpansion) {
4228 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00004229 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004230 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004231 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004232 OrigNumExpansions,
4233 /*ExpectParameterPack=*/false);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004234 if (!NewParm)
4235 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004236
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004237 OutParamTypes.push_back(NewParm->getType());
4238 if (PVars)
4239 PVars->push_back(NewParm);
4240 }
4241
John McCall8fb0d9d2011-05-01 22:35:37 +00004242 // The next parameter should have the same adjustment as the
4243 // last thing we pushed, but we post-incremented indexAdjustment
4244 // on every push. Also, if we push nothing, the adjustment should
4245 // go down by one.
4246 indexAdjustment--;
4247
Douglas Gregor5499af42011-01-05 23:12:31 +00004248 // We're done with the pack expansion.
4249 continue;
4250 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004251
4252 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004253 // expansion.
Douglas Gregorc52264e2011-03-02 02:04:06 +00004254 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4255 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004256 indexAdjustment,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004257 NumExpansions,
4258 /*ExpectParameterPack=*/true);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004259 } else {
David Blaikie05785d12013-02-20 22:23:23 +00004260 NewParm = getDerived().TransformFunctionTypeParam(
David Blaikie7a30dc52013-02-21 01:47:18 +00004261 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004262 }
Douglas Gregorc52264e2011-03-02 02:04:06 +00004263
John McCall58f10c32010-03-11 09:03:00 +00004264 if (!NewParm)
4265 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004266
Douglas Gregordd472162011-01-07 00:20:55 +00004267 OutParamTypes.push_back(NewParm->getType());
4268 if (PVars)
4269 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004270 continue;
4271 }
John McCall58f10c32010-03-11 09:03:00 +00004272
4273 // Deal with the possibility that we don't have a parameter
4274 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00004275 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00004276 bool IsPackExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004277 Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004278 QualType NewType;
Chad Rosier1dcde962012-08-08 18:46:20 +00004279 if (const PackExpansionType *Expansion
Douglas Gregor5499af42011-01-05 23:12:31 +00004280 = dyn_cast<PackExpansionType>(OldType)) {
4281 // We have a function parameter pack that may need to be expanded.
4282 QualType Pattern = Expansion->getPattern();
Chris Lattner01cf8db2011-07-20 06:58:45 +00004283 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor5499af42011-01-05 23:12:31 +00004284 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00004285
Douglas Gregor5499af42011-01-05 23:12:31 +00004286 // Determine whether we should expand the parameter packs.
4287 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004288 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00004289 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004290 Unexpanded,
4291 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004292 RetainExpansion,
4293 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00004294 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00004295 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004296
Douglas Gregor5499af42011-01-05 23:12:31 +00004297 if (ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004298 // Expand the function parameter pack into multiple, separate
Douglas Gregor5499af42011-01-05 23:12:31 +00004299 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004300 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004301 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4302 QualType NewType = getDerived().TransformType(Pattern);
4303 if (NewType.isNull())
4304 return true;
John McCall58f10c32010-03-11 09:03:00 +00004305
Douglas Gregordd472162011-01-07 00:20:55 +00004306 OutParamTypes.push_back(NewType);
4307 if (PVars)
4308 PVars->push_back(0);
Douglas Gregor5499af42011-01-05 23:12:31 +00004309 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004310
Douglas Gregor5499af42011-01-05 23:12:31 +00004311 // We're done with the pack expansion.
4312 continue;
4313 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004314
Douglas Gregor48d24112011-01-10 20:53:55 +00004315 // If we're supposed to retain a pack expansion, do so by temporarily
4316 // forgetting the partially-substituted parameter pack.
4317 if (RetainExpansion) {
4318 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4319 QualType NewType = getDerived().TransformType(Pattern);
4320 if (NewType.isNull())
4321 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004322
Douglas Gregor48d24112011-01-10 20:53:55 +00004323 OutParamTypes.push_back(NewType);
4324 if (PVars)
4325 PVars->push_back(0);
4326 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004327
Chad Rosier1dcde962012-08-08 18:46:20 +00004328 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004329 // expansion.
4330 OldType = Expansion->getPattern();
4331 IsPackExpansion = true;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004332 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4333 NewType = getDerived().TransformType(OldType);
4334 } else {
4335 NewType = getDerived().TransformType(OldType);
Douglas Gregor5499af42011-01-05 23:12:31 +00004336 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004337
Douglas Gregor5499af42011-01-05 23:12:31 +00004338 if (NewType.isNull())
4339 return true;
4340
4341 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004342 NewType = getSema().Context.getPackExpansionType(NewType,
4343 NumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00004344
Douglas Gregordd472162011-01-07 00:20:55 +00004345 OutParamTypes.push_back(NewType);
4346 if (PVars)
4347 PVars->push_back(0);
John McCall58f10c32010-03-11 09:03:00 +00004348 }
4349
John McCall8fb0d9d2011-05-01 22:35:37 +00004350#ifndef NDEBUG
4351 if (PVars) {
4352 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4353 if (ParmVarDecl *parm = (*PVars)[i])
4354 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor5499af42011-01-05 23:12:31 +00004355 }
John McCall8fb0d9d2011-05-01 22:35:37 +00004356#endif
4357
4358 return false;
4359}
John McCall58f10c32010-03-11 09:03:00 +00004360
4361template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004362QualType
John McCall550e0c22009-10-21 00:40:46 +00004363TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004364 FunctionProtoTypeLoc TL) {
Douglas Gregor3024f072012-04-16 07:05:22 +00004365 return getDerived().TransformFunctionProtoType(TLB, TL, 0, 0);
4366}
4367
4368template<typename Derived>
4369QualType
4370TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
4371 FunctionProtoTypeLoc TL,
4372 CXXRecordDecl *ThisContext,
4373 unsigned ThisTypeQuals) {
Douglas Gregor4afc2362010-08-31 00:26:14 +00004374 // Transform the parameters and return type.
4375 //
Richard Smithf623c962012-04-17 00:58:00 +00004376 // We are required to instantiate the params and return type in source order.
Douglas Gregor7fb25412010-10-01 18:44:50 +00004377 // When the function has a trailing return type, we instantiate the
4378 // parameters before the return type, since the return type can then refer
4379 // to the parameters themselves (via decltype, sizeof, etc.).
4380 //
Chris Lattner01cf8db2011-07-20 06:58:45 +00004381 SmallVector<QualType, 4> ParamTypes;
4382 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall424cec92011-01-19 06:33:43 +00004383 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00004384
Douglas Gregor7fb25412010-10-01 18:44:50 +00004385 QualType ResultType;
4386
Richard Smith1226c602012-08-14 22:51:13 +00004387 if (T->hasTrailingReturn()) {
Alp Toker9cacbab2014-01-20 20:26:09 +00004388 if (getDerived().TransformFunctionTypeParams(
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004389 TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(),
Alp Toker9cacbab2014-01-20 20:26:09 +00004390 TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004391 return QualType();
4392
Douglas Gregor3024f072012-04-16 07:05:22 +00004393 {
4394 // C++11 [expr.prim.general]p3:
Chad Rosier1dcde962012-08-08 18:46:20 +00004395 // If a declaration declares a member function or member function
4396 // template of a class X, the expression this is a prvalue of type
Douglas Gregor3024f072012-04-16 07:05:22 +00004397 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier1dcde962012-08-08 18:46:20 +00004398 // and the end of the function-definition, member-declarator, or
Douglas Gregor3024f072012-04-16 07:05:22 +00004399 // declarator.
4400 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier1dcde962012-08-08 18:46:20 +00004401
Alp Toker42a16a62014-01-25 23:51:36 +00004402 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor3024f072012-04-16 07:05:22 +00004403 if (ResultType.isNull())
4404 return QualType();
4405 }
Douglas Gregor7fb25412010-10-01 18:44:50 +00004406 }
4407 else {
Alp Toker42a16a62014-01-25 23:51:36 +00004408 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00004409 if (ResultType.isNull())
4410 return QualType();
4411
Alp Toker9cacbab2014-01-20 20:26:09 +00004412 if (getDerived().TransformFunctionTypeParams(
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004413 TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(),
Alp Toker9cacbab2014-01-20 20:26:09 +00004414 TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004415 return QualType();
4416 }
4417
Richard Smithf623c962012-04-17 00:58:00 +00004418 // FIXME: Need to transform the exception-specification too.
4419
John McCall550e0c22009-10-21 00:40:46 +00004420 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00004421 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() ||
Alp Toker9cacbab2014-01-20 20:26:09 +00004422 T->getNumParams() != ParamTypes.size() ||
4423 !std::equal(T->param_type_begin(), T->param_type_end(),
4424 ParamTypes.begin())) {
Jordan Rose5c382722013-03-08 21:51:21 +00004425 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +00004426 T->getExtProtoInfo());
John McCall550e0c22009-10-21 00:40:46 +00004427 if (Result.isNull())
4428 return QualType();
4429 }
Mike Stump11289f42009-09-09 15:08:12 +00004430
John McCall550e0c22009-10-21 00:40:46 +00004431 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004432 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00004433 NewTL.setLParenLoc(TL.getLParenLoc());
4434 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004435 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004436 for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i)
4437 NewTL.setParam(i, ParamDecls[i]);
John McCall550e0c22009-10-21 00:40:46 +00004438
4439 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004440}
Mike Stump11289f42009-09-09 15:08:12 +00004441
Douglas Gregord6ff3322009-08-04 16:50:30 +00004442template<typename Derived>
4443QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00004444 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004445 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004446 const FunctionNoProtoType *T = TL.getTypePtr();
Alp Toker42a16a62014-01-25 23:51:36 +00004447 QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
John McCall550e0c22009-10-21 00:40:46 +00004448 if (ResultType.isNull())
4449 return QualType();
4450
4451 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00004452 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType())
John McCall550e0c22009-10-21 00:40:46 +00004453 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4454
4455 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004456 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00004457 NewTL.setLParenLoc(TL.getLParenLoc());
4458 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004459 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCall550e0c22009-10-21 00:40:46 +00004460
4461 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004462}
Mike Stump11289f42009-09-09 15:08:12 +00004463
John McCallb96ec562009-12-04 22:46:56 +00004464template<typename Derived> QualType
4465TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004466 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004467 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004468 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00004469 if (!D)
4470 return QualType();
4471
4472 QualType Result = TL.getType();
4473 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4474 Result = getDerived().RebuildUnresolvedUsingType(D);
4475 if (Result.isNull())
4476 return QualType();
4477 }
4478
4479 // We might get an arbitrary type spec type back. We should at
4480 // least always get a type spec type, though.
4481 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4482 NewTL.setNameLoc(TL.getNameLoc());
4483
4484 return Result;
4485}
4486
Douglas Gregord6ff3322009-08-04 16:50:30 +00004487template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004488QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004489 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004490 const TypedefType *T = TL.getTypePtr();
Richard Smithdda56e42011-04-15 14:24:37 +00004491 TypedefNameDecl *Typedef
4492 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4493 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004494 if (!Typedef)
4495 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004496
John McCall550e0c22009-10-21 00:40:46 +00004497 QualType Result = TL.getType();
4498 if (getDerived().AlwaysRebuild() ||
4499 Typedef != T->getDecl()) {
4500 Result = getDerived().RebuildTypedefType(Typedef);
4501 if (Result.isNull())
4502 return QualType();
4503 }
Mike Stump11289f42009-09-09 15:08:12 +00004504
John McCall550e0c22009-10-21 00:40:46 +00004505 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4506 NewTL.setNameLoc(TL.getNameLoc());
4507
4508 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004509}
Mike Stump11289f42009-09-09 15:08:12 +00004510
Douglas Gregord6ff3322009-08-04 16:50:30 +00004511template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004512QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004513 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00004514 // typeof expressions are not potentially evaluated contexts
Eli Friedman15681d62012-09-26 04:34:21 +00004515 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4516 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00004517
John McCalldadc5752010-08-24 06:29:42 +00004518 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004519 if (E.isInvalid())
4520 return QualType();
4521
Eli Friedmane4f22df2012-02-29 04:03:55 +00004522 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
4523 if (E.isInvalid())
4524 return QualType();
4525
John McCall550e0c22009-10-21 00:40:46 +00004526 QualType Result = TL.getType();
4527 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00004528 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004529 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00004530 if (Result.isNull())
4531 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004532 }
John McCall550e0c22009-10-21 00:40:46 +00004533 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00004534
John McCall550e0c22009-10-21 00:40:46 +00004535 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004536 NewTL.setTypeofLoc(TL.getTypeofLoc());
4537 NewTL.setLParenLoc(TL.getLParenLoc());
4538 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00004539
4540 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004541}
Mike Stump11289f42009-09-09 15:08:12 +00004542
4543template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004544QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004545 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00004546 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4547 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4548 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00004549 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004550
John McCall550e0c22009-10-21 00:40:46 +00004551 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00004552 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4553 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00004554 if (Result.isNull())
4555 return QualType();
4556 }
Mike Stump11289f42009-09-09 15:08:12 +00004557
John McCall550e0c22009-10-21 00:40:46 +00004558 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004559 NewTL.setTypeofLoc(TL.getTypeofLoc());
4560 NewTL.setLParenLoc(TL.getLParenLoc());
4561 NewTL.setRParenLoc(TL.getRParenLoc());
4562 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00004563
4564 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004565}
Mike Stump11289f42009-09-09 15:08:12 +00004566
4567template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004568QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004569 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004570 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004571
Douglas Gregore922c772009-08-04 22:27:00 +00004572 // decltype expressions are not potentially evaluated contexts
Richard Smithfd555f62012-02-22 02:04:18 +00004573 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, 0,
4574 /*IsDecltype=*/ true);
Mike Stump11289f42009-09-09 15:08:12 +00004575
John McCalldadc5752010-08-24 06:29:42 +00004576 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004577 if (E.isInvalid())
4578 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004579
Richard Smithfd555f62012-02-22 02:04:18 +00004580 E = getSema().ActOnDecltypeExpression(E.take());
4581 if (E.isInvalid())
4582 return QualType();
4583
John McCall550e0c22009-10-21 00:40:46 +00004584 QualType Result = TL.getType();
4585 if (getDerived().AlwaysRebuild() ||
4586 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004587 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004588 if (Result.isNull())
4589 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004590 }
John McCall550e0c22009-10-21 00:40:46 +00004591 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00004592
John McCall550e0c22009-10-21 00:40:46 +00004593 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4594 NewTL.setNameLoc(TL.getNameLoc());
4595
4596 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004597}
4598
4599template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00004600QualType TreeTransform<Derived>::TransformUnaryTransformType(
4601 TypeLocBuilder &TLB,
4602 UnaryTransformTypeLoc TL) {
4603 QualType Result = TL.getType();
4604 if (Result->isDependentType()) {
4605 const UnaryTransformType *T = TL.getTypePtr();
4606 QualType NewBase =
4607 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4608 Result = getDerived().RebuildUnaryTransformType(NewBase,
4609 T->getUTTKind(),
4610 TL.getKWLoc());
4611 if (Result.isNull())
4612 return QualType();
4613 }
4614
4615 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4616 NewTL.setKWLoc(TL.getKWLoc());
4617 NewTL.setParensRange(TL.getParensRange());
4618 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4619 return Result;
4620}
4621
4622template<typename Derived>
Richard Smith30482bc2011-02-20 03:19:35 +00004623QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4624 AutoTypeLoc TL) {
4625 const AutoType *T = TL.getTypePtr();
4626 QualType OldDeduced = T->getDeducedType();
4627 QualType NewDeduced;
4628 if (!OldDeduced.isNull()) {
4629 NewDeduced = getDerived().TransformType(OldDeduced);
4630 if (NewDeduced.isNull())
4631 return QualType();
4632 }
4633
4634 QualType Result = TL.getType();
Richard Smith27d807c2013-04-30 13:56:41 +00004635 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
4636 T->isDependentType()) {
Richard Smith74aeef52013-04-26 16:15:35 +00004637 Result = getDerived().RebuildAutoType(NewDeduced, T->isDecltypeAuto());
Richard Smith30482bc2011-02-20 03:19:35 +00004638 if (Result.isNull())
4639 return QualType();
4640 }
4641
4642 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4643 NewTL.setNameLoc(TL.getNameLoc());
4644
4645 return Result;
4646}
4647
4648template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004649QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004650 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004651 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004652 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004653 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4654 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004655 if (!Record)
4656 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004657
John McCall550e0c22009-10-21 00:40:46 +00004658 QualType Result = TL.getType();
4659 if (getDerived().AlwaysRebuild() ||
4660 Record != T->getDecl()) {
4661 Result = getDerived().RebuildRecordType(Record);
4662 if (Result.isNull())
4663 return QualType();
4664 }
Mike Stump11289f42009-09-09 15:08:12 +00004665
John McCall550e0c22009-10-21 00:40:46 +00004666 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4667 NewTL.setNameLoc(TL.getNameLoc());
4668
4669 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004670}
Mike Stump11289f42009-09-09 15:08:12 +00004671
4672template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004673QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004674 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004675 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004676 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004677 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4678 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004679 if (!Enum)
4680 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004681
John McCall550e0c22009-10-21 00:40:46 +00004682 QualType Result = TL.getType();
4683 if (getDerived().AlwaysRebuild() ||
4684 Enum != T->getDecl()) {
4685 Result = getDerived().RebuildEnumType(Enum);
4686 if (Result.isNull())
4687 return QualType();
4688 }
Mike Stump11289f42009-09-09 15:08:12 +00004689
John McCall550e0c22009-10-21 00:40:46 +00004690 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4691 NewTL.setNameLoc(TL.getNameLoc());
4692
4693 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004694}
John McCallfcc33b02009-09-05 00:15:47 +00004695
John McCalle78aac42010-03-10 03:28:59 +00004696template<typename Derived>
4697QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4698 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004699 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00004700 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4701 TL.getTypePtr()->getDecl());
4702 if (!D) return QualType();
4703
4704 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4705 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4706 return T;
4707}
4708
Douglas Gregord6ff3322009-08-04 16:50:30 +00004709template<typename Derived>
4710QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004711 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004712 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004713 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004714}
4715
Mike Stump11289f42009-09-09 15:08:12 +00004716template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00004717QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004718 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004719 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004720 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00004721
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004722 // Substitute into the replacement type, which itself might involve something
4723 // that needs to be transformed. This only tends to occur with default
4724 // template arguments of template template parameters.
4725 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4726 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4727 if (Replacement.isNull())
4728 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00004729
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004730 // Always canonicalize the replacement type.
4731 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4732 QualType Result
Chad Rosier1dcde962012-08-08 18:46:20 +00004733 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004734 Replacement);
Chad Rosier1dcde962012-08-08 18:46:20 +00004735
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004736 // Propagate type-source information.
4737 SubstTemplateTypeParmTypeLoc NewTL
4738 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4739 NewTL.setNameLoc(TL.getNameLoc());
4740 return Result;
4741
John McCallcebee162009-10-18 09:09:24 +00004742}
4743
4744template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00004745QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4746 TypeLocBuilder &TLB,
4747 SubstTemplateTypeParmPackTypeLoc TL) {
4748 return TransformTypeSpecType(TLB, TL);
4749}
4750
4751template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00004752QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00004753 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004754 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00004755 const TemplateSpecializationType *T = TL.getTypePtr();
4756
Douglas Gregordf846d12011-03-02 18:46:51 +00004757 // The nested-name-specifier never matters in a TemplateSpecializationType,
4758 // because we can't have a dependent nested-name-specifier anyway.
4759 CXXScopeSpec SS;
Mike Stump11289f42009-09-09 15:08:12 +00004760 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00004761 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4762 TL.getTemplateNameLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004763 if (Template.isNull())
4764 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004765
John McCall31f82722010-11-12 08:19:04 +00004766 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4767}
4768
Eli Friedman0dfb8892011-10-06 23:00:33 +00004769template<typename Derived>
4770QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
4771 AtomicTypeLoc TL) {
4772 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
4773 if (ValueType.isNull())
4774 return QualType();
4775
4776 QualType Result = TL.getType();
4777 if (getDerived().AlwaysRebuild() ||
4778 ValueType != TL.getValueLoc().getType()) {
4779 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
4780 if (Result.isNull())
4781 return QualType();
4782 }
4783
4784 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
4785 NewTL.setKWLoc(TL.getKWLoc());
4786 NewTL.setLParenLoc(TL.getLParenLoc());
4787 NewTL.setRParenLoc(TL.getRParenLoc());
4788
4789 return Result;
4790}
4791
Chad Rosier1dcde962012-08-08 18:46:20 +00004792 /// \brief Simple iterator that traverses the template arguments in a
Douglas Gregorfe921a72010-12-20 23:36:19 +00004793 /// container that provides a \c getArgLoc() member function.
4794 ///
4795 /// This iterator is intended to be used with the iterator form of
4796 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4797 template<typename ArgLocContainer>
4798 class TemplateArgumentLocContainerIterator {
4799 ArgLocContainer *Container;
4800 unsigned Index;
Chad Rosier1dcde962012-08-08 18:46:20 +00004801
Douglas Gregorfe921a72010-12-20 23:36:19 +00004802 public:
4803 typedef TemplateArgumentLoc value_type;
4804 typedef TemplateArgumentLoc reference;
4805 typedef int difference_type;
4806 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00004807
Douglas Gregorfe921a72010-12-20 23:36:19 +00004808 class pointer {
4809 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00004810
Douglas Gregorfe921a72010-12-20 23:36:19 +00004811 public:
4812 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00004813
Douglas Gregorfe921a72010-12-20 23:36:19 +00004814 const TemplateArgumentLoc *operator->() const {
4815 return &Arg;
4816 }
4817 };
Chad Rosier1dcde962012-08-08 18:46:20 +00004818
4819
Douglas Gregorfe921a72010-12-20 23:36:19 +00004820 TemplateArgumentLocContainerIterator() {}
Chad Rosier1dcde962012-08-08 18:46:20 +00004821
Douglas Gregorfe921a72010-12-20 23:36:19 +00004822 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4823 unsigned Index)
4824 : Container(&Container), Index(Index) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00004825
Douglas Gregorfe921a72010-12-20 23:36:19 +00004826 TemplateArgumentLocContainerIterator &operator++() {
4827 ++Index;
4828 return *this;
4829 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004830
Douglas Gregorfe921a72010-12-20 23:36:19 +00004831 TemplateArgumentLocContainerIterator operator++(int) {
4832 TemplateArgumentLocContainerIterator Old(*this);
4833 ++(*this);
4834 return Old;
4835 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004836
Douglas Gregorfe921a72010-12-20 23:36:19 +00004837 TemplateArgumentLoc operator*() const {
4838 return Container->getArgLoc(Index);
4839 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004840
Douglas Gregorfe921a72010-12-20 23:36:19 +00004841 pointer operator->() const {
4842 return pointer(Container->getArgLoc(Index));
4843 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004844
Douglas Gregorfe921a72010-12-20 23:36:19 +00004845 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004846 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004847 return X.Container == Y.Container && X.Index == Y.Index;
4848 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004849
Douglas Gregorfe921a72010-12-20 23:36:19 +00004850 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004851 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004852 return !(X == Y);
4853 }
4854 };
Chad Rosier1dcde962012-08-08 18:46:20 +00004855
4856
John McCall31f82722010-11-12 08:19:04 +00004857template <typename Derived>
4858QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4859 TypeLocBuilder &TLB,
4860 TemplateSpecializationTypeLoc TL,
4861 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00004862 TemplateArgumentListInfo NewTemplateArgs;
4863 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4864 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00004865 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4866 ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00004867 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregorfe921a72010-12-20 23:36:19 +00004868 ArgIterator(TL, TL.getNumArgs()),
4869 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00004870 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004871
John McCall0ad16662009-10-29 08:12:44 +00004872 // FIXME: maybe don't rebuild if all the template arguments are the same.
4873
4874 QualType Result =
4875 getDerived().RebuildTemplateSpecializationType(Template,
4876 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00004877 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00004878
4879 if (!Result.isNull()) {
Richard Smith3f1b5d02011-05-05 21:57:07 +00004880 // Specializations of template template parameters are represented as
4881 // TemplateSpecializationTypes, and substitution of type alias templates
4882 // within a dependent context can transform them into
4883 // DependentTemplateSpecializationTypes.
4884 if (isa<DependentTemplateSpecializationType>(Result)) {
4885 DependentTemplateSpecializationTypeLoc NewTL
4886 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004887 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3f1b5d02011-05-05 21:57:07 +00004888 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00004889 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004890 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3f1b5d02011-05-05 21:57:07 +00004891 NewTL.setLAngleLoc(TL.getLAngleLoc());
4892 NewTL.setRAngleLoc(TL.getRAngleLoc());
4893 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4894 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4895 return Result;
4896 }
4897
John McCall0ad16662009-10-29 08:12:44 +00004898 TemplateSpecializationTypeLoc NewTL
4899 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004900 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall0ad16662009-10-29 08:12:44 +00004901 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4902 NewTL.setLAngleLoc(TL.getLAngleLoc());
4903 NewTL.setRAngleLoc(TL.getRAngleLoc());
4904 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4905 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004906 }
Mike Stump11289f42009-09-09 15:08:12 +00004907
John McCall0ad16662009-10-29 08:12:44 +00004908 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004909}
Mike Stump11289f42009-09-09 15:08:12 +00004910
Douglas Gregor5a064722011-02-28 17:23:35 +00004911template <typename Derived>
4912QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4913 TypeLocBuilder &TLB,
4914 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +00004915 TemplateName Template,
4916 CXXScopeSpec &SS) {
Douglas Gregor5a064722011-02-28 17:23:35 +00004917 TemplateArgumentListInfo NewTemplateArgs;
4918 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4919 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4920 typedef TemplateArgumentLocContainerIterator<
4921 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00004922 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor5a064722011-02-28 17:23:35 +00004923 ArgIterator(TL, TL.getNumArgs()),
4924 NewTemplateArgs))
4925 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00004926
Douglas Gregor5a064722011-02-28 17:23:35 +00004927 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier1dcde962012-08-08 18:46:20 +00004928
Douglas Gregor5a064722011-02-28 17:23:35 +00004929 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4930 QualType Result
4931 = getSema().Context.getDependentTemplateSpecializationType(
4932 TL.getTypePtr()->getKeyword(),
4933 DTN->getQualifier(),
4934 DTN->getIdentifier(),
4935 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00004936
Douglas Gregor5a064722011-02-28 17:23:35 +00004937 DependentTemplateSpecializationTypeLoc NewTL
4938 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004939 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004940 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00004941 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004942 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00004943 NewTL.setLAngleLoc(TL.getLAngleLoc());
4944 NewTL.setRAngleLoc(TL.getRAngleLoc());
4945 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4946 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4947 return Result;
4948 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004949
4950 QualType Result
Douglas Gregor5a064722011-02-28 17:23:35 +00004951 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004952 TL.getTemplateNameLoc(),
Douglas Gregor5a064722011-02-28 17:23:35 +00004953 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00004954
Douglas Gregor5a064722011-02-28 17:23:35 +00004955 if (!Result.isNull()) {
4956 /// FIXME: Wrap this in an elaborated-type-specifier?
4957 TemplateSpecializationTypeLoc NewTL
4958 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00004959 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004960 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00004961 NewTL.setLAngleLoc(TL.getLAngleLoc());
4962 NewTL.setRAngleLoc(TL.getRAngleLoc());
4963 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4964 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4965 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004966
Douglas Gregor5a064722011-02-28 17:23:35 +00004967 return Result;
4968}
4969
Mike Stump11289f42009-09-09 15:08:12 +00004970template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004971QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00004972TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004973 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004974 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00004975
Douglas Gregor844cb502011-03-01 18:12:44 +00004976 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara6150c882010-05-11 21:36:43 +00004977 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor844cb502011-03-01 18:12:44 +00004978 if (TL.getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004979 QualifierLoc
Douglas Gregor844cb502011-03-01 18:12:44 +00004980 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4981 if (!QualifierLoc)
Abramo Bagnara6150c882010-05-11 21:36:43 +00004982 return QualType();
4983 }
Mike Stump11289f42009-09-09 15:08:12 +00004984
John McCall31f82722010-11-12 08:19:04 +00004985 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4986 if (NamedT.isNull())
4987 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00004988
Richard Smith3f1b5d02011-05-05 21:57:07 +00004989 // C++0x [dcl.type.elab]p2:
4990 // If the identifier resolves to a typedef-name or the simple-template-id
4991 // resolves to an alias template specialization, the
4992 // elaborated-type-specifier is ill-formed.
Richard Smith0c4a34b2011-05-14 15:04:18 +00004993 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
4994 if (const TemplateSpecializationType *TST =
4995 NamedT->getAs<TemplateSpecializationType>()) {
4996 TemplateName Template = TST->getTemplateName();
4997 if (TypeAliasTemplateDecl *TAT =
4998 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
4999 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
5000 diag::err_tag_reference_non_tag) << 4;
5001 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
5002 }
Richard Smith3f1b5d02011-05-05 21:57:07 +00005003 }
5004 }
5005
John McCall550e0c22009-10-21 00:40:46 +00005006 QualType Result = TL.getType();
5007 if (getDerived().AlwaysRebuild() ||
Douglas Gregor844cb502011-03-01 18:12:44 +00005008 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00005009 NamedT != T->getNamedType()) {
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005010 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00005011 T->getKeyword(),
Douglas Gregor844cb502011-03-01 18:12:44 +00005012 QualifierLoc, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00005013 if (Result.isNull())
5014 return QualType();
5015 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00005016
Abramo Bagnara6150c882010-05-11 21:36:43 +00005017 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005018 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005019 NewTL.setQualifierLoc(QualifierLoc);
John McCall550e0c22009-10-21 00:40:46 +00005020 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005021}
Mike Stump11289f42009-09-09 15:08:12 +00005022
5023template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00005024QualType TreeTransform<Derived>::TransformAttributedType(
5025 TypeLocBuilder &TLB,
5026 AttributedTypeLoc TL) {
5027 const AttributedType *oldType = TL.getTypePtr();
5028 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
5029 if (modifiedType.isNull())
5030 return QualType();
5031
5032 QualType result = TL.getType();
5033
5034 // FIXME: dependent operand expressions?
5035 if (getDerived().AlwaysRebuild() ||
5036 modifiedType != oldType->getModifiedType()) {
5037 // TODO: this is really lame; we should really be rebuilding the
5038 // equivalent type from first principles.
5039 QualType equivalentType
5040 = getDerived().TransformType(oldType->getEquivalentType());
5041 if (equivalentType.isNull())
5042 return QualType();
5043 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
5044 modifiedType,
5045 equivalentType);
5046 }
5047
5048 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
5049 newTL.setAttrNameLoc(TL.getAttrNameLoc());
5050 if (TL.hasAttrOperand())
5051 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5052 if (TL.hasAttrExprOperand())
5053 newTL.setAttrExprOperand(TL.getAttrExprOperand());
5054 else if (TL.hasAttrEnumOperand())
5055 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
5056
5057 return result;
5058}
5059
5060template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00005061QualType
5062TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
5063 ParenTypeLoc TL) {
5064 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
5065 if (Inner.isNull())
5066 return QualType();
5067
5068 QualType Result = TL.getType();
5069 if (getDerived().AlwaysRebuild() ||
5070 Inner != TL.getInnerLoc().getType()) {
5071 Result = getDerived().RebuildParenType(Inner);
5072 if (Result.isNull())
5073 return QualType();
5074 }
5075
5076 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
5077 NewTL.setLParenLoc(TL.getLParenLoc());
5078 NewTL.setRParenLoc(TL.getRParenLoc());
5079 return Result;
5080}
5081
5082template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00005083QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005084 DependentNameTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005085 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00005086
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005087 NestedNameSpecifierLoc QualifierLoc
5088 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5089 if (!QualifierLoc)
Douglas Gregord6ff3322009-08-04 16:50:30 +00005090 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005091
John McCallc392f372010-06-11 00:33:02 +00005092 QualType Result
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005093 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005094 TL.getElaboratedKeywordLoc(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005095 QualifierLoc,
5096 T->getIdentifier(),
John McCallc392f372010-06-11 00:33:02 +00005097 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00005098 if (Result.isNull())
5099 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005100
Abramo Bagnarad7548482010-05-19 21:37:53 +00005101 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
5102 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00005103 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
5104
Abramo Bagnarad7548482010-05-19 21:37:53 +00005105 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005106 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005107 NewTL.setQualifierLoc(QualifierLoc);
John McCallc392f372010-06-11 00:33:02 +00005108 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00005109 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005110 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005111 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00005112 NewTL.setNameLoc(TL.getNameLoc());
5113 }
John McCall550e0c22009-10-21 00:40:46 +00005114 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005115}
Mike Stump11289f42009-09-09 15:08:12 +00005116
Douglas Gregord6ff3322009-08-04 16:50:30 +00005117template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00005118QualType TreeTransform<Derived>::
5119 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005120 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregora7a795b2011-03-01 20:11:18 +00005121 NestedNameSpecifierLoc QualifierLoc;
5122 if (TL.getQualifierLoc()) {
5123 QualifierLoc
5124 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5125 if (!QualifierLoc)
Douglas Gregor5a064722011-02-28 17:23:35 +00005126 return QualType();
5127 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005128
John McCall31f82722010-11-12 08:19:04 +00005129 return getDerived()
Douglas Gregora7a795b2011-03-01 20:11:18 +00005130 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall31f82722010-11-12 08:19:04 +00005131}
5132
5133template<typename Derived>
5134QualType TreeTransform<Derived>::
Douglas Gregora7a795b2011-03-01 20:11:18 +00005135TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
5136 DependentTemplateSpecializationTypeLoc TL,
5137 NestedNameSpecifierLoc QualifierLoc) {
5138 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00005139
Douglas Gregora7a795b2011-03-01 20:11:18 +00005140 TemplateArgumentListInfo NewTemplateArgs;
5141 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5142 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00005143
Douglas Gregora7a795b2011-03-01 20:11:18 +00005144 typedef TemplateArgumentLocContainerIterator<
5145 DependentTemplateSpecializationTypeLoc> ArgIterator;
5146 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5147 ArgIterator(TL, TL.getNumArgs()),
5148 NewTemplateArgs))
5149 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005150
Douglas Gregora7a795b2011-03-01 20:11:18 +00005151 QualType Result
5152 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
5153 QualifierLoc,
5154 T->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005155 TL.getTemplateNameLoc(),
Douglas Gregora7a795b2011-03-01 20:11:18 +00005156 NewTemplateArgs);
5157 if (Result.isNull())
5158 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005159
Douglas Gregora7a795b2011-03-01 20:11:18 +00005160 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
5161 QualType NamedT = ElabT->getNamedType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005162
Douglas Gregora7a795b2011-03-01 20:11:18 +00005163 // Copy information relevant to the template specialization.
5164 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor43f788f2011-03-07 02:33:33 +00005165 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005166 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005167 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005168 NamedTL.setLAngleLoc(TL.getLAngleLoc());
5169 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005170 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005171 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier1dcde962012-08-08 18:46:20 +00005172
Douglas Gregora7a795b2011-03-01 20:11:18 +00005173 // Copy information relevant to the elaborated type.
5174 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005175 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005176 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor43f788f2011-03-07 02:33:33 +00005177 } else if (isa<DependentTemplateSpecializationType>(Result)) {
5178 DependentTemplateSpecializationTypeLoc SpecTL
5179 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005180 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005181 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005182 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005183 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005184 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5185 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005186 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005187 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005188 } else {
Douglas Gregor43f788f2011-03-07 02:33:33 +00005189 TemplateSpecializationTypeLoc SpecTL
5190 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005191 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005192 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005193 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5194 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005195 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005196 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005197 }
5198 return Result;
5199}
5200
5201template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00005202QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5203 PackExpansionTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005204 QualType Pattern
5205 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor822d0302011-01-12 17:07:58 +00005206 if (Pattern.isNull())
5207 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005208
5209 QualType Result = TL.getType();
Douglas Gregor822d0302011-01-12 17:07:58 +00005210 if (getDerived().AlwaysRebuild() ||
5211 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005212 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00005213 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00005214 TL.getEllipsisLoc(),
5215 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00005216 if (Result.isNull())
5217 return QualType();
5218 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005219
Douglas Gregor822d0302011-01-12 17:07:58 +00005220 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5221 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5222 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00005223}
5224
5225template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005226QualType
5227TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005228 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005229 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00005230 TLB.pushFullCopy(TL);
5231 return TL.getType();
5232}
5233
5234template<typename Derived>
5235QualType
5236TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005237 ObjCObjectTypeLoc TL) {
John McCall8b07ec22010-05-15 11:32:37 +00005238 // ObjCObjectType is never dependent.
5239 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00005240 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005241}
Mike Stump11289f42009-09-09 15:08:12 +00005242
5243template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005244QualType
5245TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005246 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005247 // ObjCObjectPointerType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00005248 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00005249 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00005250}
5251
Douglas Gregord6ff3322009-08-04 16:50:30 +00005252//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00005253// Statement transformation
5254//===----------------------------------------------------------------------===//
5255template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005256StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005257TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00005258 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005259}
5260
5261template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005262StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005263TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
5264 return getDerived().TransformCompoundStmt(S, false);
5265}
5266
5267template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005268StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005269TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00005270 bool IsStmtExpr) {
Dmitri Gribenko800ddf32012-02-14 22:14:32 +00005271 Sema::CompoundScopeRAII CompoundScope(getSema());
5272
John McCall1ababa62010-08-27 19:56:05 +00005273 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00005274 bool SubStmtChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005275 SmallVector<Stmt*, 8> Statements;
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005276 for (auto *B : S->body()) {
5277 StmtResult Result = getDerived().TransformStmt(B);
John McCall1ababa62010-08-27 19:56:05 +00005278 if (Result.isInvalid()) {
5279 // Immediately fail if this was a DeclStmt, since it's very
5280 // likely that this will cause problems for future statements.
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005281 if (isa<DeclStmt>(B))
John McCall1ababa62010-08-27 19:56:05 +00005282 return StmtError();
5283
5284 // Otherwise, just keep processing substatements and fail later.
5285 SubStmtInvalid = true;
5286 continue;
5287 }
Mike Stump11289f42009-09-09 15:08:12 +00005288
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005289 SubStmtChanged = SubStmtChanged || Result.get() != B;
Douglas Gregorebe10102009-08-20 07:17:43 +00005290 Statements.push_back(Result.takeAs<Stmt>());
5291 }
Mike Stump11289f42009-09-09 15:08:12 +00005292
John McCall1ababa62010-08-27 19:56:05 +00005293 if (SubStmtInvalid)
5294 return StmtError();
5295
Douglas Gregorebe10102009-08-20 07:17:43 +00005296 if (!getDerived().AlwaysRebuild() &&
5297 !SubStmtChanged)
John McCallc3007a22010-10-26 07:05:15 +00005298 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005299
5300 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00005301 Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00005302 S->getRBracLoc(),
5303 IsStmtExpr);
5304}
Mike Stump11289f42009-09-09 15:08:12 +00005305
Douglas Gregorebe10102009-08-20 07:17:43 +00005306template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005307StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005308TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005309 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00005310 {
Eli Friedman1f4f9dd2012-01-18 02:54:10 +00005311 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5312 Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005313
Eli Friedman06577382009-11-19 03:14:00 +00005314 // Transform the left-hand case value.
5315 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00005316 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman06577382009-11-19 03:14:00 +00005317 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005318 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005319
Eli Friedman06577382009-11-19 03:14:00 +00005320 // Transform the right-hand case value (for the GNU case-range extension).
5321 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00005322 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman06577382009-11-19 03:14:00 +00005323 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005324 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00005325 }
Mike Stump11289f42009-09-09 15:08:12 +00005326
Douglas Gregorebe10102009-08-20 07:17:43 +00005327 // Build the case statement.
5328 // Case statements are always rebuilt so that they will attached to their
5329 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005330 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00005331 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005332 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00005333 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005334 S->getColonLoc());
5335 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005336 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005337
Douglas Gregorebe10102009-08-20 07:17:43 +00005338 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00005339 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005340 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005341 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005342
Douglas Gregorebe10102009-08-20 07:17:43 +00005343 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00005344 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005345}
5346
5347template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005348StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005349TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005350 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00005351 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005352 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005353 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005354
Douglas Gregorebe10102009-08-20 07:17:43 +00005355 // Default statements are always rebuilt
5356 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00005357 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005358}
Mike Stump11289f42009-09-09 15:08:12 +00005359
Douglas Gregorebe10102009-08-20 07:17:43 +00005360template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005361StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005362TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005363 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005364 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005365 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005366
Chris Lattnercab02a62011-02-17 20:34:02 +00005367 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5368 S->getDecl());
5369 if (!LD)
5370 return StmtError();
Richard Smithc202b282012-04-14 00:33:13 +00005371
5372
Douglas Gregorebe10102009-08-20 07:17:43 +00005373 // FIXME: Pass the real colon location in.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00005374 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005375 cast<LabelDecl>(LD), SourceLocation(),
5376 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005377}
Mike Stump11289f42009-09-09 15:08:12 +00005378
Douglas Gregorebe10102009-08-20 07:17:43 +00005379template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005380StmtResult
Richard Smithc202b282012-04-14 00:33:13 +00005381TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
5382 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5383 if (SubStmt.isInvalid())
5384 return StmtError();
5385
5386 // TODO: transform attributes
5387 if (SubStmt.get() == S->getSubStmt() /* && attrs are the same */)
5388 return S;
5389
5390 return getDerived().RebuildAttributedStmt(S->getAttrLoc(),
5391 S->getAttrs(),
5392 SubStmt.get());
5393}
5394
5395template<typename Derived>
5396StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005397TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005398 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005399 ExprResult Cond;
Douglas Gregor633caca2009-11-23 23:44:04 +00005400 VarDecl *ConditionVar = 0;
5401 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005402 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00005403 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005404 getDerived().TransformDefinition(
5405 S->getConditionVariable()->getLocation(),
5406 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00005407 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005408 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005409 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00005410 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005411
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005412 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005413 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005414
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005415 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00005416 if (S->getCond()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005417 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005418 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005419 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005420 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005421
John McCallb268a282010-08-23 23:25:46 +00005422 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005423 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005424 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005425
John McCallb268a282010-08-23 23:25:46 +00005426 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5427 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005428 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005429
Douglas Gregorebe10102009-08-20 07:17:43 +00005430 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00005431 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00005432 if (Then.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005433 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005434
Douglas Gregorebe10102009-08-20 07:17:43 +00005435 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00005436 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00005437 if (Else.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005438 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005439
Douglas Gregorebe10102009-08-20 07:17:43 +00005440 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00005441 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005442 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005443 Then.get() == S->getThen() &&
5444 Else.get() == S->getElse())
John McCallc3007a22010-10-26 07:05:15 +00005445 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005446
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005447 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00005448 Then.get(),
John McCallb268a282010-08-23 23:25:46 +00005449 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005450}
5451
5452template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005453StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005454TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005455 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00005456 ExprResult Cond;
Douglas Gregordcf19622009-11-24 17:07:59 +00005457 VarDecl *ConditionVar = 0;
5458 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005459 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00005460 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005461 getDerived().TransformDefinition(
5462 S->getConditionVariable()->getLocation(),
5463 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00005464 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005465 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005466 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00005467 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005468
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005469 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005470 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005471 }
Mike Stump11289f42009-09-09 15:08:12 +00005472
Douglas Gregorebe10102009-08-20 07:17:43 +00005473 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005474 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00005475 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00005476 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00005477 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005478 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005479
Douglas Gregorebe10102009-08-20 07:17:43 +00005480 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005481 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005482 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005483 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005484
Douglas Gregorebe10102009-08-20 07:17:43 +00005485 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00005486 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5487 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005488}
Mike Stump11289f42009-09-09 15:08:12 +00005489
Douglas Gregorebe10102009-08-20 07:17:43 +00005490template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005491StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005492TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005493 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005494 ExprResult Cond;
Douglas Gregor680f8612009-11-24 21:15:44 +00005495 VarDecl *ConditionVar = 0;
5496 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005497 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00005498 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005499 getDerived().TransformDefinition(
5500 S->getConditionVariable()->getLocation(),
5501 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00005502 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005503 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005504 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00005505 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005506
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005507 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005508 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005509
5510 if (S->getCond()) {
5511 // Convert the condition to a boolean value.
Chad Rosier1dcde962012-08-08 18:46:20 +00005512 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005513 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005514 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005515 return StmtError();
John McCallb268a282010-08-23 23:25:46 +00005516 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00005517 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005518 }
Mike Stump11289f42009-09-09 15:08:12 +00005519
John McCallb268a282010-08-23 23:25:46 +00005520 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5521 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005522 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005523
Douglas Gregorebe10102009-08-20 07:17:43 +00005524 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005525 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005526 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005527 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005528
Douglas Gregorebe10102009-08-20 07:17:43 +00005529 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00005530 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005531 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005532 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00005533 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005534
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005535 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00005536 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005537}
Mike Stump11289f42009-09-09 15:08:12 +00005538
Douglas Gregorebe10102009-08-20 07:17:43 +00005539template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005540StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005541TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005542 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005543 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005544 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005545 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005546
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005547 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005548 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005549 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005550 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005551
Douglas Gregorebe10102009-08-20 07:17:43 +00005552 if (!getDerived().AlwaysRebuild() &&
5553 Cond.get() == S->getCond() &&
5554 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005555 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005556
John McCallb268a282010-08-23 23:25:46 +00005557 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5558 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005559 S->getRParenLoc());
5560}
Mike Stump11289f42009-09-09 15:08:12 +00005561
Douglas Gregorebe10102009-08-20 07:17:43 +00005562template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005563StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005564TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005565 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00005566 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00005567 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005568 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005569
Douglas Gregorebe10102009-08-20 07:17:43 +00005570 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005571 ExprResult Cond;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005572 VarDecl *ConditionVar = 0;
5573 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005574 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005575 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005576 getDerived().TransformDefinition(
5577 S->getConditionVariable()->getLocation(),
5578 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005579 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005580 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005581 } else {
5582 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005583
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005584 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005585 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005586
5587 if (S->getCond()) {
5588 // Convert the condition to a boolean value.
Chad Rosier1dcde962012-08-08 18:46:20 +00005589 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005590 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005591 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005592 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005593
John McCallb268a282010-08-23 23:25:46 +00005594 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005595 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005596 }
Mike Stump11289f42009-09-09 15:08:12 +00005597
Chad Rosier1dcde962012-08-08 18:46:20 +00005598 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
John McCallb268a282010-08-23 23:25:46 +00005599 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005600 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005601
Douglas Gregorebe10102009-08-20 07:17:43 +00005602 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00005603 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005604 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005605 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005606
Richard Smith945f8d32013-01-14 22:39:08 +00005607 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
John McCallb268a282010-08-23 23:25:46 +00005608 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005609 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005610
Douglas Gregorebe10102009-08-20 07:17:43 +00005611 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005612 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005613 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005614 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005615
Douglas Gregorebe10102009-08-20 07:17:43 +00005616 if (!getDerived().AlwaysRebuild() &&
5617 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00005618 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005619 Inc.get() == S->getInc() &&
5620 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005621 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005622
Douglas Gregorebe10102009-08-20 07:17:43 +00005623 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005624 Init.get(), FullCond, ConditionVar,
5625 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005626}
5627
5628template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005629StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005630TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattnercab02a62011-02-17 20:34:02 +00005631 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5632 S->getLabel());
5633 if (!LD)
5634 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005635
Douglas Gregorebe10102009-08-20 07:17:43 +00005636 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00005637 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005638 cast<LabelDecl>(LD));
Douglas Gregorebe10102009-08-20 07:17:43 +00005639}
5640
5641template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005642StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005643TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005644 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00005645 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005646 return StmtError();
Eli Friedman9ccdb1d2012-01-31 22:47:07 +00005647 Target = SemaRef.MaybeCreateExprWithCleanups(Target.take());
Mike Stump11289f42009-09-09 15:08:12 +00005648
Douglas Gregorebe10102009-08-20 07:17:43 +00005649 if (!getDerived().AlwaysRebuild() &&
5650 Target.get() == S->getTarget())
John McCallc3007a22010-10-26 07:05:15 +00005651 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005652
5653 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00005654 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005655}
5656
5657template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005658StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005659TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00005660 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005661}
Mike Stump11289f42009-09-09 15:08:12 +00005662
Douglas Gregorebe10102009-08-20 07:17:43 +00005663template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005664StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005665TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00005666 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005667}
Mike Stump11289f42009-09-09 15:08:12 +00005668
Douglas Gregorebe10102009-08-20 07:17:43 +00005669template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005670StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005671TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005672 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregorebe10102009-08-20 07:17:43 +00005673 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005674 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00005675
Mike Stump11289f42009-09-09 15:08:12 +00005676 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00005677 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00005678 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005679}
Mike Stump11289f42009-09-09 15:08:12 +00005680
Douglas Gregorebe10102009-08-20 07:17:43 +00005681template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005682StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005683TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005684 bool DeclChanged = false;
Chris Lattner01cf8db2011-07-20 06:58:45 +00005685 SmallVector<Decl *, 4> Decls;
Aaron Ballman535bbcc2014-03-14 17:01:24 +00005686 for (auto *D : S->decls()) {
5687 Decl *Transformed = getDerived().TransformDefinition(D->getLocation(), 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
Aaron Ballman535bbcc2014-03-14 17:01:24 +00005691 if (Transformed != D)
Douglas Gregorebe10102009-08-20 07:17:43 +00005692 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;
Alexey Bataev3d76e772014-03-07 04:01:56 +00006305 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, 0);
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006306 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;
Alexey Bataev96d15102014-03-07 04:16:48 +00006315 getDerived().getSema().StartOpenMPDSABlock(OMPD_simd, DirName, 0);
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006316 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());
Aaron Ballman2205d2a2014-03-14 15:55:35 +00006358 for (auto *I : C->varlists()) {
6359 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(I));
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006360 if (EVar.isInvalid())
6361 return 0;
6362 Vars.push_back(EVar.take());
6363 }
6364 return getDerived().RebuildOMPPrivateClause(Vars,
6365 C->getLocStart(),
6366 C->getLParenLoc(),
6367 C->getLocEnd());
6368}
6369
Alexey Bataev758e55e2013-09-06 18:03:48 +00006370template<typename Derived>
6371OMPClause *
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006372TreeTransform<Derived>::TransformOMPFirstprivateClause(
6373 OMPFirstprivateClause *C) {
6374 llvm::SmallVector<Expr *, 16> Vars;
6375 Vars.reserve(C->varlist_size());
Aaron Ballman2205d2a2014-03-14 15:55:35 +00006376 for (auto *I : C->varlists()) {
6377 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(I));
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006378 if (EVar.isInvalid())
6379 return 0;
6380 Vars.push_back(EVar.take());
6381 }
6382 return getDerived().RebuildOMPFirstprivateClause(Vars,
6383 C->getLocStart(),
6384 C->getLParenLoc(),
6385 C->getLocEnd());
6386}
6387
6388template<typename Derived>
6389OMPClause *
Alexey Bataev758e55e2013-09-06 18:03:48 +00006390TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
6391 llvm::SmallVector<Expr *, 16> Vars;
6392 Vars.reserve(C->varlist_size());
Aaron Ballman2205d2a2014-03-14 15:55:35 +00006393 for (auto *I : C->varlists()) {
6394 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(I));
Alexey Bataev758e55e2013-09-06 18:03:48 +00006395 if (EVar.isInvalid())
6396 return 0;
6397 Vars.push_back(EVar.take());
6398 }
6399 return getDerived().RebuildOMPSharedClause(Vars,
6400 C->getLocStart(),
6401 C->getLParenLoc(),
6402 C->getLocEnd());
6403}
6404
Douglas Gregorebe10102009-08-20 07:17:43 +00006405//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00006406// Expression transformation
6407//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00006408template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006409ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006410TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006411 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006412}
Mike Stump11289f42009-09-09 15:08:12 +00006413
6414template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006415ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006416TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregorea972d32011-02-28 21:54:11 +00006417 NestedNameSpecifierLoc QualifierLoc;
6418 if (E->getQualifierLoc()) {
6419 QualifierLoc
6420 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6421 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00006422 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00006423 }
John McCallce546572009-12-08 09:08:17 +00006424
6425 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006426 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6427 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006428 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00006429 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006430
John McCall815039a2010-08-17 21:27:17 +00006431 DeclarationNameInfo NameInfo = E->getNameInfo();
6432 if (NameInfo.getName()) {
6433 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6434 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00006435 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00006436 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006437
6438 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00006439 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00006440 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006441 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00006442 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00006443
6444 // Mark it referenced in the new context regardless.
6445 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00006446 SemaRef.MarkDeclRefReferenced(E);
John McCallce546572009-12-08 09:08:17 +00006447
John McCallc3007a22010-10-26 07:05:15 +00006448 return SemaRef.Owned(E);
Douglas Gregor4bd90e52009-10-23 18:54:35 +00006449 }
John McCallce546572009-12-08 09:08:17 +00006450
6451 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCallb3774b52010-08-19 23:49:38 +00006452 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00006453 TemplateArgs = &TransArgs;
6454 TransArgs.setLAngleLoc(E->getLAngleLoc());
6455 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006456 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6457 E->getNumTemplateArgs(),
6458 TransArgs))
6459 return ExprError();
John McCallce546572009-12-08 09:08:17 +00006460 }
6461
Chad Rosier1dcde962012-08-08 18:46:20 +00006462 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregorea972d32011-02-28 21:54:11 +00006463 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00006464}
Mike Stump11289f42009-09-09 15:08:12 +00006465
Douglas Gregora16548e2009-08-11 05:31:07 +00006466template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006467ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006468TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00006469 return SemaRef.Owned(E);
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>::TransformFloatingLiteral(FloatingLiteral *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>::TransformImaginaryLiteral(ImaginaryLiteral *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>::TransformStringLiteral(StringLiteral *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>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00006493 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006494}
6495
6496template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006497ExprResult
Richard Smithc67fdd42012-03-07 08:35:16 +00006498TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
Argyrios Kyrtzidis25049092013-04-09 01:17:02 +00006499 if (FunctionDecl *FD = E->getDirectCallee())
6500 SemaRef.MarkFunctionReferenced(E->getLocStart(), FD);
Richard Smithc67fdd42012-03-07 08:35:16 +00006501 return SemaRef.MaybeBindToTemporary(E);
6502}
6503
6504template<typename Derived>
6505ExprResult
Peter Collingbourne91147592011-04-15 00:35:48 +00006506TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
6507 ExprResult ControllingExpr =
6508 getDerived().TransformExpr(E->getControllingExpr());
6509 if (ControllingExpr.isInvalid())
6510 return ExprError();
6511
Chris Lattner01cf8db2011-07-20 06:58:45 +00006512 SmallVector<Expr *, 4> AssocExprs;
6513 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbourne91147592011-04-15 00:35:48 +00006514 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
6515 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
6516 if (TS) {
6517 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
6518 if (!AssocType)
6519 return ExprError();
6520 AssocTypes.push_back(AssocType);
6521 } else {
6522 AssocTypes.push_back(0);
6523 }
6524
6525 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
6526 if (AssocExpr.isInvalid())
6527 return ExprError();
6528 AssocExprs.push_back(AssocExpr.release());
6529 }
6530
6531 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
6532 E->getDefaultLoc(),
6533 E->getRParenLoc(),
6534 ControllingExpr.release(),
Dmitri Gribenko82360372013-05-10 13:06:58 +00006535 AssocTypes,
6536 AssocExprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00006537}
6538
6539template<typename Derived>
6540ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006541TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006542 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006543 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006544 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006545
Douglas Gregora16548e2009-08-11 05:31:07 +00006546 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006547 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006548
John McCallb268a282010-08-23 23:25:46 +00006549 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006550 E->getRParen());
6551}
6552
Richard Smithdb2630f2012-10-21 03:28:35 +00006553/// \brief The operand of a unary address-of operator has special rules: it's
6554/// allowed to refer to a non-static member of a class even if there's no 'this'
6555/// object available.
6556template<typename Derived>
6557ExprResult
6558TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
6559 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
6560 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true);
6561 else
6562 return getDerived().TransformExpr(E);
6563}
6564
Mike Stump11289f42009-09-09 15:08:12 +00006565template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006566ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006567TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smitheebe125f2013-05-21 23:29:46 +00006568 ExprResult SubExpr;
6569 if (E->getOpcode() == UO_AddrOf)
6570 SubExpr = TransformAddressOfOperand(E->getSubExpr());
6571 else
6572 SubExpr = TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006573 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006574 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006575
Douglas Gregora16548e2009-08-11 05:31:07 +00006576 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006577 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006578
Douglas Gregora16548e2009-08-11 05:31:07 +00006579 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
6580 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00006581 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006582}
Mike Stump11289f42009-09-09 15:08:12 +00006583
Douglas Gregora16548e2009-08-11 05:31:07 +00006584template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006585ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00006586TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
6587 // Transform the type.
6588 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
6589 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00006590 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006591
Douglas Gregor882211c2010-04-28 22:16:22 +00006592 // Transform all of the components into components similar to what the
6593 // parser uses.
Chad Rosier1dcde962012-08-08 18:46:20 +00006594 // FIXME: It would be slightly more efficient in the non-dependent case to
6595 // just map FieldDecls, rather than requiring the rebuilder to look for
6596 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00006597 // template code that we don't care.
6598 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00006599 typedef Sema::OffsetOfComponent Component;
Douglas Gregor882211c2010-04-28 22:16:22 +00006600 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner01cf8db2011-07-20 06:58:45 +00006601 SmallVector<Component, 4> Components;
Douglas Gregor882211c2010-04-28 22:16:22 +00006602 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
6603 const Node &ON = E->getComponent(I);
6604 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00006605 Comp.isBrackets = true;
Abramo Bagnara6b6f0512011-03-12 09:45:03 +00006606 Comp.LocStart = ON.getSourceRange().getBegin();
6607 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor882211c2010-04-28 22:16:22 +00006608 switch (ON.getKind()) {
6609 case Node::Array: {
6610 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00006611 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00006612 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006613 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006614
Douglas Gregor882211c2010-04-28 22:16:22 +00006615 ExprChanged = ExprChanged || Index.get() != FromIndex;
6616 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00006617 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00006618 break;
6619 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006620
Douglas Gregor882211c2010-04-28 22:16:22 +00006621 case Node::Field:
6622 case Node::Identifier:
6623 Comp.isBrackets = false;
6624 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00006625 if (!Comp.U.IdentInfo)
6626 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00006627
Douglas Gregor882211c2010-04-28 22:16:22 +00006628 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006629
Douglas Gregord1702062010-04-29 00:18:15 +00006630 case Node::Base:
6631 // Will be recomputed during the rebuild.
6632 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00006633 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006634
Douglas Gregor882211c2010-04-28 22:16:22 +00006635 Components.push_back(Comp);
6636 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006637
Douglas Gregor882211c2010-04-28 22:16:22 +00006638 // If nothing changed, retain the existing expression.
6639 if (!getDerived().AlwaysRebuild() &&
6640 Type == E->getTypeSourceInfo() &&
6641 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00006642 return SemaRef.Owned(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00006643
Douglas Gregor882211c2010-04-28 22:16:22 +00006644 // Build a new offsetof expression.
6645 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
6646 Components.data(), Components.size(),
6647 E->getRParenLoc());
6648}
6649
6650template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006651ExprResult
John McCall8d69a212010-11-15 23:31:06 +00006652TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
6653 assert(getDerived().AlreadyTransformed(E->getType()) &&
6654 "opaque value expression requires transformation");
6655 return SemaRef.Owned(E);
6656}
6657
6658template<typename Derived>
6659ExprResult
John McCallfe96e0b2011-11-06 09:01:30 +00006660TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCalle9290822011-11-30 04:42:31 +00006661 // Rebuild the syntactic form. The original syntactic form has
6662 // opaque-value expressions in it, so strip those away and rebuild
6663 // the result. This is a really awful way of doing this, but the
6664 // better solution (rebuilding the semantic expressions and
6665 // rebinding OVEs as necessary) doesn't work; we'd need
6666 // TreeTransform to not strip away implicit conversions.
6667 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
6668 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCallfe96e0b2011-11-06 09:01:30 +00006669 if (result.isInvalid()) return ExprError();
6670
6671 // If that gives us a pseudo-object result back, the pseudo-object
6672 // expression must have been an lvalue-to-rvalue conversion which we
6673 // should reapply.
6674 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
6675 result = SemaRef.checkPseudoObjectRValue(result.take());
6676
6677 return result;
6678}
6679
6680template<typename Derived>
6681ExprResult
Peter Collingbournee190dee2011-03-11 19:24:49 +00006682TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
6683 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006684 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00006685 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00006686
John McCallbcd03502009-12-07 02:54:59 +00006687 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00006688 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00006689 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006690
John McCall4c98fd82009-11-04 07:28:41 +00006691 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCallc3007a22010-10-26 07:05:15 +00006692 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006693
Peter Collingbournee190dee2011-03-11 19:24:49 +00006694 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
6695 E->getKind(),
6696 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00006697 }
Mike Stump11289f42009-09-09 15:08:12 +00006698
Eli Friedmane4f22df2012-02-29 04:03:55 +00006699 // C++0x [expr.sizeof]p1:
6700 // The operand is either an expression, which is an unevaluated operand
6701 // [...]
Eli Friedman15681d62012-09-26 04:34:21 +00006702 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
6703 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00006704
Eli Friedmane4f22df2012-02-29 04:03:55 +00006705 ExprResult SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
6706 if (SubExpr.isInvalid())
6707 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006708
Eli Friedmane4f22df2012-02-29 04:03:55 +00006709 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
6710 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006711
Peter Collingbournee190dee2011-03-11 19:24:49 +00006712 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
6713 E->getOperatorLoc(),
6714 E->getKind(),
6715 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00006716}
Mike Stump11289f42009-09-09 15:08:12 +00006717
Douglas Gregora16548e2009-08-11 05:31:07 +00006718template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006719ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006720TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006721 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006722 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006723 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006724
John McCalldadc5752010-08-24 06:29:42 +00006725 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006726 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006727 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006728
6729
Douglas Gregora16548e2009-08-11 05:31:07 +00006730 if (!getDerived().AlwaysRebuild() &&
6731 LHS.get() == E->getLHS() &&
6732 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00006733 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006734
John McCallb268a282010-08-23 23:25:46 +00006735 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006736 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00006737 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006738 E->getRBracketLoc());
6739}
Mike Stump11289f42009-09-09 15:08:12 +00006740
6741template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006742ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006743TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006744 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00006745 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00006746 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006747 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006748
6749 // Transform arguments.
6750 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006751 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00006752 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00006753 &ArgChanged))
6754 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006755
Douglas Gregora16548e2009-08-11 05:31:07 +00006756 if (!getDerived().AlwaysRebuild() &&
6757 Callee.get() == E->getCallee() &&
6758 !ArgChanged)
Dmitri Gribenko76bb5cabfa2012-09-10 21:20:09 +00006759 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00006760
Douglas Gregora16548e2009-08-11 05:31:07 +00006761 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00006762 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00006763 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00006764 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006765 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00006766 E->getRParenLoc());
6767}
Mike Stump11289f42009-09-09 15:08:12 +00006768
6769template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006770ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006771TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006772 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00006773 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006774 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006775
Douglas Gregorea972d32011-02-28 21:54:11 +00006776 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorf405d7e2009-08-31 23:41:50 +00006777 if (E->hasQualifier()) {
Douglas Gregorea972d32011-02-28 21:54:11 +00006778 QualifierLoc
6779 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00006780
Douglas Gregorea972d32011-02-28 21:54:11 +00006781 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00006782 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00006783 }
Abramo Bagnara7945c982012-01-27 09:46:47 +00006784 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00006785
Eli Friedman2cfcef62009-12-04 06:40:45 +00006786 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006787 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
6788 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006789 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00006790 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006791
John McCall16df1e52010-03-30 21:47:33 +00006792 NamedDecl *FoundDecl = E->getFoundDecl();
6793 if (FoundDecl == E->getMemberDecl()) {
6794 FoundDecl = Member;
6795 } else {
6796 FoundDecl = cast_or_null<NamedDecl>(
6797 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
6798 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00006799 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00006800 }
6801
Douglas Gregora16548e2009-08-11 05:31:07 +00006802 if (!getDerived().AlwaysRebuild() &&
6803 Base.get() == E->getBase() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00006804 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00006805 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00006806 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00006807 !E->hasExplicitTemplateArgs()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006808
Anders Carlsson9c45ad72009-12-22 05:24:09 +00006809 // Mark it referenced in the new context regardless.
6810 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00006811 SemaRef.MarkMemberReferenced(E);
6812
John McCallc3007a22010-10-26 07:05:15 +00006813 return SemaRef.Owned(E);
Anders Carlsson9c45ad72009-12-22 05:24:09 +00006814 }
Douglas Gregora16548e2009-08-11 05:31:07 +00006815
John McCall6b51f282009-11-23 01:53:49 +00006816 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00006817 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00006818 TransArgs.setLAngleLoc(E->getLAngleLoc());
6819 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006820 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6821 E->getNumTemplateArgs(),
6822 TransArgs))
6823 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00006824 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006825
Douglas Gregora16548e2009-08-11 05:31:07 +00006826 // FIXME: Bogus source location for the operator
6827 SourceLocation FakeOperatorLoc
6828 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
6829
John McCall38836f02010-01-15 08:34:02 +00006830 // FIXME: to do this check properly, we will need to preserve the
6831 // first-qualifier-in-scope here, just in case we had a dependent
6832 // base (and therefore couldn't do the check) and a
6833 // nested-name-qualifier (and therefore could do the lookup).
6834 NamedDecl *FirstQualifierInScope = 0;
6835
John McCallb268a282010-08-23 23:25:46 +00006836 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00006837 E->isArrow(),
Douglas Gregorea972d32011-02-28 21:54:11 +00006838 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00006839 TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006840 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00006841 Member,
John McCall16df1e52010-03-30 21:47:33 +00006842 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00006843 (E->hasExplicitTemplateArgs()
John McCall6b51f282009-11-23 01:53:49 +00006844 ? &TransArgs : 0),
John McCall38836f02010-01-15 08:34:02 +00006845 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00006846}
Mike Stump11289f42009-09-09 15:08:12 +00006847
Douglas Gregora16548e2009-08-11 05:31:07 +00006848template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006849ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006850TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00006851 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006852 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006853 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006854
John McCalldadc5752010-08-24 06:29:42 +00006855 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006856 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006857 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006858
Douglas Gregora16548e2009-08-11 05:31:07 +00006859 if (!getDerived().AlwaysRebuild() &&
6860 LHS.get() == E->getLHS() &&
6861 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00006862 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006863
Lang Hames5de91cc2012-10-02 04:45:10 +00006864 Sema::FPContractStateRAII FPContractState(getSema());
6865 getSema().FPFeatures.fp_contract = E->isFPContractable();
6866
Douglas Gregora16548e2009-08-11 05:31:07 +00006867 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00006868 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006869}
6870
Mike Stump11289f42009-09-09 15:08:12 +00006871template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006872ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006873TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00006874 CompoundAssignOperator *E) {
6875 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006876}
Mike Stump11289f42009-09-09 15:08:12 +00006877
Douglas Gregora16548e2009-08-11 05:31:07 +00006878template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00006879ExprResult TreeTransform<Derived>::
6880TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
6881 // Just rebuild the common and RHS expressions and see whether we
6882 // get any changes.
6883
6884 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
6885 if (commonExpr.isInvalid())
6886 return ExprError();
6887
6888 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
6889 if (rhs.isInvalid())
6890 return ExprError();
6891
6892 if (!getDerived().AlwaysRebuild() &&
6893 commonExpr.get() == e->getCommon() &&
6894 rhs.get() == e->getFalseExpr())
6895 return SemaRef.Owned(e);
6896
6897 return getDerived().RebuildConditionalOperator(commonExpr.take(),
6898 e->getQuestionLoc(),
6899 0,
6900 e->getColonLoc(),
6901 rhs.get());
6902}
6903
6904template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006905ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006906TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00006907 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00006908 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006909 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006910
John McCalldadc5752010-08-24 06:29:42 +00006911 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006912 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006913 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006914
John McCalldadc5752010-08-24 06:29:42 +00006915 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006916 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006917 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006918
Douglas Gregora16548e2009-08-11 05:31:07 +00006919 if (!getDerived().AlwaysRebuild() &&
6920 Cond.get() == E->getCond() &&
6921 LHS.get() == E->getLHS() &&
6922 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00006923 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006924
John McCallb268a282010-08-23 23:25:46 +00006925 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00006926 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00006927 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00006928 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00006929 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006930}
Mike Stump11289f42009-09-09 15:08:12 +00006931
6932template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006933ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006934TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00006935 // Implicit casts are eliminated during transformation, since they
6936 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00006937 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006938}
Mike Stump11289f42009-09-09 15:08:12 +00006939
Douglas Gregora16548e2009-08-11 05:31:07 +00006940template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006941ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006942TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006943 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6944 if (!Type)
6945 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006946
John McCalldadc5752010-08-24 06:29:42 +00006947 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00006948 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006949 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006950 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006951
Douglas Gregora16548e2009-08-11 05:31:07 +00006952 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006953 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006954 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006955 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006956
John McCall97513962010-01-15 18:39:57 +00006957 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006958 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00006959 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006960 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006961}
Mike Stump11289f42009-09-09 15:08:12 +00006962
Douglas Gregora16548e2009-08-11 05:31:07 +00006963template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006964ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006965TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00006966 TypeSourceInfo *OldT = E->getTypeSourceInfo();
6967 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
6968 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00006969 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006970
John McCalldadc5752010-08-24 06:29:42 +00006971 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00006972 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006973 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006974
Douglas Gregora16548e2009-08-11 05:31:07 +00006975 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00006976 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006977 Init.get() == E->getInitializer())
Douglas Gregorc7f46f22011-12-10 00:23:21 +00006978 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006979
John McCall5d7aa7f2010-01-19 22:33:45 +00006980 // Note: the expression type doesn't necessarily match the
6981 // type-as-written, but that's okay, because it should always be
6982 // derivable from the initializer.
6983
John McCalle15bbff2010-01-18 19:35:47 +00006984 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00006985 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00006986 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006987}
Mike Stump11289f42009-09-09 15:08:12 +00006988
Douglas Gregora16548e2009-08-11 05:31:07 +00006989template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006990ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006991TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006992 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00006993 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006994 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006995
Douglas Gregora16548e2009-08-11 05:31:07 +00006996 if (!getDerived().AlwaysRebuild() &&
6997 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00006998 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006999
Douglas Gregora16548e2009-08-11 05:31:07 +00007000 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00007001 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00007002 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00007003 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00007004 E->getAccessorLoc(),
7005 E->getAccessor());
7006}
Mike Stump11289f42009-09-09 15:08:12 +00007007
Douglas Gregora16548e2009-08-11 05:31:07 +00007008template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007009ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007010TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007011 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00007012
Benjamin Kramerf0623432012-08-23 22:51:59 +00007013 SmallVector<Expr*, 4> Inits;
Chad Rosier1dcde962012-08-08 18:46:20 +00007014 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00007015 Inits, &InitChanged))
7016 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007017
Douglas Gregora16548e2009-08-11 05:31:07 +00007018 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCallc3007a22010-10-26 07:05:15 +00007019 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007020
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007021 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00007022 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00007023}
Mike Stump11289f42009-09-09 15:08:12 +00007024
Douglas Gregora16548e2009-08-11 05:31:07 +00007025template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007026ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007027TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007028 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00007029
Douglas Gregorebe10102009-08-20 07:17:43 +00007030 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00007031 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00007032 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007033 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007034
Douglas Gregorebe10102009-08-20 07:17:43 +00007035 // transform the designators.
Benjamin Kramerf0623432012-08-23 22:51:59 +00007036 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregora16548e2009-08-11 05:31:07 +00007037 bool ExprChanged = false;
7038 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
7039 DEnd = E->designators_end();
7040 D != DEnd; ++D) {
7041 if (D->isFieldDesignator()) {
7042 Desig.AddDesignator(Designator::getField(D->getFieldName(),
7043 D->getDotLoc(),
7044 D->getFieldLoc()));
7045 continue;
7046 }
Mike Stump11289f42009-09-09 15:08:12 +00007047
Douglas Gregora16548e2009-08-11 05:31:07 +00007048 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00007049 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00007050 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007051 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007052
7053 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007054 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00007055
Douglas Gregora16548e2009-08-11 05:31:07 +00007056 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
7057 ArrayExprs.push_back(Index.release());
7058 continue;
7059 }
Mike Stump11289f42009-09-09 15:08:12 +00007060
Douglas Gregora16548e2009-08-11 05:31:07 +00007061 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00007062 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00007063 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
7064 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007065 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007066
John McCalldadc5752010-08-24 06:29:42 +00007067 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00007068 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007069 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007070
7071 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007072 End.get(),
7073 D->getLBracketLoc(),
7074 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00007075
Douglas Gregora16548e2009-08-11 05:31:07 +00007076 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
7077 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00007078
Douglas Gregora16548e2009-08-11 05:31:07 +00007079 ArrayExprs.push_back(Start.release());
7080 ArrayExprs.push_back(End.release());
7081 }
Mike Stump11289f42009-09-09 15:08:12 +00007082
Douglas Gregora16548e2009-08-11 05:31:07 +00007083 if (!getDerived().AlwaysRebuild() &&
7084 Init.get() == E->getInit() &&
7085 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00007086 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007087
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007088 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00007089 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00007090 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007091}
Mike Stump11289f42009-09-09 15:08:12 +00007092
Douglas Gregora16548e2009-08-11 05:31:07 +00007093template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007094ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007095TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007096 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00007097 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier1dcde962012-08-08 18:46:20 +00007098
Douglas Gregor3da3c062009-10-28 00:29:27 +00007099 // FIXME: Will we ever have proper type location here? Will we actually
7100 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00007101 QualType T = getDerived().TransformType(E->getType());
7102 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00007103 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007104
Douglas Gregora16548e2009-08-11 05:31:07 +00007105 if (!getDerived().AlwaysRebuild() &&
7106 T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00007107 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007108
Douglas Gregora16548e2009-08-11 05:31:07 +00007109 return getDerived().RebuildImplicitValueInitExpr(T);
7110}
Mike Stump11289f42009-09-09 15:08:12 +00007111
Douglas Gregora16548e2009-08-11 05:31:07 +00007112template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007113ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007114TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00007115 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
7116 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007117 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007118
John McCalldadc5752010-08-24 06:29:42 +00007119 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007120 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007121 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007122
Douglas Gregora16548e2009-08-11 05:31:07 +00007123 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00007124 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007125 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00007126 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007127
John McCallb268a282010-08-23 23:25:46 +00007128 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00007129 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007130}
7131
7132template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007133ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007134TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007135 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007136 SmallVector<Expr*, 4> Inits;
Douglas Gregora3efea12011-01-03 19:04:46 +00007137 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
7138 &ArgumentChanged))
7139 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007140
Douglas Gregora16548e2009-08-11 05:31:07 +00007141 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007142 Inits,
Douglas Gregora16548e2009-08-11 05:31:07 +00007143 E->getRParenLoc());
7144}
Mike Stump11289f42009-09-09 15:08:12 +00007145
Douglas Gregora16548e2009-08-11 05:31:07 +00007146/// \brief Transform an address-of-label expression.
7147///
7148/// By default, the transformation of an address-of-label expression always
7149/// rebuilds the expression, so that the label identifier can be resolved to
7150/// the corresponding label statement by semantic analysis.
7151template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007152ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007153TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +00007154 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
7155 E->getLabel());
7156 if (!LD)
7157 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007158
Douglas Gregora16548e2009-08-11 05:31:07 +00007159 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00007160 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +00007161}
Mike Stump11289f42009-09-09 15:08:12 +00007162
7163template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00007164ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007165TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalled7b2782012-04-06 18:20:53 +00007166 SemaRef.ActOnStartStmtExpr();
John McCalldadc5752010-08-24 06:29:42 +00007167 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00007168 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCalled7b2782012-04-06 18:20:53 +00007169 if (SubStmt.isInvalid()) {
7170 SemaRef.ActOnStmtExprError();
John McCallfaf5fb42010-08-26 23:41:50 +00007171 return ExprError();
John McCalled7b2782012-04-06 18:20:53 +00007172 }
Mike Stump11289f42009-09-09 15:08:12 +00007173
Douglas Gregora16548e2009-08-11 05:31:07 +00007174 if (!getDerived().AlwaysRebuild() &&
John McCalled7b2782012-04-06 18:20:53 +00007175 SubStmt.get() == E->getSubStmt()) {
7176 // Calling this an 'error' is unintuitive, but it does the right thing.
7177 SemaRef.ActOnStmtExprError();
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007178 return SemaRef.MaybeBindToTemporary(E);
John McCalled7b2782012-04-06 18:20:53 +00007179 }
Mike Stump11289f42009-09-09 15:08:12 +00007180
7181 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007182 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007183 E->getRParenLoc());
7184}
Mike Stump11289f42009-09-09 15:08:12 +00007185
Douglas Gregora16548e2009-08-11 05:31:07 +00007186template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007187ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007188TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007189 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00007190 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007191 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007192
John McCalldadc5752010-08-24 06:29:42 +00007193 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007194 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007195 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007196
John McCalldadc5752010-08-24 06:29:42 +00007197 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007198 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007199 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007200
Douglas Gregora16548e2009-08-11 05:31:07 +00007201 if (!getDerived().AlwaysRebuild() &&
7202 Cond.get() == E->getCond() &&
7203 LHS.get() == E->getLHS() &&
7204 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00007205 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007206
Douglas Gregora16548e2009-08-11 05:31:07 +00007207 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00007208 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007209 E->getRParenLoc());
7210}
Mike Stump11289f42009-09-09 15:08:12 +00007211
Douglas Gregora16548e2009-08-11 05:31:07 +00007212template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007213ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007214TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007215 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007216}
7217
7218template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007219ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007220TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007221 switch (E->getOperator()) {
7222 case OO_New:
7223 case OO_Delete:
7224 case OO_Array_New:
7225 case OO_Array_Delete:
7226 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier1dcde962012-08-08 18:46:20 +00007227
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007228 case OO_Call: {
7229 // This is a call to an object's operator().
7230 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
7231
7232 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00007233 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007234 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007235 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007236
7237 // FIXME: Poor location information
7238 SourceLocation FakeLParenLoc
7239 = SemaRef.PP.getLocForEndOfToken(
7240 static_cast<Expr *>(Object.get())->getLocEnd());
7241
7242 // Transform the call arguments.
Benjamin Kramerf0623432012-08-23 22:51:59 +00007243 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00007244 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregora3efea12011-01-03 19:04:46 +00007245 Args))
7246 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007247
John McCallb268a282010-08-23 23:25:46 +00007248 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007249 Args,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007250 E->getLocEnd());
7251 }
7252
7253#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
7254 case OO_##Name:
7255#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
7256#include "clang/Basic/OperatorKinds.def"
7257 case OO_Subscript:
7258 // Handled below.
7259 break;
7260
7261 case OO_Conditional:
7262 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007263
7264 case OO_None:
7265 case NUM_OVERLOADED_OPERATORS:
7266 llvm_unreachable("not an overloaded operator?");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007267 }
7268
John McCalldadc5752010-08-24 06:29:42 +00007269 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00007270 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007271 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007272
Richard Smithdb2630f2012-10-21 03:28:35 +00007273 ExprResult First;
7274 if (E->getOperator() == OO_Amp)
7275 First = getDerived().TransformAddressOfOperand(E->getArg(0));
7276 else
7277 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00007278 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007279 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007280
John McCalldadc5752010-08-24 06:29:42 +00007281 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00007282 if (E->getNumArgs() == 2) {
7283 Second = getDerived().TransformExpr(E->getArg(1));
7284 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007285 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007286 }
Mike Stump11289f42009-09-09 15:08:12 +00007287
Douglas Gregora16548e2009-08-11 05:31:07 +00007288 if (!getDerived().AlwaysRebuild() &&
7289 Callee.get() == E->getCallee() &&
7290 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00007291 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007292 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00007293
Lang Hames5de91cc2012-10-02 04:45:10 +00007294 Sema::FPContractStateRAII FPContractState(getSema());
7295 getSema().FPFeatures.fp_contract = E->isFPContractable();
7296
Douglas Gregora16548e2009-08-11 05:31:07 +00007297 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
7298 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00007299 Callee.get(),
7300 First.get(),
7301 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007302}
Mike Stump11289f42009-09-09 15:08:12 +00007303
Douglas Gregora16548e2009-08-11 05:31:07 +00007304template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007305ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007306TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
7307 return getDerived().TransformCallExpr(E);
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
Peter Collingbourne41f85462011-02-09 21:07:24 +00007312TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
7313 // Transform the callee.
7314 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
7315 if (Callee.isInvalid())
7316 return ExprError();
7317
7318 // Transform exec config.
7319 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
7320 if (EC.isInvalid())
7321 return ExprError();
7322
7323 // Transform arguments.
7324 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007325 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00007326 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00007327 &ArgChanged))
7328 return ExprError();
7329
7330 if (!getDerived().AlwaysRebuild() &&
7331 Callee.get() == E->getCallee() &&
7332 !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007333 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbourne41f85462011-02-09 21:07:24 +00007334
7335 // FIXME: Wrong source location information for the '('.
7336 SourceLocation FakeLParenLoc
7337 = ((Expr *)Callee.get())->getSourceRange().getBegin();
7338 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007339 Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00007340 E->getRParenLoc(), EC.get());
7341}
7342
7343template<typename Derived>
7344ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007345TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007346 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7347 if (!Type)
7348 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007349
John McCalldadc5752010-08-24 06:29:42 +00007350 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00007351 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007352 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007353 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007354
Douglas Gregora16548e2009-08-11 05:31:07 +00007355 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007356 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007357 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00007358 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007359 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00007360 E->getStmtClass(),
Fariborz Jahanianf0738712013-02-22 22:02:53 +00007361 E->getAngleBrackets().getBegin(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007362 Type,
Fariborz Jahanianf0738712013-02-22 22:02:53 +00007363 E->getAngleBrackets().getEnd(),
7364 // FIXME. this should be '(' location
7365 E->getAngleBrackets().getEnd(),
John McCallb268a282010-08-23 23:25:46 +00007366 SubExpr.get(),
Abramo Bagnara9fb43862012-10-15 21:08:58 +00007367 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007368}
Mike Stump11289f42009-09-09 15:08:12 +00007369
Douglas Gregora16548e2009-08-11 05:31:07 +00007370template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007371ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007372TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
7373 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007374}
Mike Stump11289f42009-09-09 15:08:12 +00007375
7376template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007377ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007378TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
7379 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00007380}
7381
Douglas Gregora16548e2009-08-11 05:31:07 +00007382template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007383ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007384TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007385 CXXReinterpretCastExpr *E) {
7386 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007387}
Mike Stump11289f42009-09-09 15:08:12 +00007388
Douglas Gregora16548e2009-08-11 05:31:07 +00007389template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007390ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007391TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *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
Douglas Gregora16548e2009-08-11 05:31:07 +00007397TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007398 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007399 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7400 if (!Type)
7401 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007402
John McCalldadc5752010-08-24 06:29:42 +00007403 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00007404 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007405 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007406 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007407
Douglas Gregora16548e2009-08-11 05:31:07 +00007408 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007409 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007410 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00007411 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007412
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007413 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Eli Friedman89fe0d52013-08-15 22:02:56 +00007414 E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007415 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007416 E->getRParenLoc());
7417}
Mike Stump11289f42009-09-09 15:08:12 +00007418
Douglas Gregora16548e2009-08-11 05:31:07 +00007419template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007420ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007421TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007422 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00007423 TypeSourceInfo *TInfo
7424 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7425 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007426 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007427
Douglas Gregora16548e2009-08-11 05:31:07 +00007428 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00007429 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00007430 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007431
Douglas Gregor9da64192010-04-26 22:37:10 +00007432 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7433 E->getLocStart(),
7434 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00007435 E->getLocEnd());
7436 }
Mike Stump11289f42009-09-09 15:08:12 +00007437
Eli Friedman456f0182012-01-20 01:26:23 +00007438 // We don't know whether the subexpression is potentially evaluated until
7439 // after we perform semantic analysis. We speculatively assume it is
7440 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregora16548e2009-08-11 05:31:07 +00007441 // potentially evaluated.
Eli Friedman15681d62012-09-26 04:34:21 +00007442 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
7443 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00007444
John McCalldadc5752010-08-24 06:29:42 +00007445 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00007446 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007447 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007448
Douglas Gregora16548e2009-08-11 05:31:07 +00007449 if (!getDerived().AlwaysRebuild() &&
7450 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00007451 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007452
Douglas Gregor9da64192010-04-26 22:37:10 +00007453 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7454 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00007455 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007456 E->getLocEnd());
7457}
7458
7459template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007460ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00007461TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
7462 if (E->isTypeOperand()) {
7463 TypeSourceInfo *TInfo
7464 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7465 if (!TInfo)
7466 return ExprError();
7467
7468 if (!getDerived().AlwaysRebuild() &&
7469 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00007470 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00007471
Douglas Gregor69735112011-03-06 17:40:41 +00007472 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet9f4f2072010-09-08 12:20:18 +00007473 E->getLocStart(),
7474 TInfo,
7475 E->getLocEnd());
7476 }
7477
Francois Pichet9f4f2072010-09-08 12:20:18 +00007478 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7479
7480 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
7481 if (SubExpr.isInvalid())
7482 return ExprError();
7483
7484 if (!getDerived().AlwaysRebuild() &&
7485 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00007486 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00007487
7488 return getDerived().RebuildCXXUuidofExpr(E->getType(),
7489 E->getLocStart(),
7490 SubExpr.get(),
7491 E->getLocEnd());
7492}
7493
7494template<typename Derived>
7495ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007496TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007497 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007498}
Mike Stump11289f42009-09-09 15:08:12 +00007499
Douglas Gregora16548e2009-08-11 05:31:07 +00007500template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007501ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007502TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007503 CXXNullPtrLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007504 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007505}
Mike Stump11289f42009-09-09 15:08:12 +00007506
Douglas Gregora16548e2009-08-11 05:31:07 +00007507template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007508ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007509TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Richard Smithc3d2ebb2013-06-07 02:33:37 +00007510 QualType T = getSema().getCurrentThisType();
Mike Stump11289f42009-09-09 15:08:12 +00007511
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00007512 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
7513 // Make sure that we capture 'this'.
7514 getSema().CheckCXXThisCapture(E->getLocStart());
John McCallc3007a22010-10-26 07:05:15 +00007515 return SemaRef.Owned(E);
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00007516 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007517
Douglas Gregorb15af892010-01-07 23:12:05 +00007518 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00007519}
Mike Stump11289f42009-09-09 15:08:12 +00007520
Douglas Gregora16548e2009-08-11 05:31:07 +00007521template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007522ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007523TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007524 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007525 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007526 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007527
Douglas Gregora16548e2009-08-11 05:31:07 +00007528 if (!getDerived().AlwaysRebuild() &&
7529 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00007530 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007531
Douglas Gregor53e191ed2011-07-06 22:04:06 +00007532 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
7533 E->isThrownVariableInScope());
Douglas Gregora16548e2009-08-11 05:31:07 +00007534}
Mike Stump11289f42009-09-09 15:08:12 +00007535
Douglas Gregora16548e2009-08-11 05:31:07 +00007536template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007537ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007538TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00007539 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007540 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
7541 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007542 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00007543 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007544
Chandler Carruth794da4c2010-02-08 06:42:49 +00007545 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007546 Param == E->getParam())
John McCallc3007a22010-10-26 07:05:15 +00007547 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007548
Douglas Gregor033f6752009-12-23 23:03:06 +00007549 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00007550}
Mike Stump11289f42009-09-09 15:08:12 +00007551
Douglas Gregora16548e2009-08-11 05:31:07 +00007552template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007553ExprResult
Richard Smith852c9db2013-04-20 22:23:05 +00007554TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
7555 FieldDecl *Field
7556 = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(),
7557 E->getField()));
7558 if (!Field)
7559 return ExprError();
7560
7561 if (!getDerived().AlwaysRebuild() && Field == E->getField())
7562 return SemaRef.Owned(E);
7563
7564 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
7565}
7566
7567template<typename Derived>
7568ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00007569TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
7570 CXXScalarValueInitExpr *E) {
7571 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7572 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007573 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007574
Douglas Gregora16548e2009-08-11 05:31:07 +00007575 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00007576 T == E->getTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00007577 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007578
Chad Rosier1dcde962012-08-08 18:46:20 +00007579 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregor2b88c112010-09-08 00:15:04 +00007580 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00007581 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007582}
Mike Stump11289f42009-09-09 15:08:12 +00007583
Douglas Gregora16548e2009-08-11 05:31:07 +00007584template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007585ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007586TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007587 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00007588 TypeSourceInfo *AllocTypeInfo
7589 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
7590 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007591 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007592
Douglas Gregora16548e2009-08-11 05:31:07 +00007593 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00007594 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00007595 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007596 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007597
Douglas Gregora16548e2009-08-11 05:31:07 +00007598 // Transform the placement arguments (if any).
7599 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007600 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier1dcde962012-08-08 18:46:20 +00007601 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregora3efea12011-01-03 19:04:46 +00007602 E->getNumPlacementArgs(), true,
7603 PlacementArgs, &ArgumentChanged))
Sebastian Redl6047f072012-02-16 12:22:20 +00007604 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007605
Sebastian Redl6047f072012-02-16 12:22:20 +00007606 // Transform the initializer (if any).
7607 Expr *OldInit = E->getInitializer();
7608 ExprResult NewInit;
7609 if (OldInit)
7610 NewInit = getDerived().TransformExpr(OldInit);
7611 if (NewInit.isInvalid())
7612 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007613
Sebastian Redl6047f072012-02-16 12:22:20 +00007614 // Transform new operator and delete operator.
Douglas Gregord2d9da02010-02-26 00:38:10 +00007615 FunctionDecl *OperatorNew = 0;
7616 if (E->getOperatorNew()) {
7617 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007618 getDerived().TransformDecl(E->getLocStart(),
7619 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00007620 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00007621 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00007622 }
7623
7624 FunctionDecl *OperatorDelete = 0;
7625 if (E->getOperatorDelete()) {
7626 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007627 getDerived().TransformDecl(E->getLocStart(),
7628 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00007629 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00007630 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00007631 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007632
Douglas Gregora16548e2009-08-11 05:31:07 +00007633 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00007634 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007635 ArraySize.get() == E->getArraySize() &&
Sebastian Redl6047f072012-02-16 12:22:20 +00007636 NewInit.get() == OldInit &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00007637 OperatorNew == E->getOperatorNew() &&
7638 OperatorDelete == E->getOperatorDelete() &&
7639 !ArgumentChanged) {
7640 // Mark any declarations we need as referenced.
7641 // FIXME: instantiation-specific.
Douglas Gregord2d9da02010-02-26 00:38:10 +00007642 if (OperatorNew)
Eli Friedmanfa0df832012-02-02 03:46:19 +00007643 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregord2d9da02010-02-26 00:38:10 +00007644 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00007645 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00007646
Sebastian Redl6047f072012-02-16 12:22:20 +00007647 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor72912fb2011-07-26 15:11:03 +00007648 QualType ElementType
7649 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
7650 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
7651 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
7652 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedmanfa0df832012-02-02 03:46:19 +00007653 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor72912fb2011-07-26 15:11:03 +00007654 }
7655 }
7656 }
Sebastian Redl6047f072012-02-16 12:22:20 +00007657
John McCallc3007a22010-10-26 07:05:15 +00007658 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00007659 }
Mike Stump11289f42009-09-09 15:08:12 +00007660
Douglas Gregor0744ef62010-09-07 21:49:58 +00007661 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00007662 if (!ArraySize.get()) {
7663 // If no array size was specified, but the new expression was
7664 // instantiated with an array type (e.g., "new T" where T is
7665 // instantiated with "int[4]"), extract the outer bound from the
7666 // array type as our array size. We do this with constant and
7667 // dependently-sized array types.
7668 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
7669 if (!ArrayT) {
7670 // Do nothing
7671 } else if (const ConstantArrayType *ConsArrayT
7672 = dyn_cast<ConstantArrayType>(ArrayT)) {
Chad Rosier1dcde962012-08-08 18:46:20 +00007673 ArraySize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00007674 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
Chad Rosier1dcde962012-08-08 18:46:20 +00007675 ConsArrayT->getSize(),
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00007676 SemaRef.Context.getSizeType(),
7677 /*FIXME:*/E->getLocStart()));
Douglas Gregor2e9c7952009-12-22 17:13:37 +00007678 AllocType = ConsArrayT->getElementType();
7679 } else if (const DependentSizedArrayType *DepArrayT
7680 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
7681 if (DepArrayT->getSizeExpr()) {
John McCallc3007a22010-10-26 07:05:15 +00007682 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00007683 AllocType = DepArrayT->getElementType();
7684 }
7685 }
7686 }
Sebastian Redl6047f072012-02-16 12:22:20 +00007687
Douglas Gregora16548e2009-08-11 05:31:07 +00007688 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
7689 E->isGlobalNew(),
7690 /*FIXME:*/E->getLocStart(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007691 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00007692 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00007693 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007694 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00007695 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00007696 ArraySize.get(),
Sebastian Redl6047f072012-02-16 12:22:20 +00007697 E->getDirectInitRange(),
7698 NewInit.take());
Douglas Gregora16548e2009-08-11 05:31:07 +00007699}
Mike Stump11289f42009-09-09 15:08:12 +00007700
Douglas Gregora16548e2009-08-11 05:31:07 +00007701template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007702ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007703TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007704 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00007705 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007706 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007707
Douglas Gregord2d9da02010-02-26 00:38:10 +00007708 // Transform the delete operator, if known.
7709 FunctionDecl *OperatorDelete = 0;
7710 if (E->getOperatorDelete()) {
7711 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007712 getDerived().TransformDecl(E->getLocStart(),
7713 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00007714 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00007715 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00007716 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007717
Douglas Gregora16548e2009-08-11 05:31:07 +00007718 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00007719 Operand.get() == E->getArgument() &&
7720 OperatorDelete == E->getOperatorDelete()) {
7721 // Mark any declarations we need as referenced.
7722 // FIXME: instantiation-specific.
7723 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00007724 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00007725
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00007726 if (!E->getArgument()->isTypeDependent()) {
7727 QualType Destroyed = SemaRef.Context.getBaseElementType(
7728 E->getDestroyedType());
7729 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
7730 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +00007731 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedmanfa0df832012-02-02 03:46:19 +00007732 SemaRef.LookupDestructor(Record));
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00007733 }
7734 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007735
John McCallc3007a22010-10-26 07:05:15 +00007736 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00007737 }
Mike Stump11289f42009-09-09 15:08:12 +00007738
Douglas Gregora16548e2009-08-11 05:31:07 +00007739 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
7740 E->isGlobalDelete(),
7741 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00007742 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007743}
Mike Stump11289f42009-09-09 15:08:12 +00007744
Douglas Gregora16548e2009-08-11 05:31:07 +00007745template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007746ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00007747TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007748 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007749 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00007750 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007751 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007752
John McCallba7bf592010-08-24 05:47:05 +00007753 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00007754 bool MayBePseudoDestructor = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00007755 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00007756 E->getOperatorLoc(),
7757 E->isArrow()? tok::arrow : tok::period,
7758 ObjectTypePtr,
7759 MayBePseudoDestructor);
7760 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007761 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007762
John McCallba7bf592010-08-24 05:47:05 +00007763 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +00007764 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
7765 if (QualifierLoc) {
7766 QualifierLoc
7767 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
7768 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +00007769 return ExprError();
7770 }
Douglas Gregora6ce6082011-02-25 18:19:59 +00007771 CXXScopeSpec SS;
7772 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00007773
Douglas Gregor678f90d2010-02-25 01:56:36 +00007774 PseudoDestructorTypeStorage Destroyed;
7775 if (E->getDestroyedTypeInfo()) {
7776 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00007777 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregor579c15f2011-03-02 18:32:08 +00007778 ObjectType, 0, SS);
Douglas Gregor678f90d2010-02-25 01:56:36 +00007779 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007780 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00007781 Destroyed = DestroyedTypeInfo;
Douglas Gregorf39a8dd2011-11-09 02:19:47 +00007782 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregor678f90d2010-02-25 01:56:36 +00007783 // We aren't likely to be able to resolve the identifier down to a type
7784 // now anyway, so just retain the identifier.
7785 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
7786 E->getDestroyedTypeLoc());
7787 } else {
7788 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +00007789 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00007790 *E->getDestroyedTypeIdentifier(),
7791 E->getDestroyedTypeLoc(),
7792 /*Scope=*/0,
7793 SS, ObjectTypePtr,
7794 false);
7795 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007796 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007797
Douglas Gregor678f90d2010-02-25 01:56:36 +00007798 Destroyed
7799 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
7800 E->getDestroyedTypeLoc());
7801 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007802
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007803 TypeSourceInfo *ScopeTypeInfo = 0;
7804 if (E->getScopeTypeInfo()) {
Douglas Gregora88c55b2013-03-08 21:25:01 +00007805 CXXScopeSpec EmptySS;
7806 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
7807 E->getScopeTypeInfo(), ObjectType, 0, EmptySS);
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007808 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007809 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00007810 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007811
John McCallb268a282010-08-23 23:25:46 +00007812 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00007813 E->getOperatorLoc(),
7814 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +00007815 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007816 ScopeTypeInfo,
7817 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00007818 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00007819 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00007820}
Mike Stump11289f42009-09-09 15:08:12 +00007821
Douglas Gregorad8a3362009-09-04 17:36:40 +00007822template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007823ExprResult
John McCalld14a8642009-11-21 08:51:07 +00007824TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007825 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00007826 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
7827 Sema::LookupOrdinaryName);
7828
7829 // Transform all the decls.
7830 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
7831 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007832 NamedDecl *InstD = static_cast<NamedDecl*>(
7833 getDerived().TransformDecl(Old->getNameLoc(),
7834 *I));
John McCall84d87672009-12-10 09:41:52 +00007835 if (!InstD) {
7836 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7837 // This can happen because of dependent hiding.
7838 if (isa<UsingShadowDecl>(*I))
7839 continue;
Serge Pavlov82605302013-09-04 04:50:29 +00007840 else {
7841 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00007842 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00007843 }
John McCall84d87672009-12-10 09:41:52 +00007844 }
John McCalle66edc12009-11-24 19:00:30 +00007845
7846 // Expand using declarations.
7847 if (isa<UsingDecl>(InstD)) {
7848 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +00007849 for (auto *I : UD->shadows())
7850 R.addDecl(I);
John McCalle66edc12009-11-24 19:00:30 +00007851 continue;
7852 }
7853
7854 R.addDecl(InstD);
7855 }
7856
7857 // Resolve a kind, but don't do any further analysis. If it's
7858 // ambiguous, the callee needs to deal with it.
7859 R.resolveKind();
7860
7861 // Rebuild the nested-name qualifier, if present.
7862 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00007863 if (Old->getQualifierLoc()) {
7864 NestedNameSpecifierLoc QualifierLoc
7865 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7866 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007867 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007868
Douglas Gregor0da1d432011-02-28 20:01:57 +00007869 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00007870 }
7871
Douglas Gregor9262f472010-04-27 18:19:34 +00007872 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00007873 CXXRecordDecl *NamingClass
7874 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
7875 Old->getNameLoc(),
7876 Old->getNamingClass()));
Serge Pavlov82605302013-09-04 04:50:29 +00007877 if (!NamingClass) {
7878 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00007879 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00007880 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007881
Douglas Gregorda7be082010-04-27 16:10:10 +00007882 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00007883 }
7884
Abramo Bagnara7945c982012-01-27 09:46:47 +00007885 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
7886
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00007887 // If we have neither explicit template arguments, nor the template keyword,
7888 // it's a normal declaration name.
7889 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
John McCalle66edc12009-11-24 19:00:30 +00007890 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
7891
7892 // If we have template arguments, rebuild them, then rebuild the
7893 // templateid expression.
7894 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola3dd531d2012-08-28 04:13:54 +00007895 if (Old->hasExplicitTemplateArgs() &&
7896 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregor62e06f22010-12-20 17:31:10 +00007897 Old->getNumTemplateArgs(),
Serge Pavlov82605302013-09-04 04:50:29 +00007898 TransArgs)) {
7899 R.clear();
Douglas Gregor62e06f22010-12-20 17:31:10 +00007900 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00007901 }
John McCalle66edc12009-11-24 19:00:30 +00007902
Abramo Bagnara7945c982012-01-27 09:46:47 +00007903 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00007904 Old->requiresADL(), &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00007905}
Mike Stump11289f42009-09-09 15:08:12 +00007906
Douglas Gregora16548e2009-08-11 05:31:07 +00007907template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007908ExprResult
Douglas Gregor29c42f22012-02-24 07:38:34 +00007909TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
7910 bool ArgChanged = false;
Dmitri Gribenkof8579502013-01-12 19:30:44 +00007911 SmallVector<TypeSourceInfo *, 4> Args;
Douglas Gregor29c42f22012-02-24 07:38:34 +00007912 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
7913 TypeSourceInfo *From = E->getArg(I);
7914 TypeLoc FromTL = From->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00007915 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
Douglas Gregor29c42f22012-02-24 07:38:34 +00007916 TypeLocBuilder TLB;
7917 TLB.reserve(FromTL.getFullDataSize());
7918 QualType To = getDerived().TransformType(TLB, FromTL);
7919 if (To.isNull())
7920 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007921
Douglas Gregor29c42f22012-02-24 07:38:34 +00007922 if (To == From->getType())
7923 Args.push_back(From);
7924 else {
7925 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7926 ArgChanged = true;
7927 }
7928 continue;
7929 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007930
Douglas Gregor29c42f22012-02-24 07:38:34 +00007931 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00007932
Douglas Gregor29c42f22012-02-24 07:38:34 +00007933 // We have a pack expansion. Instantiate it.
David Blaikie6adc78e2013-02-18 22:06:02 +00007934 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
Douglas Gregor29c42f22012-02-24 07:38:34 +00007935 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
7936 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
7937 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00007938
Douglas Gregor29c42f22012-02-24 07:38:34 +00007939 // Determine whether the set of unexpanded parameter packs can and should
7940 // be expanded.
7941 bool Expand = true;
7942 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00007943 Optional<unsigned> OrigNumExpansions =
7944 ExpansionTL.getTypePtr()->getNumExpansions();
7945 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor29c42f22012-02-24 07:38:34 +00007946 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
7947 PatternTL.getSourceRange(),
7948 Unexpanded,
7949 Expand, RetainExpansion,
7950 NumExpansions))
7951 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007952
Douglas Gregor29c42f22012-02-24 07:38:34 +00007953 if (!Expand) {
7954 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00007955 // transformation on the pack expansion, producing another pack
Douglas Gregor29c42f22012-02-24 07:38:34 +00007956 // expansion.
7957 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier1dcde962012-08-08 18:46:20 +00007958
Douglas Gregor29c42f22012-02-24 07:38:34 +00007959 TypeLocBuilder TLB;
7960 TLB.reserve(From->getTypeLoc().getFullDataSize());
7961
7962 QualType To = getDerived().TransformType(TLB, PatternTL);
7963 if (To.isNull())
7964 return ExprError();
7965
Chad Rosier1dcde962012-08-08 18:46:20 +00007966 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00007967 PatternTL.getSourceRange(),
7968 ExpansionTL.getEllipsisLoc(),
7969 NumExpansions);
7970 if (To.isNull())
7971 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007972
Douglas Gregor29c42f22012-02-24 07:38:34 +00007973 PackExpansionTypeLoc ToExpansionTL
7974 = TLB.push<PackExpansionTypeLoc>(To);
7975 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7976 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7977 continue;
7978 }
7979
7980 // Expand the pack expansion by substituting for each argument in the
7981 // pack(s).
7982 for (unsigned I = 0; I != *NumExpansions; ++I) {
7983 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
7984 TypeLocBuilder TLB;
7985 TLB.reserve(PatternTL.getFullDataSize());
7986 QualType To = getDerived().TransformType(TLB, PatternTL);
7987 if (To.isNull())
7988 return ExprError();
7989
Eli Friedman5e05c4a2013-07-19 21:49:32 +00007990 if (To->containsUnexpandedParameterPack()) {
7991 To = getDerived().RebuildPackExpansionType(To,
7992 PatternTL.getSourceRange(),
7993 ExpansionTL.getEllipsisLoc(),
7994 NumExpansions);
7995 if (To.isNull())
7996 return ExprError();
7997
7998 PackExpansionTypeLoc ToExpansionTL
7999 = TLB.push<PackExpansionTypeLoc>(To);
8000 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8001 }
8002
Douglas Gregor29c42f22012-02-24 07:38:34 +00008003 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8004 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008005
Douglas Gregor29c42f22012-02-24 07:38:34 +00008006 if (!RetainExpansion)
8007 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00008008
Douglas Gregor29c42f22012-02-24 07:38:34 +00008009 // If we're supposed to retain a pack expansion, do so by temporarily
8010 // forgetting the partially-substituted parameter pack.
8011 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
8012
8013 TypeLocBuilder TLB;
8014 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00008015
Douglas Gregor29c42f22012-02-24 07:38:34 +00008016 QualType To = getDerived().TransformType(TLB, PatternTL);
8017 if (To.isNull())
8018 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008019
8020 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00008021 PatternTL.getSourceRange(),
8022 ExpansionTL.getEllipsisLoc(),
8023 NumExpansions);
8024 if (To.isNull())
8025 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008026
Douglas Gregor29c42f22012-02-24 07:38:34 +00008027 PackExpansionTypeLoc ToExpansionTL
8028 = TLB.push<PackExpansionTypeLoc>(To);
8029 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8030 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8031 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008032
Douglas Gregor29c42f22012-02-24 07:38:34 +00008033 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8034 return SemaRef.Owned(E);
8035
8036 return getDerived().RebuildTypeTrait(E->getTrait(),
8037 E->getLocStart(),
8038 Args,
8039 E->getLocEnd());
8040}
8041
8042template<typename Derived>
8043ExprResult
John Wiegley6242b6a2011-04-28 00:16:57 +00008044TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
8045 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
8046 if (!T)
8047 return ExprError();
8048
8049 if (!getDerived().AlwaysRebuild() &&
8050 T == E->getQueriedTypeSourceInfo())
8051 return SemaRef.Owned(E);
8052
8053 ExprResult SubExpr;
8054 {
8055 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8056 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
8057 if (SubExpr.isInvalid())
8058 return ExprError();
8059
8060 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
8061 return SemaRef.Owned(E);
8062 }
8063
8064 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
8065 E->getLocStart(),
8066 T,
8067 SubExpr.get(),
8068 E->getLocEnd());
8069}
8070
8071template<typename Derived>
8072ExprResult
John Wiegleyf9f65842011-04-25 06:54:41 +00008073TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
8074 ExprResult SubExpr;
8075 {
8076 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8077 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
8078 if (SubExpr.isInvalid())
8079 return ExprError();
8080
8081 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
8082 return SemaRef.Owned(E);
8083 }
8084
8085 return getDerived().RebuildExpressionTrait(
8086 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
8087}
8088
8089template<typename Derived>
8090ExprResult
John McCall8cd78132009-11-19 22:55:06 +00008091TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008092 DependentScopeDeclRefExpr *E) {
Richard Smithdb2630f2012-10-21 03:28:35 +00008093 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand*/false);
8094}
8095
8096template<typename Derived>
8097ExprResult
8098TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
8099 DependentScopeDeclRefExpr *E,
8100 bool IsAddressOfOperand) {
Reid Kleckner916ac4d2013-10-15 18:38:02 +00008101 assert(E->getQualifierLoc());
Douglas Gregor3a43fd62011-02-25 20:49:16 +00008102 NestedNameSpecifierLoc QualifierLoc
8103 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
8104 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008105 return ExprError();
Abramo Bagnara7945c982012-01-27 09:46:47 +00008106 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00008107
John McCall31f82722010-11-12 08:19:04 +00008108 // TODO: If this is a conversion-function-id, verify that the
8109 // destination type name (if present) resolves the same way after
8110 // instantiation as it did in the local scope.
8111
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008112 DeclarationNameInfo NameInfo
8113 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
8114 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00008115 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008116
John McCalle66edc12009-11-24 19:00:30 +00008117 if (!E->hasExplicitTemplateArgs()) {
8118 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3a43fd62011-02-25 20:49:16 +00008119 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008120 // Note: it is sufficient to compare the Name component of NameInfo:
8121 // if name has not changed, DNLoc has not changed either.
8122 NameInfo.getName() == E->getDeclName())
John McCallc3007a22010-10-26 07:05:15 +00008123 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00008124
Douglas Gregor3a43fd62011-02-25 20:49:16 +00008125 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008126 TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008127 NameInfo,
Richard Smithdb2630f2012-10-21 03:28:35 +00008128 /*TemplateArgs*/ 0,
8129 IsAddressOfOperand);
Douglas Gregord019ff62009-10-22 17:20:55 +00008130 }
John McCall6b51f282009-11-23 01:53:49 +00008131
8132 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008133 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8134 E->getNumTemplateArgs(),
8135 TransArgs))
8136 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008137
Douglas Gregor3a43fd62011-02-25 20:49:16 +00008138 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008139 TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008140 NameInfo,
Richard Smithdb2630f2012-10-21 03:28:35 +00008141 &TransArgs,
8142 IsAddressOfOperand);
Douglas Gregora16548e2009-08-11 05:31:07 +00008143}
8144
8145template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008146ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008147TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithd59b8322012-12-19 01:39:02 +00008148 // CXXConstructExprs other than for list-initialization and
8149 // CXXTemporaryObjectExpr are always implicit, so when we have
8150 // a 1-argument construction we just transform that argument.
Richard Smithdd2ca572012-11-26 08:32:48 +00008151 if ((E->getNumArgs() == 1 ||
8152 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithd59b8322012-12-19 01:39:02 +00008153 (!getDerived().DropCallArgument(E->getArg(0))) &&
8154 !E->isListInitialization())
Douglas Gregordb56b912010-02-03 03:01:57 +00008155 return getDerived().TransformExpr(E->getArg(0));
8156
Douglas Gregora16548e2009-08-11 05:31:07 +00008157 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
8158
8159 QualType T = getDerived().TransformType(E->getType());
8160 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00008161 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008162
8163 CXXConstructorDecl *Constructor
8164 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008165 getDerived().TransformDecl(E->getLocStart(),
8166 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008167 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00008168 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008169
Douglas Gregora16548e2009-08-11 05:31:07 +00008170 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008171 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00008172 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00008173 &ArgumentChanged))
8174 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008175
Douglas Gregora16548e2009-08-11 05:31:07 +00008176 if (!getDerived().AlwaysRebuild() &&
8177 T == E->getType() &&
8178 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00008179 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00008180 // Mark the constructor as referenced.
8181 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00008182 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00008183 return SemaRef.Owned(E);
Douglas Gregorde550352010-02-26 00:01:57 +00008184 }
Mike Stump11289f42009-09-09 15:08:12 +00008185
Douglas Gregordb121ba2009-12-14 16:27:04 +00008186 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
8187 Constructor, E->isElidable(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008188 Args,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00008189 E->hadMultipleCandidates(),
Richard Smithd59b8322012-12-19 01:39:02 +00008190 E->isListInitialization(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00008191 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00008192 E->getConstructionKind(),
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00008193 E->getParenOrBraceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00008194}
Mike Stump11289f42009-09-09 15:08:12 +00008195
Douglas Gregora16548e2009-08-11 05:31:07 +00008196/// \brief Transform a C++ temporary-binding expression.
8197///
Douglas Gregor363b1512009-12-24 18:51:59 +00008198/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
8199/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00008200template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008201ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008202TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00008203 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008204}
Mike Stump11289f42009-09-09 15:08:12 +00008205
John McCall5d413782010-12-06 08:20:24 +00008206/// \brief Transform a C++ expression that contains cleanups that should
8207/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +00008208///
John McCall5d413782010-12-06 08:20:24 +00008209/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +00008210/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00008211template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008212ExprResult
John McCall5d413782010-12-06 08:20:24 +00008213TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00008214 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008215}
Mike Stump11289f42009-09-09 15:08:12 +00008216
Douglas Gregora16548e2009-08-11 05:31:07 +00008217template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008218ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008219TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00008220 CXXTemporaryObjectExpr *E) {
8221 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8222 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00008223 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008224
Douglas Gregora16548e2009-08-11 05:31:07 +00008225 CXXConstructorDecl *Constructor
8226 = cast_or_null<CXXConstructorDecl>(
Chad Rosier1dcde962012-08-08 18:46:20 +00008227 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008228 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008229 if (!Constructor)
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 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008233 SmallVector<Expr*, 8> Args;
Douglas Gregora16548e2009-08-11 05:31:07 +00008234 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +00008235 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00008236 &ArgumentChanged))
8237 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008238
Douglas Gregora16548e2009-08-11 05:31:07 +00008239 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00008240 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008241 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00008242 !ArgumentChanged) {
8243 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00008244 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00008245 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00008246 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008247
Richard Smithd59b8322012-12-19 01:39:02 +00008248 // FIXME: Pass in E->isListInitialization().
Douglas Gregor2b88c112010-09-08 00:15:04 +00008249 return getDerived().RebuildCXXTemporaryObjectExpr(T,
8250 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008251 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00008252 E->getLocEnd());
8253}
Mike Stump11289f42009-09-09 15:08:12 +00008254
Douglas Gregora16548e2009-08-11 05:31:07 +00008255template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008256ExprResult
Douglas Gregore31e6062012-02-07 10:09:13 +00008257TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008258
8259 // Transform any init-capture expressions before entering the scope of the
8260 // lambda body, because they are not semantically within that scope.
8261 SmallVector<InitCaptureInfoTy, 8> InitCaptureExprsAndTypes;
8262 InitCaptureExprsAndTypes.resize(E->explicit_capture_end() -
8263 E->explicit_capture_begin());
8264
8265 for (LambdaExpr::capture_iterator C = E->capture_begin(),
8266 CEnd = E->capture_end();
8267 C != CEnd; ++C) {
8268 if (!C->isInitCapture())
8269 continue;
8270 EnterExpressionEvaluationContext EEEC(getSema(),
8271 Sema::PotentiallyEvaluated);
8272 ExprResult NewExprInitResult = getDerived().TransformInitializer(
8273 C->getCapturedVar()->getInit(),
8274 C->getCapturedVar()->getInitStyle() == VarDecl::CallInit);
8275
8276 if (NewExprInitResult.isInvalid())
8277 return ExprError();
8278 Expr *NewExprInit = NewExprInitResult.get();
8279
8280 VarDecl *OldVD = C->getCapturedVar();
8281 QualType NewInitCaptureType =
8282 getSema().performLambdaInitCaptureInitialization(C->getLocation(),
8283 OldVD->getType()->isReferenceType(), OldVD->getIdentifier(),
8284 NewExprInit);
8285 NewExprInitResult = NewExprInit;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008286 InitCaptureExprsAndTypes[C - E->capture_begin()] =
8287 std::make_pair(NewExprInitResult, NewInitCaptureType);
8288
8289 }
8290
Faisal Vali524ca282013-11-12 01:40:44 +00008291 LambdaScopeInfo *LSI = getSema().PushLambdaScope();
Faisal Vali2cba1332013-10-23 06:44:28 +00008292 // Transform the template parameters, and add them to the current
8293 // instantiation scope. The null case is handled correctly.
8294 LSI->GLTemplateParameterList = getDerived().TransformTemplateParameterList(
8295 E->getTemplateParameterList());
8296
8297 // Check to see if the TypeSourceInfo of the call operator needs to
8298 // be transformed, and if so do the transformation in the
8299 // CurrentInstantiationScope.
8300
8301 TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo();
8302 FunctionProtoTypeLoc OldCallOpFPTL =
8303 OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>();
8304 TypeSourceInfo *NewCallOpTSI = 0;
8305
8306 const bool CallOpWasAlreadyTransformed =
8307 getDerived().AlreadyTransformed(OldCallOpTSI->getType());
8308
8309 // Use the Old Call Operator's TypeSourceInfo if it is already transformed.
8310 if (CallOpWasAlreadyTransformed)
8311 NewCallOpTSI = OldCallOpTSI;
8312 else {
8313 // Transform the TypeSourceInfo of the Original Lambda's Call Operator.
8314 // The transformation MUST be done in the CurrentInstantiationScope since
8315 // it introduces a mapping of the original to the newly created
8316 // transformed parameters.
8317
8318 TypeLocBuilder NewCallOpTLBuilder;
8319 QualType NewCallOpType = TransformFunctionProtoType(NewCallOpTLBuilder,
8320 OldCallOpFPTL,
8321 0, 0);
8322 NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context,
8323 NewCallOpType);
Faisal Vali2b391ab2013-09-26 19:54:12 +00008324 }
Faisal Vali2cba1332013-10-23 06:44:28 +00008325 // Extract the ParmVarDecls from the NewCallOpTSI and add them to
8326 // the vector below - this will be used to synthesize the
8327 // NewCallOperator. Additionally, add the parameters of the untransformed
8328 // lambda call operator to the CurrentInstantiationScope.
8329 SmallVector<ParmVarDecl *, 4> Params;
8330 {
8331 FunctionProtoTypeLoc NewCallOpFPTL =
8332 NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>();
8333 ParmVarDecl **NewParamDeclArray = NewCallOpFPTL.getParmArray();
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00008334 const unsigned NewNumArgs = NewCallOpFPTL.getNumParams();
Faisal Vali2cba1332013-10-23 06:44:28 +00008335
8336 for (unsigned I = 0; I < NewNumArgs; ++I) {
8337 // If this call operator's type does not require transformation,
8338 // the parameters do not get added to the current instantiation scope,
8339 // - so ADD them! This allows the following to compile when the enclosing
8340 // template is specialized and the entire lambda expression has to be
8341 // transformed.
8342 // template<class T> void foo(T t) {
8343 // auto L = [](auto a) {
8344 // auto M = [](char b) { <-- note: non-generic lambda
8345 // auto N = [](auto c) {
8346 // int x = sizeof(a);
8347 // x = sizeof(b); <-- specifically this line
8348 // x = sizeof(c);
8349 // };
8350 // };
8351 // };
8352 // }
8353 // foo('a')
8354 if (CallOpWasAlreadyTransformed)
8355 getDerived().transformedLocalDecl(NewParamDeclArray[I],
8356 NewParamDeclArray[I]);
8357 // Add to Params array, so these parameters can be used to create
8358 // the newly transformed call operator.
8359 Params.push_back(NewParamDeclArray[I]);
8360 }
8361 }
8362
8363 if (!NewCallOpTSI)
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008364 return ExprError();
8365
Eli Friedmand564afb2012-09-19 01:18:11 +00008366 // Create the local class that will describe the lambda.
8367 CXXRecordDecl *Class
8368 = getSema().createLambdaClosureType(E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +00008369 NewCallOpTSI,
Faisal Valic1a6dc42013-10-23 16:10:50 +00008370 /*KnownDependent=*/false,
8371 E->getCaptureDefault());
8372
Eli Friedmand564afb2012-09-19 01:18:11 +00008373 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
8374
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008375 // Build the call operator.
Faisal Vali2cba1332013-10-23 06:44:28 +00008376 CXXMethodDecl *NewCallOperator
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008377 = getSema().startLambdaDefinition(Class, E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +00008378 NewCallOpTSI,
Douglas Gregoradb376e2012-02-14 22:28:59 +00008379 E->getCallOperator()->getLocEnd(),
Richard Smith505df232012-07-22 23:45:10 +00008380 Params);
Faisal Vali2cba1332013-10-23 06:44:28 +00008381 LSI->CallOperator = NewCallOperator;
Rafael Espindola4b35f272013-10-04 14:28:51 +00008382
Faisal Vali2cba1332013-10-23 06:44:28 +00008383 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
8384
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008385 return getDerived().TransformLambdaScope(E, NewCallOperator,
8386 InitCaptureExprsAndTypes);
Richard Smith2589b9802012-07-25 03:56:55 +00008387}
8388
8389template<typename Derived>
8390ExprResult
8391TreeTransform<Derived>::TransformLambdaScope(LambdaExpr *E,
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008392 CXXMethodDecl *CallOperator,
8393 ArrayRef<InitCaptureInfoTy> InitCaptureExprsAndTypes) {
Richard Smithba71c082013-05-16 06:20:58 +00008394 bool Invalid = false;
8395
Douglas Gregorb4328232012-02-14 00:00:48 +00008396 // Introduce the context of the call operator.
Richard Smith7ff2bcb2014-01-24 01:54:52 +00008397 Sema::ContextRAII SavedContext(getSema(), CallOperator,
8398 /*NewThisContext*/false);
Douglas Gregorb4328232012-02-14 00:00:48 +00008399
Faisal Vali2b391ab2013-09-26 19:54:12 +00008400 LambdaScopeInfo *const LSI = getSema().getCurLambda();
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008401 // Enter the scope of the lambda.
Faisal Vali2b391ab2013-09-26 19:54:12 +00008402 getSema().buildLambdaScope(LSI, CallOperator, E->getIntroducerRange(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008403 E->getCaptureDefault(),
James Dennettddd36ff2013-08-09 23:08:25 +00008404 E->getCaptureDefaultLoc(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008405 E->hasExplicitParameters(),
8406 E->hasExplicitResultType(),
8407 E->isMutable());
Chad Rosier1dcde962012-08-08 18:46:20 +00008408
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008409 // Transform captures.
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008410 bool FinishedExplicitCaptures = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00008411 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008412 CEnd = E->capture_end();
8413 C != CEnd; ++C) {
8414 // When we hit the first implicit capture, tell Sema that we've finished
8415 // the list of explicit captures.
8416 if (!FinishedExplicitCaptures && C->isImplicit()) {
8417 getSema().finishLambdaExplicitCaptures(LSI);
8418 FinishedExplicitCaptures = true;
8419 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008420
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008421 // Capturing 'this' is trivial.
8422 if (C->capturesThis()) {
8423 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
8424 continue;
8425 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008426
Richard Smithba71c082013-05-16 06:20:58 +00008427 // Rebuild init-captures, including the implied field declaration.
8428 if (C->isInitCapture()) {
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008429
8430 InitCaptureInfoTy InitExprTypePair =
8431 InitCaptureExprsAndTypes[C - E->capture_begin()];
8432 ExprResult Init = InitExprTypePair.first;
8433 QualType InitQualType = InitExprTypePair.second;
8434 if (Init.isInvalid() || InitQualType.isNull()) {
Richard Smithba71c082013-05-16 06:20:58 +00008435 Invalid = true;
8436 continue;
8437 }
Richard Smithbb13c9a2013-09-28 04:02:39 +00008438 VarDecl *OldVD = C->getCapturedVar();
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008439 VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl(
8440 OldVD->getLocation(), InitExprTypePair.second,
8441 OldVD->getIdentifier(), Init.get());
Richard Smithbb13c9a2013-09-28 04:02:39 +00008442 if (!NewVD)
Richard Smithba71c082013-05-16 06:20:58 +00008443 Invalid = true;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008444 else {
Richard Smithbb13c9a2013-09-28 04:02:39 +00008445 getDerived().transformedLocalDecl(OldVD, NewVD);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008446 }
Richard Smithbb13c9a2013-09-28 04:02:39 +00008447 getSema().buildInitCaptureField(LSI, NewVD);
Richard Smithba71c082013-05-16 06:20:58 +00008448 continue;
8449 }
8450
8451 assert(C->capturesVariable() && "unexpected kind of lambda capture");
8452
Douglas Gregor3e308b12012-02-14 19:27:52 +00008453 // Determine the capture kind for Sema.
8454 Sema::TryCaptureKind Kind
8455 = C->isImplicit()? Sema::TryCapture_Implicit
8456 : C->getCaptureKind() == LCK_ByCopy
8457 ? Sema::TryCapture_ExplicitByVal
8458 : Sema::TryCapture_ExplicitByRef;
8459 SourceLocation EllipsisLoc;
8460 if (C->isPackExpansion()) {
8461 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
8462 bool ShouldExpand = false;
8463 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00008464 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +00008465 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
8466 C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +00008467 Unexpanded,
8468 ShouldExpand, RetainExpansion,
Richard Smithba71c082013-05-16 06:20:58 +00008469 NumExpansions)) {
8470 Invalid = true;
8471 continue;
8472 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008473
Douglas Gregor3e308b12012-02-14 19:27:52 +00008474 if (ShouldExpand) {
8475 // The transform has determined that we should perform an expansion;
8476 // transform and capture each of the arguments.
8477 // expansion of the pattern. Do so.
8478 VarDecl *Pack = C->getCapturedVar();
8479 for (unsigned I = 0; I != *NumExpansions; ++I) {
8480 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8481 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +00008482 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +00008483 Pack));
8484 if (!CapturedVar) {
8485 Invalid = true;
8486 continue;
8487 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008488
Douglas Gregor3e308b12012-02-14 19:27:52 +00008489 // Capture the transformed variable.
Chad Rosier1dcde962012-08-08 18:46:20 +00008490 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
8491 }
Douglas Gregor3e308b12012-02-14 19:27:52 +00008492 continue;
8493 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008494
Douglas Gregor3e308b12012-02-14 19:27:52 +00008495 EllipsisLoc = C->getEllipsisLoc();
8496 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008497
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008498 // Transform the captured variable.
8499 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +00008500 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008501 C->getCapturedVar()));
8502 if (!CapturedVar) {
8503 Invalid = true;
8504 continue;
8505 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008506
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008507 // Capture the transformed variable.
Douglas Gregorfdf598e2012-02-18 09:37:24 +00008508 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008509 }
8510 if (!FinishedExplicitCaptures)
8511 getSema().finishLambdaExplicitCaptures(LSI);
8512
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008513
8514 // Enter a new evaluation context to insulate the lambda from any
8515 // cleanups from the enclosing full-expression.
Chad Rosier1dcde962012-08-08 18:46:20 +00008516 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008517
8518 if (Invalid) {
Chad Rosier1dcde962012-08-08 18:46:20 +00008519 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008520 /*IsInstantiation=*/true);
8521 return ExprError();
8522 }
8523
8524 // Instantiate the body of the lambda expression.
Douglas Gregorb4328232012-02-14 00:00:48 +00008525 StmtResult Body = getDerived().TransformStmt(E->getBody());
8526 if (Body.isInvalid()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00008527 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
Douglas Gregorb4328232012-02-14 00:00:48 +00008528 /*IsInstantiation=*/true);
Chad Rosier1dcde962012-08-08 18:46:20 +00008529 return ExprError();
Douglas Gregorb4328232012-02-14 00:00:48 +00008530 }
Douglas Gregor7fcbd902012-02-21 00:37:24 +00008531
Chad Rosier1dcde962012-08-08 18:46:20 +00008532 return getSema().ActOnLambdaExpr(E->getLocStart(), Body.take(),
Douglas Gregorb61e8092012-04-04 17:40:10 +00008533 /*CurScope=*/0, /*IsInstantiation=*/true);
Douglas Gregore31e6062012-02-07 10:09:13 +00008534}
8535
8536template<typename Derived>
8537ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008538TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008539 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00008540 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8541 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00008542 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008543
Douglas Gregora16548e2009-08-11 05:31:07 +00008544 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008545 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +00008546 Args.reserve(E->arg_size());
Chad Rosier1dcde962012-08-08 18:46:20 +00008547 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00008548 &ArgumentChanged))
8549 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008550
Douglas Gregora16548e2009-08-11 05:31:07 +00008551 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00008552 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008553 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00008554 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00008555
Douglas Gregora16548e2009-08-11 05:31:07 +00008556 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +00008557 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +00008558 E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008559 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00008560 E->getRParenLoc());
8561}
Mike Stump11289f42009-09-09 15:08:12 +00008562
Douglas Gregora16548e2009-08-11 05:31:07 +00008563template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008564ExprResult
John McCall8cd78132009-11-19 22:55:06 +00008565TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008566 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008567 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00008568 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00008569 Expr *OldBase;
8570 QualType BaseType;
8571 QualType ObjectType;
8572 if (!E->isImplicitAccess()) {
8573 OldBase = E->getBase();
8574 Base = getDerived().TransformExpr(OldBase);
8575 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008576 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008577
John McCall2d74de92009-12-01 22:10:20 +00008578 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +00008579 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +00008580 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00008581 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00008582 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00008583 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00008584 ObjectTy,
8585 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00008586 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008587 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00008588
John McCallba7bf592010-08-24 05:47:05 +00008589 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +00008590 BaseType = ((Expr*) Base.get())->getType();
8591 } else {
8592 OldBase = 0;
8593 BaseType = getDerived().TransformType(E->getBaseType());
8594 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
8595 }
Mike Stump11289f42009-09-09 15:08:12 +00008596
Douglas Gregora5cb6da2009-10-20 05:58:46 +00008597 // Transform the first part of the nested-name-specifier that qualifies
8598 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00008599 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00008600 = getDerived().TransformFirstQualifierInScope(
Douglas Gregore16af532011-02-28 18:50:33 +00008601 E->getFirstQualifierFoundInScope(),
8602 E->getQualifierLoc().getBeginLoc());
Mike Stump11289f42009-09-09 15:08:12 +00008603
Douglas Gregore16af532011-02-28 18:50:33 +00008604 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00008605 if (E->getQualifier()) {
Douglas Gregore16af532011-02-28 18:50:33 +00008606 QualifierLoc
8607 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
8608 ObjectType,
8609 FirstQualifierInScope);
8610 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008611 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +00008612 }
Mike Stump11289f42009-09-09 15:08:12 +00008613
Abramo Bagnara7945c982012-01-27 09:46:47 +00008614 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
8615
John McCall31f82722010-11-12 08:19:04 +00008616 // TODO: If this is a conversion-function-id, verify that the
8617 // destination type name (if present) resolves the same way after
8618 // instantiation as it did in the local scope.
8619
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008620 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +00008621 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008622 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00008623 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008624
John McCall2d74de92009-12-01 22:10:20 +00008625 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00008626 // This is a reference to a member without an explicitly-specified
8627 // template argument list. Optimize for this common case.
8628 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00008629 Base.get() == OldBase &&
8630 BaseType == E->getBaseType() &&
Douglas Gregore16af532011-02-28 18:50:33 +00008631 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008632 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00008633 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCallc3007a22010-10-26 07:05:15 +00008634 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00008635
John McCallb268a282010-08-23 23:25:46 +00008636 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00008637 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00008638 E->isArrow(),
8639 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00008640 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008641 TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00008642 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008643 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00008644 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00008645 }
8646
John McCall6b51f282009-11-23 01:53:49 +00008647 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008648 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8649 E->getNumTemplateArgs(),
8650 TransArgs))
8651 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008652
John McCallb268a282010-08-23 23:25:46 +00008653 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00008654 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00008655 E->isArrow(),
8656 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00008657 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008658 TemplateKWLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +00008659 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008660 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00008661 &TransArgs);
8662}
8663
8664template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008665ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008666TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00008667 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00008668 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00008669 QualType BaseType;
8670 if (!Old->isImplicitAccess()) {
8671 Base = getDerived().TransformExpr(Old->getBase());
8672 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008673 return ExprError();
Richard Smithcab9a7d2011-10-26 19:06:56 +00008674 Base = getSema().PerformMemberExprBaseConversion(Base.take(),
8675 Old->isArrow());
8676 if (Base.isInvalid())
8677 return ExprError();
8678 BaseType = Base.get()->getType();
John McCall2d74de92009-12-01 22:10:20 +00008679 } else {
8680 BaseType = getDerived().TransformType(Old->getBaseType());
8681 }
John McCall10eae182009-11-30 22:42:35 +00008682
Douglas Gregor0da1d432011-02-28 20:01:57 +00008683 NestedNameSpecifierLoc QualifierLoc;
8684 if (Old->getQualifierLoc()) {
8685 QualifierLoc
8686 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
8687 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008688 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00008689 }
8690
Abramo Bagnara7945c982012-01-27 09:46:47 +00008691 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
8692
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008693 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +00008694 Sema::LookupOrdinaryName);
8695
8696 // Transform all the decls.
8697 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
8698 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008699 NamedDecl *InstD = static_cast<NamedDecl*>(
8700 getDerived().TransformDecl(Old->getMemberLoc(),
8701 *I));
John McCall84d87672009-12-10 09:41:52 +00008702 if (!InstD) {
8703 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
8704 // This can happen because of dependent hiding.
8705 if (isa<UsingShadowDecl>(*I))
8706 continue;
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00008707 else {
8708 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00008709 return ExprError();
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00008710 }
John McCall84d87672009-12-10 09:41:52 +00008711 }
John McCall10eae182009-11-30 22:42:35 +00008712
8713 // Expand using declarations.
8714 if (isa<UsingDecl>(InstD)) {
8715 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +00008716 for (auto *I : UD->shadows())
8717 R.addDecl(I);
John McCall10eae182009-11-30 22:42:35 +00008718 continue;
8719 }
8720
8721 R.addDecl(InstD);
8722 }
8723
8724 R.resolveKind();
8725
Douglas Gregor9262f472010-04-27 18:19:34 +00008726 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00008727 if (Old->getNamingClass()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00008728 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00008729 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00008730 Old->getMemberLoc(),
8731 Old->getNamingClass()));
8732 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00008733 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008734
Douglas Gregorda7be082010-04-27 16:10:10 +00008735 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00008736 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008737
John McCall10eae182009-11-30 22:42:35 +00008738 TemplateArgumentListInfo TransArgs;
8739 if (Old->hasExplicitTemplateArgs()) {
8740 TransArgs.setLAngleLoc(Old->getLAngleLoc());
8741 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008742 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
8743 Old->getNumTemplateArgs(),
8744 TransArgs))
8745 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00008746 }
John McCall38836f02010-01-15 08:34:02 +00008747
8748 // FIXME: to do this check properly, we will need to preserve the
8749 // first-qualifier-in-scope here, just in case we had a dependent
8750 // base (and therefore couldn't do the check) and a
8751 // nested-name-qualifier (and therefore could do the lookup).
8752 NamedDecl *FirstQualifierInScope = 0;
Chad Rosier1dcde962012-08-08 18:46:20 +00008753
John McCallb268a282010-08-23 23:25:46 +00008754 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00008755 BaseType,
John McCall10eae182009-11-30 22:42:35 +00008756 Old->getOperatorLoc(),
8757 Old->isArrow(),
Douglas Gregor0da1d432011-02-28 20:01:57 +00008758 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008759 TemplateKWLoc,
John McCall38836f02010-01-15 08:34:02 +00008760 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00008761 R,
8762 (Old->hasExplicitTemplateArgs()
8763 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00008764}
8765
8766template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008767ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +00008768TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Alexis Hunt414e3e32011-05-31 19:54:49 +00008769 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00008770 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
8771 if (SubExpr.isInvalid())
8772 return ExprError();
8773
8774 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCallc3007a22010-10-26 07:05:15 +00008775 return SemaRef.Owned(E);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00008776
8777 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
8778}
8779
8780template<typename Derived>
8781ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +00008782TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +00008783 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
8784 if (Pattern.isInvalid())
8785 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008786
Douglas Gregor0f836ea2011-01-13 00:19:55 +00008787 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
8788 return SemaRef.Owned(E);
8789
Douglas Gregorb8840002011-01-14 21:20:45 +00008790 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
8791 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +00008792}
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008793
8794template<typename Derived>
8795ExprResult
8796TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
8797 // If E is not value-dependent, then nothing will change when we transform it.
8798 // Note: This is an instantiation-centric view.
8799 if (!E->isValueDependent())
8800 return SemaRef.Owned(E);
8801
8802 // Note: None of the implementations of TryExpandParameterPacks can ever
8803 // produce a diagnostic when given only a single unexpanded parameter pack,
Chad Rosier1dcde962012-08-08 18:46:20 +00008804 // so
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008805 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
8806 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00008807 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00008808 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +00008809 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikieb9c168a2011-09-22 02:34:54 +00008810 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00008811 ShouldExpand, RetainExpansion,
8812 NumExpansions))
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008813 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008814
Douglas Gregorab96bcf2011-10-10 18:59:29 +00008815 if (RetainExpansion)
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008816 return SemaRef.Owned(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00008817
Douglas Gregorab96bcf2011-10-10 18:59:29 +00008818 NamedDecl *Pack = E->getPack();
8819 if (!ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00008820 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
Douglas Gregorab96bcf2011-10-10 18:59:29 +00008821 Pack));
8822 if (!Pack)
8823 return ExprError();
8824 }
8825
Chad Rosier1dcde962012-08-08 18:46:20 +00008826
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008827 // We now know the length of the parameter pack, so build a new expression
8828 // that stores that length.
Chad Rosier1dcde962012-08-08 18:46:20 +00008829 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
8830 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregorab96bcf2011-10-10 18:59:29 +00008831 NumExpansions);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008832}
8833
Douglas Gregore8e9dd62011-01-03 17:17:50 +00008834template<typename Derived>
8835ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +00008836TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
8837 SubstNonTypeTemplateParmPackExpr *E) {
8838 // Default behavior is to do nothing with this transformation.
8839 return SemaRef.Owned(E);
8840}
8841
8842template<typename Derived>
8843ExprResult
John McCall7c454bb2011-07-15 05:09:51 +00008844TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
8845 SubstNonTypeTemplateParmExpr *E) {
8846 // Default behavior is to do nothing with this transformation.
8847 return SemaRef.Owned(E);
8848}
8849
8850template<typename Derived>
8851ExprResult
Richard Smithb15fe3a2012-09-12 00:56:43 +00008852TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
8853 // Default behavior is to do nothing with this transformation.
8854 return SemaRef.Owned(E);
8855}
8856
8857template<typename Derived>
8858ExprResult
Douglas Gregorfe314812011-06-21 17:03:29 +00008859TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
8860 MaterializeTemporaryExpr *E) {
8861 return getDerived().TransformExpr(E->GetTemporaryExpr());
8862}
Chad Rosier1dcde962012-08-08 18:46:20 +00008863
Douglas Gregorfe314812011-06-21 17:03:29 +00008864template<typename Derived>
8865ExprResult
Richard Smithcc1b96d2013-06-12 22:31:48 +00008866TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
8867 CXXStdInitializerListExpr *E) {
8868 return getDerived().TransformExpr(E->getSubExpr());
8869}
8870
8871template<typename Derived>
8872ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008873TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00008874 return SemaRef.MaybeBindToTemporary(E);
8875}
8876
8877template<typename Derived>
8878ExprResult
8879TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Jordy Rose8986c5992012-03-12 17:53:02 +00008880 return SemaRef.Owned(E);
Ted Kremeneke65b0862012-03-06 20:05:56 +00008881}
8882
8883template<typename Derived>
8884ExprResult
Patrick Beard0caa3942012-04-19 00:25:12 +00008885TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
8886 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
8887 if (SubExpr.isInvalid())
8888 return ExprError();
8889
8890 if (!getDerived().AlwaysRebuild() &&
8891 SubExpr.get() == E->getSubExpr())
8892 return SemaRef.Owned(E);
8893
8894 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremeneke65b0862012-03-06 20:05:56 +00008895}
8896
8897template<typename Derived>
8898ExprResult
8899TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
8900 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +00008901 SmallVector<Expr *, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +00008902 bool ArgChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00008903 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremeneke65b0862012-03-06 20:05:56 +00008904 /*IsCall=*/false, Elements, &ArgChanged))
8905 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008906
Ted Kremeneke65b0862012-03-06 20:05:56 +00008907 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8908 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00008909
Ted Kremeneke65b0862012-03-06 20:05:56 +00008910 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
8911 Elements.data(),
8912 Elements.size());
8913}
8914
8915template<typename Derived>
8916ExprResult
8917TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier1dcde962012-08-08 18:46:20 +00008918 ObjCDictionaryLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00008919 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +00008920 SmallVector<ObjCDictionaryElement, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +00008921 bool ArgChanged = false;
8922 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
8923 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier1dcde962012-08-08 18:46:20 +00008924
Ted Kremeneke65b0862012-03-06 20:05:56 +00008925 if (OrigElement.isPackExpansion()) {
8926 // This key/value element is a pack expansion.
8927 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
8928 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
8929 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
8930 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
8931
8932 // Determine whether the set of unexpanded parameter packs can
8933 // and should be expanded.
8934 bool Expand = true;
8935 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00008936 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
8937 Optional<unsigned> NumExpansions = OrigNumExpansions;
Ted Kremeneke65b0862012-03-06 20:05:56 +00008938 SourceRange PatternRange(OrigElement.Key->getLocStart(),
8939 OrigElement.Value->getLocEnd());
8940 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
8941 PatternRange,
8942 Unexpanded,
8943 Expand, RetainExpansion,
8944 NumExpansions))
8945 return ExprError();
8946
8947 if (!Expand) {
8948 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00008949 // transformation on the pack expansion, producing another pack
Ted Kremeneke65b0862012-03-06 20:05:56 +00008950 // expansion.
8951 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
8952 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8953 if (Key.isInvalid())
8954 return ExprError();
8955
8956 if (Key.get() != OrigElement.Key)
8957 ArgChanged = true;
8958
8959 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8960 if (Value.isInvalid())
8961 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008962
Ted Kremeneke65b0862012-03-06 20:05:56 +00008963 if (Value.get() != OrigElement.Value)
8964 ArgChanged = true;
8965
Chad Rosier1dcde962012-08-08 18:46:20 +00008966 ObjCDictionaryElement Expansion = {
Ted Kremeneke65b0862012-03-06 20:05:56 +00008967 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
8968 };
8969 Elements.push_back(Expansion);
8970 continue;
8971 }
8972
8973 // Record right away that the argument was changed. This needs
8974 // to happen even if the array expands to nothing.
8975 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00008976
Ted Kremeneke65b0862012-03-06 20:05:56 +00008977 // The transform has determined that we should perform an elementwise
8978 // expansion of the pattern. Do so.
8979 for (unsigned I = 0; I != *NumExpansions; ++I) {
8980 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8981 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8982 if (Key.isInvalid())
8983 return ExprError();
8984
8985 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8986 if (Value.isInvalid())
8987 return ExprError();
8988
Chad Rosier1dcde962012-08-08 18:46:20 +00008989 ObjCDictionaryElement Element = {
Ted Kremeneke65b0862012-03-06 20:05:56 +00008990 Key.get(), Value.get(), SourceLocation(), NumExpansions
8991 };
8992
8993 // If any unexpanded parameter packs remain, we still have a
8994 // pack expansion.
8995 if (Key.get()->containsUnexpandedParameterPack() ||
8996 Value.get()->containsUnexpandedParameterPack())
8997 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier1dcde962012-08-08 18:46:20 +00008998
Ted Kremeneke65b0862012-03-06 20:05:56 +00008999 Elements.push_back(Element);
9000 }
9001
9002 // We've finished with this pack expansion.
9003 continue;
9004 }
9005
9006 // Transform and check key.
9007 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
9008 if (Key.isInvalid())
9009 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009010
Ted Kremeneke65b0862012-03-06 20:05:56 +00009011 if (Key.get() != OrigElement.Key)
9012 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009013
Ted Kremeneke65b0862012-03-06 20:05:56 +00009014 // Transform and check value.
9015 ExprResult Value
9016 = getDerived().TransformExpr(OrigElement.Value);
9017 if (Value.isInvalid())
9018 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009019
Ted Kremeneke65b0862012-03-06 20:05:56 +00009020 if (Value.get() != OrigElement.Value)
9021 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009022
9023 ObjCDictionaryElement Element = {
David Blaikie7a30dc52013-02-21 01:47:18 +00009024 Key.get(), Value.get(), SourceLocation(), None
Ted Kremeneke65b0862012-03-06 20:05:56 +00009025 };
9026 Elements.push_back(Element);
9027 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009028
Ted Kremeneke65b0862012-03-06 20:05:56 +00009029 if (!getDerived().AlwaysRebuild() && !ArgChanged)
9030 return SemaRef.MaybeBindToTemporary(E);
9031
9032 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
9033 Elements.data(),
9034 Elements.size());
Douglas Gregora16548e2009-08-11 05:31:07 +00009035}
9036
Mike Stump11289f42009-09-09 15:08:12 +00009037template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009038ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009039TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00009040 TypeSourceInfo *EncodedTypeInfo
9041 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
9042 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009043 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009044
Douglas Gregora16548e2009-08-11 05:31:07 +00009045 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00009046 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00009047 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009048
9049 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00009050 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00009051 E->getRParenLoc());
9052}
Mike Stump11289f42009-09-09 15:08:12 +00009053
Douglas Gregora16548e2009-08-11 05:31:07 +00009054template<typename Derived>
John McCall31168b02011-06-15 23:02:42 +00009055ExprResult TreeTransform<Derived>::
9056TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
John McCallbc489892013-04-11 02:14:26 +00009057 // This is a kind of implicit conversion, and it needs to get dropped
9058 // and recomputed for the same general reasons that ImplicitCastExprs
9059 // do, as well a more specific one: this expression is only valid when
9060 // it appears *immediately* as an argument expression.
9061 return getDerived().TransformExpr(E->getSubExpr());
John McCall31168b02011-06-15 23:02:42 +00009062}
9063
9064template<typename Derived>
9065ExprResult TreeTransform<Derived>::
9066TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier1dcde962012-08-08 18:46:20 +00009067 TypeSourceInfo *TSInfo
John McCall31168b02011-06-15 23:02:42 +00009068 = getDerived().TransformType(E->getTypeInfoAsWritten());
9069 if (!TSInfo)
9070 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009071
John McCall31168b02011-06-15 23:02:42 +00009072 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier1dcde962012-08-08 18:46:20 +00009073 if (Result.isInvalid())
John McCall31168b02011-06-15 23:02:42 +00009074 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009075
John McCall31168b02011-06-15 23:02:42 +00009076 if (!getDerived().AlwaysRebuild() &&
9077 TSInfo == E->getTypeInfoAsWritten() &&
9078 Result.get() == E->getSubExpr())
9079 return SemaRef.Owned(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009080
John McCall31168b02011-06-15 23:02:42 +00009081 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier1dcde962012-08-08 18:46:20 +00009082 E->getBridgeKeywordLoc(), TSInfo,
John McCall31168b02011-06-15 23:02:42 +00009083 Result.get());
9084}
9085
9086template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009087ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009088TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009089 // Transform arguments.
9090 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009091 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +00009092 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +00009093 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009094 &ArgChanged))
9095 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009096
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009097 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
9098 // Class message: transform the receiver type.
9099 TypeSourceInfo *ReceiverTypeInfo
9100 = getDerived().TransformType(E->getClassReceiverTypeInfo());
9101 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009102 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009103
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009104 // If nothing changed, just retain the existing message send.
9105 if (!getDerived().AlwaysRebuild() &&
9106 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009107 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009108
9109 // Build a new class message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009110 SmallVector<SourceLocation, 16> SelLocs;
9111 E->getSelectorLocs(SelLocs);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009112 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
9113 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009114 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009115 E->getMethodDecl(),
9116 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009117 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009118 E->getRightLoc());
9119 }
9120
9121 // Instance message: transform the receiver
9122 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
9123 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +00009124 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009125 = getDerived().TransformExpr(E->getInstanceReceiver());
9126 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009127 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009128
9129 // If nothing changed, just retain the existing message send.
9130 if (!getDerived().AlwaysRebuild() &&
9131 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009132 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009133
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009134 // Build a new instance message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009135 SmallVector<SourceLocation, 16> SelLocs;
9136 E->getSelectorLocs(SelLocs);
John McCallb268a282010-08-23 23:25:46 +00009137 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009138 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009139 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009140 E->getMethodDecl(),
9141 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009142 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009143 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00009144}
9145
Mike Stump11289f42009-09-09 15:08:12 +00009146template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009147ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009148TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00009149 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009150}
9151
Mike Stump11289f42009-09-09 15:08:12 +00009152template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009153ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009154TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00009155 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009156}
9157
Mike Stump11289f42009-09-09 15:08:12 +00009158template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009159ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009160TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00009161 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00009162 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00009163 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009164 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +00009165
9166 // We don't need to transform the ivar; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +00009167
Douglas Gregord51d90d2010-04-26 20:11:03 +00009168 // If nothing changed, just retain the existing expression.
9169 if (!getDerived().AlwaysRebuild() &&
9170 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00009171 return SemaRef.Owned(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009172
John McCallb268a282010-08-23 23:25:46 +00009173 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00009174 E->getLocation(),
9175 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +00009176}
9177
Mike Stump11289f42009-09-09 15:08:12 +00009178template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009179ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009180TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +00009181 // 'super' and types never change. Property never changes. Just
9182 // retain the existing expression.
9183 if (!E->isObjectReceiver())
John McCallc3007a22010-10-26 07:05:15 +00009184 return SemaRef.Owned(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009185
Douglas Gregor9faee212010-04-26 20:47:02 +00009186 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00009187 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +00009188 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009189 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009190
Douglas Gregor9faee212010-04-26 20:47:02 +00009191 // We don't need to transform the property; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +00009192
Douglas Gregor9faee212010-04-26 20:47:02 +00009193 // If nothing changed, just retain the existing expression.
9194 if (!getDerived().AlwaysRebuild() &&
9195 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00009196 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009197
John McCallb7bd14f2010-12-02 01:19:52 +00009198 if (E->isExplicitProperty())
9199 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
9200 E->getExplicitProperty(),
9201 E->getLocation());
9202
9203 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall526ab472011-10-25 17:37:35 +00009204 SemaRef.Context.PseudoObjectTy,
John McCallb7bd14f2010-12-02 01:19:52 +00009205 E->getImplicitPropertyGetter(),
9206 E->getImplicitPropertySetter(),
9207 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00009208}
9209
Mike Stump11289f42009-09-09 15:08:12 +00009210template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009211ExprResult
Ted Kremeneke65b0862012-03-06 20:05:56 +00009212TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
9213 // Transform the base expression.
9214 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
9215 if (Base.isInvalid())
9216 return ExprError();
9217
9218 // Transform the key expression.
9219 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
9220 if (Key.isInvalid())
9221 return ExprError();
9222
9223 // If nothing changed, just retain the existing expression.
9224 if (!getDerived().AlwaysRebuild() &&
9225 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
9226 return SemaRef.Owned(E);
9227
Chad Rosier1dcde962012-08-08 18:46:20 +00009228 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremeneke65b0862012-03-06 20:05:56 +00009229 Base.get(), Key.get(),
9230 E->getAtIndexMethodDecl(),
9231 E->setAtIndexMethodDecl());
9232}
9233
9234template<typename Derived>
9235ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009236TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00009237 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00009238 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00009239 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009240 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009241
Douglas Gregord51d90d2010-04-26 20:11:03 +00009242 // If nothing changed, just retain the existing expression.
9243 if (!getDerived().AlwaysRebuild() &&
9244 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00009245 return SemaRef.Owned(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009246
John McCallb268a282010-08-23 23:25:46 +00009247 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00009248 E->getOpLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00009249 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +00009250}
9251
Mike Stump11289f42009-09-09 15:08:12 +00009252template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009253ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009254TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009255 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009256 SmallVector<Expr*, 8> SubExprs;
Douglas Gregora3efea12011-01-03 19:04:46 +00009257 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier1dcde962012-08-08 18:46:20 +00009258 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00009259 SubExprs, &ArgumentChanged))
9260 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009261
Douglas Gregora16548e2009-08-11 05:31:07 +00009262 if (!getDerived().AlwaysRebuild() &&
9263 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00009264 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00009265
Douglas Gregora16548e2009-08-11 05:31:07 +00009266 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009267 SubExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00009268 E->getRParenLoc());
9269}
9270
Mike Stump11289f42009-09-09 15:08:12 +00009271template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009272ExprResult
Hal Finkelc4d7c822013-09-18 03:29:45 +00009273TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) {
9274 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
9275 if (SrcExpr.isInvalid())
9276 return ExprError();
9277
9278 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
9279 if (!Type)
9280 return ExprError();
9281
9282 if (!getDerived().AlwaysRebuild() &&
9283 Type == E->getTypeSourceInfo() &&
9284 SrcExpr.get() == E->getSrcExpr())
9285 return SemaRef.Owned(E);
9286
9287 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
9288 SrcExpr.get(), Type,
9289 E->getRParenLoc());
9290}
9291
9292template<typename Derived>
9293ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009294TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +00009295 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier1dcde962012-08-08 18:46:20 +00009296
John McCall490112f2011-02-04 18:33:18 +00009297 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
9298 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
9299
9300 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahaniandd5eb9d2011-12-03 17:47:53 +00009301 blockScope->TheDecl->setBlockMissingReturnType(
9302 oldBlock->blockMissingReturnType());
Chad Rosier1dcde962012-08-08 18:46:20 +00009303
Chris Lattner01cf8db2011-07-20 06:58:45 +00009304 SmallVector<ParmVarDecl*, 4> params;
9305 SmallVector<QualType, 4> paramTypes;
Chad Rosier1dcde962012-08-08 18:46:20 +00009306
Fariborz Jahanian1babe772010-07-09 18:44:02 +00009307 // Parameter substitution.
John McCall490112f2011-02-04 18:33:18 +00009308 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
9309 oldBlock->param_begin(),
9310 oldBlock->param_size(),
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +00009311 0, paramTypes, &params)) {
9312 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009313 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +00009314 }
John McCall490112f2011-02-04 18:33:18 +00009315
Jordan Rosea0a86be2013-03-08 22:25:36 +00009316 const FunctionProtoType *exprFunctionType = E->getFunctionType();
Eli Friedman34b49062012-01-26 03:00:14 +00009317 QualType exprResultType =
Alp Toker314cc812014-01-25 16:55:45 +00009318 getDerived().TransformType(exprFunctionType->getReturnType());
Douglas Gregor476e3022011-01-19 21:32:01 +00009319
Jordan Rose5c382722013-03-08 21:51:21 +00009320 QualType functionType =
9321 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +00009322 exprFunctionType->getExtProtoInfo());
John McCall490112f2011-02-04 18:33:18 +00009323 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +00009324
9325 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +00009326 if (!params.empty())
David Blaikie9c70e042011-09-21 18:16:56 +00009327 blockScope->TheDecl->setParams(params);
Eli Friedman34b49062012-01-26 03:00:14 +00009328
9329 if (!oldBlock->blockMissingReturnType()) {
9330 blockScope->HasImplicitReturnType = false;
9331 blockScope->ReturnType = exprResultType;
9332 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009333
John McCall3882ace2011-01-05 12:14:39 +00009334 // Transform the body
John McCall490112f2011-02-04 18:33:18 +00009335 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +00009336 if (body.isInvalid()) {
9337 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
John McCall3882ace2011-01-05 12:14:39 +00009338 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +00009339 }
John McCall3882ace2011-01-05 12:14:39 +00009340
John McCall490112f2011-02-04 18:33:18 +00009341#ifndef NDEBUG
9342 // In builds with assertions, make sure that we captured everything we
9343 // captured before.
Douglas Gregor4385d8b2011-05-20 15:32:55 +00009344 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
Aaron Ballman9371dd22014-03-14 18:34:04 +00009345 for (const auto &I : oldBlock->captures()) {
9346 VarDecl *oldCapture = I.getVariable();
John McCall490112f2011-02-04 18:33:18 +00009347
Douglas Gregor4385d8b2011-05-20 15:32:55 +00009348 // Ignore parameter packs.
9349 if (isa<ParmVarDecl>(oldCapture) &&
9350 cast<ParmVarDecl>(oldCapture)->isParameterPack())
9351 continue;
John McCall490112f2011-02-04 18:33:18 +00009352
Douglas Gregor4385d8b2011-05-20 15:32:55 +00009353 VarDecl *newCapture =
9354 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
9355 oldCapture));
9356 assert(blockScope->CaptureMap.count(newCapture));
9357 }
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00009358 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCall490112f2011-02-04 18:33:18 +00009359 }
9360#endif
9361
9362 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
9363 /*Scope=*/0);
Douglas Gregora16548e2009-08-11 05:31:07 +00009364}
9365
Mike Stump11289f42009-09-09 15:08:12 +00009366template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009367ExprResult
Tanya Lattner55808c12011-06-04 00:47:47 +00009368TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikie83d382b2011-09-23 05:06:16 +00009369 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner55808c12011-06-04 00:47:47 +00009370}
Eli Friedmandf14b3a2011-10-11 02:20:01 +00009371
9372template<typename Derived>
9373ExprResult
9374TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedman8d3e43f2011-10-14 22:48:56 +00009375 QualType RetTy = getDerived().TransformType(E->getType());
9376 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009377 SmallVector<Expr*, 8> SubExprs;
Eli Friedman8d3e43f2011-10-14 22:48:56 +00009378 SubExprs.reserve(E->getNumSubExprs());
9379 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
9380 SubExprs, &ArgumentChanged))
9381 return ExprError();
9382
9383 if (!getDerived().AlwaysRebuild() &&
9384 !ArgumentChanged)
9385 return SemaRef.Owned(E);
9386
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009387 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedman8d3e43f2011-10-14 22:48:56 +00009388 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedmandf14b3a2011-10-11 02:20:01 +00009389}
Chad Rosier1dcde962012-08-08 18:46:20 +00009390
Douglas Gregora16548e2009-08-11 05:31:07 +00009391//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00009392// Type reconstruction
9393//===----------------------------------------------------------------------===//
9394
Mike Stump11289f42009-09-09 15:08:12 +00009395template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00009396QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
9397 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00009398 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009399 getDerived().getBaseEntity());
9400}
9401
Mike Stump11289f42009-09-09 15:08:12 +00009402template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00009403QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
9404 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00009405 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009406 getDerived().getBaseEntity());
9407}
9408
Mike Stump11289f42009-09-09 15:08:12 +00009409template<typename Derived>
9410QualType
John McCall70dd5f62009-10-30 00:06:24 +00009411TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
9412 bool WrittenAsLValue,
9413 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00009414 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +00009415 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00009416}
9417
9418template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009419QualType
John McCall70dd5f62009-10-30 00:06:24 +00009420TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
9421 QualType ClassType,
9422 SourceLocation Sigil) {
Reid Kleckner0503a872013-12-05 01:23:43 +00009423 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil,
9424 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00009425}
9426
9427template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009428QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00009429TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
9430 ArrayType::ArraySizeModifier SizeMod,
9431 const llvm::APInt *Size,
9432 Expr *SizeExpr,
9433 unsigned IndexTypeQuals,
9434 SourceRange BracketsRange) {
9435 if (SizeExpr || !Size)
9436 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
9437 IndexTypeQuals, BracketsRange,
9438 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00009439
9440 QualType Types[] = {
9441 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
9442 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
9443 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00009444 };
Craig Toppere5ce8312013-07-15 03:38:40 +00009445 const unsigned NumTypes = llvm::array_lengthof(Types);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009446 QualType SizeType;
9447 for (unsigned I = 0; I != NumTypes; ++I)
9448 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
9449 SizeType = Types[I];
9450 break;
9451 }
Mike Stump11289f42009-09-09 15:08:12 +00009452
Eli Friedman9562f392012-01-25 23:20:27 +00009453 // Note that we can return a VariableArrayType here in the case where
9454 // the element type was a dependent VariableArrayType.
9455 IntegerLiteral *ArraySize
9456 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
9457 /*FIXME*/BracketsRange.getBegin());
9458 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009459 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00009460 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00009461}
Mike Stump11289f42009-09-09 15:08:12 +00009462
Douglas Gregord6ff3322009-08-04 16:50:30 +00009463template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009464QualType
9465TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009466 ArrayType::ArraySizeModifier SizeMod,
9467 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00009468 unsigned IndexTypeQuals,
9469 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00009470 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00009471 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009472}
9473
9474template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009475QualType
Mike Stump11289f42009-09-09 15:08:12 +00009476TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009477 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00009478 unsigned IndexTypeQuals,
9479 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00009480 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00009481 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009482}
Mike Stump11289f42009-09-09 15:08:12 +00009483
Douglas Gregord6ff3322009-08-04 16:50:30 +00009484template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009485QualType
9486TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009487 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00009488 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009489 unsigned IndexTypeQuals,
9490 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00009491 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00009492 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009493 IndexTypeQuals, BracketsRange);
9494}
9495
9496template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009497QualType
9498TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009499 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00009500 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009501 unsigned IndexTypeQuals,
9502 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00009503 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00009504 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009505 IndexTypeQuals, BracketsRange);
9506}
9507
9508template<typename Derived>
9509QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +00009510 unsigned NumElements,
9511 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00009512 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +00009513 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009514}
Mike Stump11289f42009-09-09 15:08:12 +00009515
Douglas Gregord6ff3322009-08-04 16:50:30 +00009516template<typename Derived>
9517QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
9518 unsigned NumElements,
9519 SourceLocation AttributeLoc) {
9520 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
9521 NumElements, true);
9522 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00009523 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
9524 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +00009525 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009526}
Mike Stump11289f42009-09-09 15:08:12 +00009527
Douglas Gregord6ff3322009-08-04 16:50:30 +00009528template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009529QualType
9530TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +00009531 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009532 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +00009533 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009534}
Mike Stump11289f42009-09-09 15:08:12 +00009535
Douglas Gregord6ff3322009-08-04 16:50:30 +00009536template<typename Derived>
Jordan Rose5c382722013-03-08 21:51:21 +00009537QualType TreeTransform<Derived>::RebuildFunctionProtoType(
9538 QualType T,
9539 llvm::MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +00009540 const FunctionProtoType::ExtProtoInfo &EPI) {
9541 return SemaRef.BuildFunctionType(T, ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009542 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +00009543 getDerived().getBaseEntity(),
Jordan Rosea0a86be2013-03-08 22:25:36 +00009544 EPI);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009545}
Mike Stump11289f42009-09-09 15:08:12 +00009546
Douglas Gregord6ff3322009-08-04 16:50:30 +00009547template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00009548QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
9549 return SemaRef.Context.getFunctionNoProtoType(T);
9550}
9551
9552template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00009553QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
9554 assert(D && "no decl found");
9555 if (D->isInvalidDecl()) return QualType();
9556
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009557 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +00009558 TypeDecl *Ty;
9559 if (isa<UsingDecl>(D)) {
9560 UsingDecl *Using = cast<UsingDecl>(D);
Enea Zaffanellae05a3cf2013-07-22 10:54:09 +00009561 assert(Using->hasTypename() &&
John McCallb96ec562009-12-04 22:46:56 +00009562 "UnresolvedUsingTypenameDecl transformed to non-typename using");
9563
9564 // A valid resolved using typename decl points to exactly one type decl.
9565 assert(++Using->shadow_begin() == Using->shadow_end());
9566 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +00009567
John McCallb96ec562009-12-04 22:46:56 +00009568 } else {
9569 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
9570 "UnresolvedUsingTypenameDecl transformed to non-using decl");
9571 Ty = cast<UnresolvedUsingTypenameDecl>(D);
9572 }
9573
9574 return SemaRef.Context.getTypeDeclType(Ty);
9575}
9576
9577template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00009578QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
9579 SourceLocation Loc) {
9580 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009581}
9582
9583template<typename Derived>
9584QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
9585 return SemaRef.Context.getTypeOfType(Underlying);
9586}
9587
9588template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00009589QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
9590 SourceLocation Loc) {
9591 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009592}
9593
9594template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00009595QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
9596 UnaryTransformType::UTTKind UKind,
9597 SourceLocation Loc) {
9598 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
9599}
9600
9601template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00009602QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00009603 TemplateName Template,
9604 SourceLocation TemplateNameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +00009605 TemplateArgumentListInfo &TemplateArgs) {
John McCall6b51f282009-11-23 01:53:49 +00009606 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009607}
Mike Stump11289f42009-09-09 15:08:12 +00009608
Douglas Gregor1135c352009-08-06 05:28:30 +00009609template<typename Derived>
Eli Friedman0dfb8892011-10-06 23:00:33 +00009610QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
9611 SourceLocation KWLoc) {
9612 return SemaRef.BuildAtomicType(ValueType, KWLoc);
9613}
9614
9615template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009616TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00009617TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +00009618 bool TemplateKW,
9619 TemplateDecl *Template) {
Douglas Gregor9db53502011-03-02 18:07:45 +00009620 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00009621 Template);
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,
9627 const IdentifierInfo &Name,
9628 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +00009629 QualType ObjectType,
9630 NamedDecl *FirstQualifierInScope) {
Douglas Gregor9db53502011-03-02 18:07:45 +00009631 UnqualifiedId TemplateName;
9632 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregorbb119652010-06-16 23:00:59 +00009633 Sema::TemplateTy Template;
Abramo Bagnara7945c982012-01-27 09:46:47 +00009634 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregorbb119652010-06-16 23:00:59 +00009635 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009636 SS, TemplateKWLoc, TemplateName,
John McCallba7bf592010-08-24 05:47:05 +00009637 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00009638 /*EnteringContext=*/false,
9639 Template);
John McCall31f82722010-11-12 08:19:04 +00009640 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +00009641}
Mike Stump11289f42009-09-09 15:08:12 +00009642
Douglas Gregora16548e2009-08-11 05:31:07 +00009643template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00009644TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00009645TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +00009646 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +00009647 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +00009648 QualType ObjectType) {
Douglas Gregor71395fa2009-11-04 00:56:37 +00009649 UnqualifiedId Name;
Douglas Gregor9db53502011-03-02 18:07:45 +00009650 // FIXME: Bogus location information.
Abramo Bagnara7945c982012-01-27 09:46:47 +00009651 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregor9db53502011-03-02 18:07:45 +00009652 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnara7945c982012-01-27 09:46:47 +00009653 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregorbb119652010-06-16 23:00:59 +00009654 Sema::TemplateTy Template;
9655 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009656 SS, TemplateKWLoc, Name,
John McCallba7bf592010-08-24 05:47:05 +00009657 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00009658 /*EnteringContext=*/false,
9659 Template);
Serge Pavlov9ddb76e2013-08-27 13:15:56 +00009660 return Template.get();
Douglas Gregor71395fa2009-11-04 00:56:37 +00009661}
Chad Rosier1dcde962012-08-08 18:46:20 +00009662
Douglas Gregor71395fa2009-11-04 00:56:37 +00009663template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009664ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009665TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
9666 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00009667 Expr *OrigCallee,
9668 Expr *First,
9669 Expr *Second) {
9670 Expr *Callee = OrigCallee->IgnoreParenCasts();
9671 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00009672
Douglas Gregora16548e2009-08-11 05:31:07 +00009673 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00009674 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +00009675 if (!First->getType()->isOverloadableType() &&
9676 !Second->getType()->isOverloadableType())
9677 return getSema().CreateBuiltinArraySubscriptExpr(First,
9678 Callee->getLocStart(),
9679 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00009680 } else if (Op == OO_Arrow) {
9681 // -> is never a builtin operation.
John McCallb268a282010-08-23 23:25:46 +00009682 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
9683 } else if (Second == 0 || isPostIncDec) {
9684 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009685 // The argument is not of overloadable type, so try to create a
9686 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +00009687 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00009688 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00009689
John McCallb268a282010-08-23 23:25:46 +00009690 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00009691 }
9692 } else {
John McCallb268a282010-08-23 23:25:46 +00009693 if (!First->getType()->isOverloadableType() &&
9694 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009695 // Neither of the arguments is an overloadable type, so try to
9696 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +00009697 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00009698 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00009699 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +00009700 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009701 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009702
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009703 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00009704 }
9705 }
Mike Stump11289f42009-09-09 15:08:12 +00009706
9707 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00009708 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00009709 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00009710
John McCallb268a282010-08-23 23:25:46 +00009711 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +00009712 assert(ULE->requiresADL());
9713
9714 // FIXME: Do we have to check
9715 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall4c4c1df2010-01-26 03:27:55 +00009716 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00009717 } else {
Richard Smith58db83d2012-11-28 21:47:39 +00009718 // If we've resolved this to a particular non-member function, just call
9719 // that function. If we resolved it to a member function,
9720 // CreateOverloaded* will find that function for us.
9721 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
9722 if (!isa<CXXMethodDecl>(ND))
9723 Functions.addDecl(ND);
John McCalld14a8642009-11-21 08:51:07 +00009724 }
Mike Stump11289f42009-09-09 15:08:12 +00009725
Douglas Gregora16548e2009-08-11 05:31:07 +00009726 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +00009727 Expr *Args[2] = { First, Second };
9728 unsigned NumArgs = 1 + (Second != 0);
Mike Stump11289f42009-09-09 15:08:12 +00009729
Douglas Gregora16548e2009-08-11 05:31:07 +00009730 // Create the overloaded operator invocation for unary operators.
9731 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +00009732 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00009733 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +00009734 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00009735 }
Mike Stump11289f42009-09-09 15:08:12 +00009736
Douglas Gregore9d62932011-07-15 16:25:15 +00009737 if (Op == OO_Subscript) {
9738 SourceLocation LBrace;
9739 SourceLocation RBrace;
9740
9741 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
9742 DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
9743 LBrace = SourceLocation::getFromRawEncoding(
9744 NameLoc.CXXOperatorName.BeginOpNameLoc);
9745 RBrace = SourceLocation::getFromRawEncoding(
9746 NameLoc.CXXOperatorName.EndOpNameLoc);
9747 } else {
9748 LBrace = Callee->getLocStart();
9749 RBrace = OpLoc;
9750 }
9751
9752 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
9753 First, Second);
9754 }
Sebastian Redladba46e2009-10-29 20:17:01 +00009755
Douglas Gregora16548e2009-08-11 05:31:07 +00009756 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +00009757 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00009758 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00009759 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
9760 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009761 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009762
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009763 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00009764}
Mike Stump11289f42009-09-09 15:08:12 +00009765
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009766template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00009767ExprResult
John McCallb268a282010-08-23 23:25:46 +00009768TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009769 SourceLocation OperatorLoc,
9770 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +00009771 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009772 TypeSourceInfo *ScopeType,
9773 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00009774 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00009775 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +00009776 QualType BaseType = Base->getType();
9777 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009778 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier1dcde962012-08-08 18:46:20 +00009779 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +00009780 !BaseType->getAs<PointerType>()->getPointeeType()
9781 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009782 // This pseudo-destructor expression is still a pseudo-destructor.
John McCallb268a282010-08-23 23:25:46 +00009783 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009784 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00009785 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00009786 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009787 /*FIXME?*/true);
9788 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009789
Douglas Gregor678f90d2010-02-25 01:56:36 +00009790 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009791 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
9792 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
9793 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
9794 NameInfo.setNamedTypeInfo(DestroyedType);
9795
Richard Smith8e4a3862012-05-15 06:15:11 +00009796 // The scope type is now known to be a valid nested name specifier
9797 // component. Tack it on to the end of the nested name specifier.
9798 if (ScopeType)
9799 SS.Extend(SemaRef.Context, SourceLocation(),
9800 ScopeType->getTypeLoc(), CCLoc);
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009801
Abramo Bagnara7945c982012-01-27 09:46:47 +00009802 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCallb268a282010-08-23 23:25:46 +00009803 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009804 OperatorLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009805 SS, TemplateKWLoc,
9806 /*FIXME: FirstQualifier*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009807 NameInfo,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009808 /*TemplateArgs*/ 0);
9809}
9810
Tareq A. Siraj24110cc2013-04-16 18:53:08 +00009811template<typename Derived>
9812StmtResult
9813TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
Wei Pan17fbf6e2013-05-04 03:59:06 +00009814 SourceLocation Loc = S->getLocStart();
9815 unsigned NumParams = S->getCapturedDecl()->getNumParams();
9816 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/0,
9817 S->getCapturedRegionKind(), NumParams);
9818 StmtResult Body = getDerived().TransformStmt(S->getCapturedStmt());
9819
9820 if (Body.isInvalid()) {
9821 getSema().ActOnCapturedRegionError();
9822 return StmtError();
9823 }
9824
9825 return getSema().ActOnCapturedRegionEnd(Body.take());
Tareq A. Siraj24110cc2013-04-16 18:53:08 +00009826}
9827
Douglas Gregord6ff3322009-08-04 16:50:30 +00009828} // end namespace clang
9829
9830#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H