blob: c1847fa7d5b3b71b57f99ebf27fcc736395a9a1c [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;
Douglas Gregorebe10102009-08-20 07:17:43 +00005276 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
5277 B != BEnd; ++B) {
John McCalldadc5752010-08-24 06:29:42 +00005278 StmtResult Result = getDerived().TransformStmt(*B);
John McCall1ababa62010-08-27 19:56:05 +00005279 if (Result.isInvalid()) {
5280 // Immediately fail if this was a DeclStmt, since it's very
5281 // likely that this will cause problems for future statements.
5282 if (isa<DeclStmt>(*B))
5283 return StmtError();
5284
5285 // Otherwise, just keep processing substatements and fail later.
5286 SubStmtInvalid = true;
5287 continue;
5288 }
Mike Stump11289f42009-09-09 15:08:12 +00005289
Douglas Gregorebe10102009-08-20 07:17:43 +00005290 SubStmtChanged = SubStmtChanged || Result.get() != *B;
5291 Statements.push_back(Result.takeAs<Stmt>());
5292 }
Mike Stump11289f42009-09-09 15:08:12 +00005293
John McCall1ababa62010-08-27 19:56:05 +00005294 if (SubStmtInvalid)
5295 return StmtError();
5296
Douglas Gregorebe10102009-08-20 07:17:43 +00005297 if (!getDerived().AlwaysRebuild() &&
5298 !SubStmtChanged)
John McCallc3007a22010-10-26 07:05:15 +00005299 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005300
5301 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00005302 Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00005303 S->getRBracLoc(),
5304 IsStmtExpr);
5305}
Mike Stump11289f42009-09-09 15:08:12 +00005306
Douglas Gregorebe10102009-08-20 07:17:43 +00005307template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005308StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005309TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005310 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00005311 {
Eli Friedman1f4f9dd2012-01-18 02:54:10 +00005312 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5313 Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005314
Eli Friedman06577382009-11-19 03:14:00 +00005315 // Transform the left-hand case value.
5316 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00005317 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman06577382009-11-19 03:14:00 +00005318 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005319 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005320
Eli Friedman06577382009-11-19 03:14:00 +00005321 // Transform the right-hand case value (for the GNU case-range extension).
5322 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00005323 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman06577382009-11-19 03:14:00 +00005324 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005325 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00005326 }
Mike Stump11289f42009-09-09 15:08:12 +00005327
Douglas Gregorebe10102009-08-20 07:17:43 +00005328 // Build the case statement.
5329 // Case statements are always rebuilt so that they will attached to their
5330 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005331 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00005332 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005333 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00005334 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005335 S->getColonLoc());
5336 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005337 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005338
Douglas Gregorebe10102009-08-20 07:17:43 +00005339 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00005340 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005341 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005342 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005343
Douglas Gregorebe10102009-08-20 07:17:43 +00005344 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00005345 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005346}
5347
5348template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005349StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005350TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005351 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00005352 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005353 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005354 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005355
Douglas Gregorebe10102009-08-20 07:17:43 +00005356 // Default statements are always rebuilt
5357 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00005358 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005359}
Mike Stump11289f42009-09-09 15:08:12 +00005360
Douglas Gregorebe10102009-08-20 07:17:43 +00005361template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005362StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005363TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005364 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005365 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005366 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005367
Chris Lattnercab02a62011-02-17 20:34:02 +00005368 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5369 S->getDecl());
5370 if (!LD)
5371 return StmtError();
Richard Smithc202b282012-04-14 00:33:13 +00005372
5373
Douglas Gregorebe10102009-08-20 07:17:43 +00005374 // FIXME: Pass the real colon location in.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00005375 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005376 cast<LabelDecl>(LD), SourceLocation(),
5377 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005378}
Mike Stump11289f42009-09-09 15:08:12 +00005379
Douglas Gregorebe10102009-08-20 07:17:43 +00005380template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005381StmtResult
Richard Smithc202b282012-04-14 00:33:13 +00005382TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
5383 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5384 if (SubStmt.isInvalid())
5385 return StmtError();
5386
5387 // TODO: transform attributes
5388 if (SubStmt.get() == S->getSubStmt() /* && attrs are the same */)
5389 return S;
5390
5391 return getDerived().RebuildAttributedStmt(S->getAttrLoc(),
5392 S->getAttrs(),
5393 SubStmt.get());
5394}
5395
5396template<typename Derived>
5397StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005398TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005399 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005400 ExprResult Cond;
Douglas Gregor633caca2009-11-23 23:44:04 +00005401 VarDecl *ConditionVar = 0;
5402 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005403 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00005404 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005405 getDerived().TransformDefinition(
5406 S->getConditionVariable()->getLocation(),
5407 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00005408 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005409 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005410 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00005411 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005412
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005413 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005414 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005415
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005416 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00005417 if (S->getCond()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005418 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005419 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005420 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005421 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005422
John McCallb268a282010-08-23 23:25:46 +00005423 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005424 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005425 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005426
John McCallb268a282010-08-23 23:25:46 +00005427 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5428 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005429 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005430
Douglas Gregorebe10102009-08-20 07:17:43 +00005431 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00005432 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00005433 if (Then.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005434 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005435
Douglas Gregorebe10102009-08-20 07:17:43 +00005436 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00005437 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00005438 if (Else.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005439 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005440
Douglas Gregorebe10102009-08-20 07:17:43 +00005441 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00005442 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005443 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005444 Then.get() == S->getThen() &&
5445 Else.get() == S->getElse())
John McCallc3007a22010-10-26 07:05:15 +00005446 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005447
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005448 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00005449 Then.get(),
John McCallb268a282010-08-23 23:25:46 +00005450 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005451}
5452
5453template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005454StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005455TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005456 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00005457 ExprResult Cond;
Douglas Gregordcf19622009-11-24 17:07:59 +00005458 VarDecl *ConditionVar = 0;
5459 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005460 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00005461 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005462 getDerived().TransformDefinition(
5463 S->getConditionVariable()->getLocation(),
5464 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00005465 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005466 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005467 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00005468 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005469
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005470 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005471 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005472 }
Mike Stump11289f42009-09-09 15:08:12 +00005473
Douglas Gregorebe10102009-08-20 07:17:43 +00005474 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005475 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00005476 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00005477 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00005478 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005479 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005480
Douglas Gregorebe10102009-08-20 07:17:43 +00005481 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005482 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005483 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005484 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005485
Douglas Gregorebe10102009-08-20 07:17:43 +00005486 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00005487 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5488 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005489}
Mike Stump11289f42009-09-09 15:08:12 +00005490
Douglas Gregorebe10102009-08-20 07:17:43 +00005491template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005492StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005493TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005494 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005495 ExprResult Cond;
Douglas Gregor680f8612009-11-24 21:15:44 +00005496 VarDecl *ConditionVar = 0;
5497 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005498 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00005499 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005500 getDerived().TransformDefinition(
5501 S->getConditionVariable()->getLocation(),
5502 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00005503 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005504 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005505 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00005506 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005507
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005508 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005509 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005510
5511 if (S->getCond()) {
5512 // Convert the condition to a boolean value.
Chad Rosier1dcde962012-08-08 18:46:20 +00005513 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005514 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005515 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005516 return StmtError();
John McCallb268a282010-08-23 23:25:46 +00005517 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00005518 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005519 }
Mike Stump11289f42009-09-09 15:08:12 +00005520
John McCallb268a282010-08-23 23:25:46 +00005521 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5522 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005523 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005524
Douglas Gregorebe10102009-08-20 07:17:43 +00005525 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005526 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005527 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005528 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005529
Douglas Gregorebe10102009-08-20 07:17:43 +00005530 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00005531 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005532 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005533 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00005534 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005535
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005536 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00005537 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005538}
Mike Stump11289f42009-09-09 15:08:12 +00005539
Douglas Gregorebe10102009-08-20 07:17:43 +00005540template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005541StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005542TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005543 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005544 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005545 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005546 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005547
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005548 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005549 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005550 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005551 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005552
Douglas Gregorebe10102009-08-20 07:17:43 +00005553 if (!getDerived().AlwaysRebuild() &&
5554 Cond.get() == S->getCond() &&
5555 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005556 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005557
John McCallb268a282010-08-23 23:25:46 +00005558 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5559 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005560 S->getRParenLoc());
5561}
Mike Stump11289f42009-09-09 15:08:12 +00005562
Douglas Gregorebe10102009-08-20 07:17:43 +00005563template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005564StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005565TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005566 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00005567 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00005568 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005569 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005570
Douglas Gregorebe10102009-08-20 07:17:43 +00005571 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005572 ExprResult Cond;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005573 VarDecl *ConditionVar = 0;
5574 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005575 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005576 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005577 getDerived().TransformDefinition(
5578 S->getConditionVariable()->getLocation(),
5579 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005580 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005581 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005582 } else {
5583 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005584
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005585 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005586 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005587
5588 if (S->getCond()) {
5589 // Convert the condition to a boolean value.
Chad Rosier1dcde962012-08-08 18:46:20 +00005590 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005591 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005592 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005593 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005594
John McCallb268a282010-08-23 23:25:46 +00005595 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005596 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005597 }
Mike Stump11289f42009-09-09 15:08:12 +00005598
Chad Rosier1dcde962012-08-08 18:46:20 +00005599 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
John McCallb268a282010-08-23 23:25:46 +00005600 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005601 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005602
Douglas Gregorebe10102009-08-20 07:17:43 +00005603 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00005604 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005605 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005606 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005607
Richard Smith945f8d32013-01-14 22:39:08 +00005608 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
John McCallb268a282010-08-23 23:25:46 +00005609 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005610 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005611
Douglas Gregorebe10102009-08-20 07:17:43 +00005612 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005613 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005614 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005615 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005616
Douglas Gregorebe10102009-08-20 07:17:43 +00005617 if (!getDerived().AlwaysRebuild() &&
5618 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00005619 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005620 Inc.get() == S->getInc() &&
5621 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005622 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005623
Douglas Gregorebe10102009-08-20 07:17:43 +00005624 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005625 Init.get(), FullCond, ConditionVar,
5626 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005627}
5628
5629template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005630StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005631TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattnercab02a62011-02-17 20:34:02 +00005632 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5633 S->getLabel());
5634 if (!LD)
5635 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005636
Douglas Gregorebe10102009-08-20 07:17:43 +00005637 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00005638 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005639 cast<LabelDecl>(LD));
Douglas Gregorebe10102009-08-20 07:17:43 +00005640}
5641
5642template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005643StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005644TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005645 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00005646 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005647 return StmtError();
Eli Friedman9ccdb1d2012-01-31 22:47:07 +00005648 Target = SemaRef.MaybeCreateExprWithCleanups(Target.take());
Mike Stump11289f42009-09-09 15:08:12 +00005649
Douglas Gregorebe10102009-08-20 07:17:43 +00005650 if (!getDerived().AlwaysRebuild() &&
5651 Target.get() == S->getTarget())
John McCallc3007a22010-10-26 07:05:15 +00005652 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005653
5654 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00005655 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005656}
5657
5658template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005659StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005660TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00005661 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005662}
Mike Stump11289f42009-09-09 15:08:12 +00005663
Douglas Gregorebe10102009-08-20 07:17:43 +00005664template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005665StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005666TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00005667 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005668}
Mike Stump11289f42009-09-09 15:08:12 +00005669
Douglas Gregorebe10102009-08-20 07:17:43 +00005670template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005671StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005672TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005673 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregorebe10102009-08-20 07:17:43 +00005674 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005675 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00005676
Mike Stump11289f42009-09-09 15:08:12 +00005677 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00005678 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00005679 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005680}
Mike Stump11289f42009-09-09 15:08:12 +00005681
Douglas Gregorebe10102009-08-20 07:17:43 +00005682template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005683StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005684TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005685 bool DeclChanged = false;
Chris Lattner01cf8db2011-07-20 06:58:45 +00005686 SmallVector<Decl *, 4> Decls;
Douglas Gregorebe10102009-08-20 07:17:43 +00005687 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5688 D != DEnd; ++D) {
Douglas Gregor25289362010-03-01 17:25:41 +00005689 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5690 *D);
Douglas Gregorebe10102009-08-20 07:17:43 +00005691 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00005692 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005693
Douglas Gregorebe10102009-08-20 07:17:43 +00005694 if (Transformed != *D)
5695 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00005696
Douglas Gregorebe10102009-08-20 07:17:43 +00005697 Decls.push_back(Transformed);
5698 }
Mike Stump11289f42009-09-09 15:08:12 +00005699
Douglas Gregorebe10102009-08-20 07:17:43 +00005700 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCallc3007a22010-10-26 07:05:15 +00005701 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005702
Rafael Espindolaab417692013-07-09 12:05:01 +00005703 return getDerived().RebuildDeclStmt(Decls, S->getStartLoc(), S->getEndLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005704}
Mike Stump11289f42009-09-09 15:08:12 +00005705
Douglas Gregorebe10102009-08-20 07:17:43 +00005706template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005707StmtResult
Chad Rosierde70e0e2012-08-25 00:11:56 +00005708TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005709
Benjamin Kramerf0623432012-08-23 22:51:59 +00005710 SmallVector<Expr*, 8> Constraints;
5711 SmallVector<Expr*, 8> Exprs;
Chris Lattner01cf8db2011-07-20 06:58:45 +00005712 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00005713
John McCalldadc5752010-08-24 06:29:42 +00005714 ExprResult AsmString;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005715 SmallVector<Expr*, 8> Clobbers;
Anders Carlssonaaeef072010-01-24 05:50:09 +00005716
5717 bool ExprsChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00005718
Anders Carlssonaaeef072010-01-24 05:50:09 +00005719 // Go through the outputs.
5720 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005721 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005722
Anders Carlssonaaeef072010-01-24 05:50:09 +00005723 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005724 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005725
Anders Carlssonaaeef072010-01-24 05:50:09 +00005726 // Transform the output expr.
5727 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005728 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005729 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005730 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005731
Anders Carlssonaaeef072010-01-24 05:50:09 +00005732 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00005733
John McCallb268a282010-08-23 23:25:46 +00005734 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005735 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005736
Anders Carlssonaaeef072010-01-24 05:50:09 +00005737 // Go through the inputs.
5738 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005739 Names.push_back(S->getInputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005740
Anders Carlssonaaeef072010-01-24 05:50:09 +00005741 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005742 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005743
Anders Carlssonaaeef072010-01-24 05:50:09 +00005744 // Transform the input expr.
5745 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005746 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005747 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005748 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005749
Anders Carlssonaaeef072010-01-24 05:50:09 +00005750 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00005751
John McCallb268a282010-08-23 23:25:46 +00005752 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005753 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005754
Anders Carlssonaaeef072010-01-24 05:50:09 +00005755 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCallc3007a22010-10-26 07:05:15 +00005756 return SemaRef.Owned(S);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005757
5758 // Go through the clobbers.
5759 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosierd9fb09a2012-08-27 23:28:41 +00005760 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00005761
5762 // No need to transform the asm string literal.
5763 AsmString = SemaRef.Owned(S->getAsmString());
Chad Rosierde70e0e2012-08-25 00:11:56 +00005764 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
5765 S->isVolatile(), S->getNumOutputs(),
5766 S->getNumInputs(), Names.data(),
5767 Constraints, Exprs, AsmString.get(),
5768 Clobbers, S->getRParenLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005769}
5770
Chad Rosier32503022012-06-11 20:47:18 +00005771template<typename Derived>
5772StmtResult
5773TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier99fc3812012-08-07 00:29:06 +00005774 ArrayRef<Token> AsmToks =
5775 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier3ed0bd92012-08-08 19:48:07 +00005776
John McCallf413f5e2013-05-03 00:10:13 +00005777 bool HadError = false, HadChange = false;
5778
5779 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
5780 SmallVector<Expr*, 8> TransformedExprs;
5781 TransformedExprs.reserve(SrcExprs.size());
5782 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
5783 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
5784 if (!Result.isUsable()) {
5785 HadError = true;
5786 } else {
5787 HadChange |= (Result.get() != SrcExprs[i]);
5788 TransformedExprs.push_back(Result.take());
5789 }
5790 }
5791
5792 if (HadError) return StmtError();
5793 if (!HadChange && !getDerived().AlwaysRebuild())
5794 return Owned(S);
5795
Chad Rosierb6f46c12012-08-15 16:53:30 +00005796 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
John McCallf413f5e2013-05-03 00:10:13 +00005797 AsmToks, S->getAsmString(),
5798 S->getNumOutputs(), S->getNumInputs(),
5799 S->getAllConstraints(), S->getClobbers(),
5800 TransformedExprs, S->getEndLoc());
Chad Rosier32503022012-06-11 20:47:18 +00005801}
Douglas Gregorebe10102009-08-20 07:17:43 +00005802
5803template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005804StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005805TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005806 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00005807 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005808 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005809 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005810
Douglas Gregor96c79492010-04-23 22:50:49 +00005811 // Transform the @catch statements (if present).
5812 bool AnyCatchChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005813 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor96c79492010-04-23 22:50:49 +00005814 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00005815 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00005816 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005817 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00005818 if (Catch.get() != S->getCatchStmt(I))
5819 AnyCatchChanged = true;
5820 CatchStmts.push_back(Catch.release());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005821 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005822
Douglas Gregor306de2f2010-04-22 23:59:56 +00005823 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00005824 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00005825 if (S->getFinallyStmt()) {
5826 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5827 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005828 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00005829 }
5830
5831 // If nothing changed, just retain this statement.
5832 if (!getDerived().AlwaysRebuild() &&
5833 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00005834 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00005835 Finally.get() == S->getFinallyStmt())
John McCallc3007a22010-10-26 07:05:15 +00005836 return SemaRef.Owned(S);
Chad Rosier1dcde962012-08-08 18:46:20 +00005837
Douglas Gregor306de2f2010-04-22 23:59:56 +00005838 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00005839 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00005840 CatchStmts, Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005841}
Mike Stump11289f42009-09-09 15:08:12 +00005842
Douglas Gregorebe10102009-08-20 07:17:43 +00005843template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005844StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005845TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005846 // Transform the @catch parameter, if there is one.
5847 VarDecl *Var = 0;
5848 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5849 TypeSourceInfo *TSInfo = 0;
5850 if (FromVar->getTypeSourceInfo()) {
5851 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5852 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005853 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005854 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005855
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005856 QualType T;
5857 if (TSInfo)
5858 T = TSInfo->getType();
5859 else {
5860 T = getDerived().TransformType(FromVar->getType());
5861 if (T.isNull())
Chad Rosier1dcde962012-08-08 18:46:20 +00005862 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005863 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005864
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005865 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5866 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00005867 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005868 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005869
John McCalldadc5752010-08-24 06:29:42 +00005870 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005871 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005872 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005873
5874 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005875 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005876 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005877}
Mike Stump11289f42009-09-09 15:08:12 +00005878
Douglas Gregorebe10102009-08-20 07:17:43 +00005879template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005880StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005881TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005882 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005883 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005884 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005885 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005886
Douglas Gregor306de2f2010-04-22 23:59:56 +00005887 // If nothing changed, just retain this statement.
5888 if (!getDerived().AlwaysRebuild() &&
5889 Body.get() == S->getFinallyBody())
John McCallc3007a22010-10-26 07:05:15 +00005890 return SemaRef.Owned(S);
Douglas Gregor306de2f2010-04-22 23:59:56 +00005891
5892 // Build a new statement.
5893 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00005894 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005895}
Mike Stump11289f42009-09-09 15:08:12 +00005896
Douglas Gregorebe10102009-08-20 07:17:43 +00005897template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005898StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005899TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005900 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00005901 if (S->getThrowExpr()) {
5902 Operand = getDerived().TransformExpr(S->getThrowExpr());
5903 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005904 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00005905 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005906
Douglas Gregor2900c162010-04-22 21:44:01 +00005907 if (!getDerived().AlwaysRebuild() &&
5908 Operand.get() == S->getThrowExpr())
John McCallc3007a22010-10-26 07:05:15 +00005909 return getSema().Owned(S);
Chad Rosier1dcde962012-08-08 18:46:20 +00005910
John McCallb268a282010-08-23 23:25:46 +00005911 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005912}
Mike Stump11289f42009-09-09 15:08:12 +00005913
Douglas Gregorebe10102009-08-20 07:17:43 +00005914template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005915StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005916TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00005917 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00005918 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00005919 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00005920 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005921 return StmtError();
John McCalld9bb7432011-07-27 21:50:02 +00005922 Object =
5923 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
5924 Object.get());
5925 if (Object.isInvalid())
5926 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005927
Douglas Gregor6148de72010-04-22 22:01:21 +00005928 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005929 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00005930 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005931 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005932
Douglas Gregor6148de72010-04-22 22:01:21 +00005933 // If nothing change, just retain the current statement.
5934 if (!getDerived().AlwaysRebuild() &&
5935 Object.get() == S->getSynchExpr() &&
5936 Body.get() == S->getSynchBody())
John McCallc3007a22010-10-26 07:05:15 +00005937 return SemaRef.Owned(S);
Douglas Gregor6148de72010-04-22 22:01:21 +00005938
5939 // Build a new statement.
5940 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00005941 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005942}
5943
5944template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005945StmtResult
John McCall31168b02011-06-15 23:02:42 +00005946TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
5947 ObjCAutoreleasePoolStmt *S) {
5948 // Transform the body.
5949 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
5950 if (Body.isInvalid())
5951 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005952
John McCall31168b02011-06-15 23:02:42 +00005953 // If nothing changed, just retain this statement.
5954 if (!getDerived().AlwaysRebuild() &&
5955 Body.get() == S->getSubStmt())
5956 return SemaRef.Owned(S);
5957
5958 // Build a new statement.
5959 return getDerived().RebuildObjCAutoreleasePoolStmt(
5960 S->getAtLoc(), Body.get());
5961}
5962
5963template<typename Derived>
5964StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005965TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00005966 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00005967 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00005968 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005969 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005970 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005971
Douglas Gregorf68a5082010-04-22 23:10:45 +00005972 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00005973 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005974 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005975 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005976
Douglas Gregorf68a5082010-04-22 23:10:45 +00005977 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005978 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005979 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005980 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005981
Douglas Gregorf68a5082010-04-22 23:10:45 +00005982 // If nothing changed, just retain this statement.
5983 if (!getDerived().AlwaysRebuild() &&
5984 Element.get() == S->getElement() &&
5985 Collection.get() == S->getCollection() &&
5986 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005987 return SemaRef.Owned(S);
Chad Rosier1dcde962012-08-08 18:46:20 +00005988
Douglas Gregorf68a5082010-04-22 23:10:45 +00005989 // Build a new statement.
5990 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00005991 Element.get(),
5992 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00005993 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005994 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005995}
5996
David Majnemer5f7efef2013-10-15 09:50:08 +00005997template <typename Derived>
5998StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005999 // Transform the exception declaration, if any.
6000 VarDecl *Var = 0;
David Majnemer5f7efef2013-10-15 09:50:08 +00006001 if (VarDecl *ExceptionDecl = S->getExceptionDecl()) {
6002 TypeSourceInfo *T =
6003 getDerived().TransformType(ExceptionDecl->getTypeSourceInfo());
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00006004 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006005 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006006
David Majnemer5f7efef2013-10-15 09:50:08 +00006007 Var = getDerived().RebuildExceptionDecl(
6008 ExceptionDecl, T, ExceptionDecl->getInnerLocStart(),
6009 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
Douglas Gregorb412e172010-07-25 18:17:45 +00006010 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00006011 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00006012 }
Mike Stump11289f42009-09-09 15:08:12 +00006013
Douglas Gregorebe10102009-08-20 07:17:43 +00006014 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00006015 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00006016 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006017 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006018
David Majnemer5f7efef2013-10-15 09:50:08 +00006019 if (!getDerived().AlwaysRebuild() && !Var &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006020 Handler.get() == S->getHandlerBlock())
John McCallc3007a22010-10-26 07:05:15 +00006021 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00006022
David Majnemer5f7efef2013-10-15 09:50:08 +00006023 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006024}
Mike Stump11289f42009-09-09 15:08:12 +00006025
David Majnemer5f7efef2013-10-15 09:50:08 +00006026template <typename Derived>
6027StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006028 // Transform the try block itself.
David Majnemer5f7efef2013-10-15 09:50:08 +00006029 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
Douglas Gregorebe10102009-08-20 07:17:43 +00006030 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006031 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006032
Douglas Gregorebe10102009-08-20 07:17:43 +00006033 // Transform the handlers.
6034 bool HandlerChanged = false;
David Majnemer5f7efef2013-10-15 09:50:08 +00006035 SmallVector<Stmt *, 8> Handlers;
Douglas Gregorebe10102009-08-20 07:17:43 +00006036 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
David Majnemer5f7efef2013-10-15 09:50:08 +00006037 StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I));
Douglas Gregorebe10102009-08-20 07:17:43 +00006038 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006039 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006040
Douglas Gregorebe10102009-08-20 07:17:43 +00006041 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
6042 Handlers.push_back(Handler.takeAs<Stmt>());
6043 }
Mike Stump11289f42009-09-09 15:08:12 +00006044
David Majnemer5f7efef2013-10-15 09:50:08 +00006045 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006046 !HandlerChanged)
John McCallc3007a22010-10-26 07:05:15 +00006047 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00006048
John McCallb268a282010-08-23 23:25:46 +00006049 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006050 Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00006051}
Mike Stump11289f42009-09-09 15:08:12 +00006052
Richard Smith02e85f32011-04-14 22:09:26 +00006053template<typename Derived>
6054StmtResult
6055TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
6056 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
6057 if (Range.isInvalid())
6058 return StmtError();
6059
6060 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
6061 if (BeginEnd.isInvalid())
6062 return StmtError();
6063
6064 ExprResult Cond = getDerived().TransformExpr(S->getCond());
6065 if (Cond.isInvalid())
6066 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006067 if (Cond.get())
6068 Cond = SemaRef.CheckBooleanCondition(Cond.take(), S->getColonLoc());
6069 if (Cond.isInvalid())
6070 return StmtError();
6071 if (Cond.get())
6072 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.take());
Richard Smith02e85f32011-04-14 22:09:26 +00006073
6074 ExprResult Inc = getDerived().TransformExpr(S->getInc());
6075 if (Inc.isInvalid())
6076 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006077 if (Inc.get())
6078 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.take());
Richard Smith02e85f32011-04-14 22:09:26 +00006079
6080 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
6081 if (LoopVar.isInvalid())
6082 return StmtError();
6083
6084 StmtResult NewStmt = S;
6085 if (getDerived().AlwaysRebuild() ||
6086 Range.get() != S->getRangeStmt() ||
6087 BeginEnd.get() != S->getBeginEndStmt() ||
6088 Cond.get() != S->getCond() ||
6089 Inc.get() != S->getInc() ||
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006090 LoopVar.get() != S->getLoopVarStmt()) {
Richard Smith02e85f32011-04-14 22:09:26 +00006091 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6092 S->getColonLoc(), Range.get(),
6093 BeginEnd.get(), Cond.get(),
6094 Inc.get(), LoopVar.get(),
6095 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006096 if (NewStmt.isInvalid())
6097 return StmtError();
6098 }
Richard Smith02e85f32011-04-14 22:09:26 +00006099
6100 StmtResult Body = getDerived().TransformStmt(S->getBody());
6101 if (Body.isInvalid())
6102 return StmtError();
6103
6104 // Body has changed but we didn't rebuild the for-range statement. Rebuild
6105 // it now so we have a new statement to attach the body to.
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006106 if (Body.get() != S->getBody() && NewStmt.get() == S) {
Richard Smith02e85f32011-04-14 22:09:26 +00006107 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6108 S->getColonLoc(), Range.get(),
6109 BeginEnd.get(), Cond.get(),
6110 Inc.get(), LoopVar.get(),
6111 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006112 if (NewStmt.isInvalid())
6113 return StmtError();
6114 }
Richard Smith02e85f32011-04-14 22:09:26 +00006115
6116 if (NewStmt.get() == S)
6117 return SemaRef.Owned(S);
6118
6119 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
6120}
6121
John Wiegley1c0675e2011-04-28 01:08:34 +00006122template<typename Derived>
6123StmtResult
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006124TreeTransform<Derived>::TransformMSDependentExistsStmt(
6125 MSDependentExistsStmt *S) {
6126 // Transform the nested-name-specifier, if any.
6127 NestedNameSpecifierLoc QualifierLoc;
6128 if (S->getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006129 QualifierLoc
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006130 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
6131 if (!QualifierLoc)
6132 return StmtError();
6133 }
6134
6135 // Transform the declaration name.
6136 DeclarationNameInfo NameInfo = S->getNameInfo();
6137 if (NameInfo.getName()) {
6138 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6139 if (!NameInfo.getName())
6140 return StmtError();
6141 }
6142
6143 // Check whether anything changed.
6144 if (!getDerived().AlwaysRebuild() &&
6145 QualifierLoc == S->getQualifierLoc() &&
6146 NameInfo.getName() == S->getNameInfo().getName())
6147 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006148
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006149 // Determine whether this name exists, if we can.
6150 CXXScopeSpec SS;
6151 SS.Adopt(QualifierLoc);
6152 bool Dependent = false;
6153 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/0, SS, NameInfo)) {
6154 case Sema::IER_Exists:
6155 if (S->isIfExists())
6156 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006157
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006158 return new (getSema().Context) NullStmt(S->getKeywordLoc());
6159
6160 case Sema::IER_DoesNotExist:
6161 if (S->isIfNotExists())
6162 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006163
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006164 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00006165
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006166 case Sema::IER_Dependent:
6167 Dependent = true;
6168 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006169
Douglas Gregor4a2a8f72011-10-25 03:44:56 +00006170 case Sema::IER_Error:
6171 return StmtError();
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006172 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006173
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006174 // We need to continue with the instantiation, so do so now.
6175 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
6176 if (SubStmt.isInvalid())
6177 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006178
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006179 // If we have resolved the name, just transform to the substatement.
6180 if (!Dependent)
6181 return SubStmt;
Chad Rosier1dcde962012-08-08 18:46:20 +00006182
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006183 // The name is still dependent, so build a dependent expression again.
6184 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
6185 S->isIfExists(),
6186 QualifierLoc,
6187 NameInfo,
6188 SubStmt.get());
6189}
6190
6191template<typename Derived>
John McCall5e77d762013-04-16 07:28:30 +00006192ExprResult
6193TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
6194 NestedNameSpecifierLoc QualifierLoc;
6195 if (E->getQualifierLoc()) {
6196 QualifierLoc
6197 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6198 if (!QualifierLoc)
6199 return ExprError();
6200 }
6201
6202 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
6203 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
6204 if (!PD)
6205 return ExprError();
6206
6207 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
6208 if (Base.isInvalid())
6209 return ExprError();
6210
6211 return new (SemaRef.getASTContext())
6212 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
6213 SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
6214 QualifierLoc, E->getMemberLoc());
6215}
6216
David Majnemerfad8f482013-10-15 09:33:02 +00006217template <typename Derived>
6218StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00006219 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006220 if (TryBlock.isInvalid())
6221 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006222
6223 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
David Majnemer7e755502013-10-15 09:30:14 +00006224 if (Handler.isInvalid())
6225 return StmtError();
6226
David Majnemerfad8f482013-10-15 09:33:02 +00006227 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
6228 Handler.get() == S->getHandler())
John Wiegley1c0675e2011-04-28 01:08:34 +00006229 return SemaRef.Owned(S);
6230
David Majnemerfad8f482013-10-15 09:33:02 +00006231 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(),
6232 TryBlock.take(), Handler.take());
John Wiegley1c0675e2011-04-28 01:08:34 +00006233}
6234
David Majnemerfad8f482013-10-15 09:33:02 +00006235template <typename Derived>
6236StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00006237 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006238 if (Block.isInvalid())
6239 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006240
David Majnemerfad8f482013-10-15 09:33:02 +00006241 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.take());
John Wiegley1c0675e2011-04-28 01:08:34 +00006242}
6243
David Majnemerfad8f482013-10-15 09:33:02 +00006244template <typename Derived>
6245StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
John Wiegley1c0675e2011-04-28 01:08:34 +00006246 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
David Majnemerfad8f482013-10-15 09:33:02 +00006247 if (FilterExpr.isInvalid())
6248 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006249
David Majnemer7e755502013-10-15 09:30:14 +00006250 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006251 if (Block.isInvalid())
6252 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006253
David Majnemerfad8f482013-10-15 09:33:02 +00006254 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.take(),
John Wiegley1c0675e2011-04-28 01:08:34 +00006255 Block.take());
6256}
6257
David Majnemerfad8f482013-10-15 09:33:02 +00006258template <typename Derived>
6259StmtResult TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
6260 if (isa<SEHFinallyStmt>(Handler))
John Wiegley1c0675e2011-04-28 01:08:34 +00006261 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
6262 else
6263 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
6264}
6265
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006266template<typename Derived>
6267StmtResult
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006268TreeTransform<Derived>::TransformOMPExecutableDirective(
6269 OMPExecutableDirective *D) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00006270
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006271 // Transform the clauses
Alexey Bataev758e55e2013-09-06 18:03:48 +00006272 llvm::SmallVector<OMPClause *, 16> TClauses;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006273 ArrayRef<OMPClause *> Clauses = D->clauses();
6274 TClauses.reserve(Clauses.size());
6275 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
6276 I != E; ++I) {
6277 if (*I) {
6278 OMPClause *Clause = getDerived().TransformOMPClause(*I);
Alexey Bataev758e55e2013-09-06 18:03:48 +00006279 if (!Clause) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006280 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00006281 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006282 TClauses.push_back(Clause);
6283 }
6284 else {
6285 TClauses.push_back(0);
6286 }
6287 }
Alexey Bataev758e55e2013-09-06 18:03:48 +00006288 if (!D->getAssociatedStmt()) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006289 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00006290 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006291 StmtResult AssociatedStmt =
6292 getDerived().TransformStmt(D->getAssociatedStmt());
Alexey Bataev758e55e2013-09-06 18:03:48 +00006293 if (AssociatedStmt.isInvalid()) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006294 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00006295 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006296
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006297 return getDerived().RebuildOMPExecutableDirective(D->getDirectiveKind(),
6298 TClauses,
6299 AssociatedStmt.take(),
6300 D->getLocStart(),
6301 D->getLocEnd());
6302}
6303
6304template<typename Derived>
6305StmtResult
6306TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
6307 DeclarationNameInfo DirName;
Alexey Bataev3d76e772014-03-07 04:01:56 +00006308 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, 0);
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006309 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6310 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6311 return Res;
6312}
6313
6314template<typename Derived>
6315StmtResult
6316TreeTransform<Derived>::TransformOMPSimdDirective(OMPSimdDirective *D) {
6317 DeclarationNameInfo DirName;
Alexey Bataev96d15102014-03-07 04:16:48 +00006318 getDerived().getSema().StartOpenMPDSABlock(OMPD_simd, DirName, 0);
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006319 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6320 getDerived().getSema().EndOpenMPDSABlock(Res.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00006321 return Res;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006322}
6323
6324template<typename Derived>
6325OMPClause *
Alexey Bataevaadd52e2014-02-13 05:29:23 +00006326TreeTransform<Derived>::TransformOMPIfClause(OMPIfClause *C) {
Alexey Bataevaf7849e2014-03-05 06:45:14 +00006327 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
6328 if (Cond.isInvalid())
6329 return 0;
6330 return getDerived().RebuildOMPIfClause(Cond.take(), C->getLocStart(),
Alexey Bataevaadd52e2014-02-13 05:29:23 +00006331 C->getLParenLoc(), C->getLocEnd());
6332}
6333
6334template<typename Derived>
6335OMPClause *
Alexey Bataev568a8332014-03-06 06:15:19 +00006336TreeTransform<Derived>::TransformOMPNumThreadsClause(OMPNumThreadsClause *C) {
6337 ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads());
6338 if (NumThreads.isInvalid())
6339 return 0;
6340 return getDerived().RebuildOMPNumThreadsClause(NumThreads.take(),
6341 C->getLocStart(),
6342 C->getLParenLoc(),
6343 C->getLocEnd());
6344}
6345
6346template<typename Derived>
6347OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006348TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
6349 return getDerived().RebuildOMPDefaultClause(C->getDefaultKind(),
6350 C->getDefaultKindKwLoc(),
6351 C->getLocStart(),
6352 C->getLParenLoc(),
6353 C->getLocEnd());
6354}
6355
6356template<typename Derived>
6357OMPClause *
6358TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00006359 llvm::SmallVector<Expr *, 16> Vars;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006360 Vars.reserve(C->varlist_size());
Aaron Ballman2205d2a2014-03-14 15:55:35 +00006361 for (auto *I : C->varlists()) {
6362 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(I));
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006363 if (EVar.isInvalid())
6364 return 0;
6365 Vars.push_back(EVar.take());
6366 }
6367 return getDerived().RebuildOMPPrivateClause(Vars,
6368 C->getLocStart(),
6369 C->getLParenLoc(),
6370 C->getLocEnd());
6371}
6372
Alexey Bataev758e55e2013-09-06 18:03:48 +00006373template<typename Derived>
6374OMPClause *
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006375TreeTransform<Derived>::TransformOMPFirstprivateClause(
6376 OMPFirstprivateClause *C) {
6377 llvm::SmallVector<Expr *, 16> Vars;
6378 Vars.reserve(C->varlist_size());
Aaron Ballman2205d2a2014-03-14 15:55:35 +00006379 for (auto *I : C->varlists()) {
6380 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(I));
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006381 if (EVar.isInvalid())
6382 return 0;
6383 Vars.push_back(EVar.take());
6384 }
6385 return getDerived().RebuildOMPFirstprivateClause(Vars,
6386 C->getLocStart(),
6387 C->getLParenLoc(),
6388 C->getLocEnd());
6389}
6390
6391template<typename Derived>
6392OMPClause *
Alexey Bataev758e55e2013-09-06 18:03:48 +00006393TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
6394 llvm::SmallVector<Expr *, 16> Vars;
6395 Vars.reserve(C->varlist_size());
Aaron Ballman2205d2a2014-03-14 15:55:35 +00006396 for (auto *I : C->varlists()) {
6397 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(I));
Alexey Bataev758e55e2013-09-06 18:03:48 +00006398 if (EVar.isInvalid())
6399 return 0;
6400 Vars.push_back(EVar.take());
6401 }
6402 return getDerived().RebuildOMPSharedClause(Vars,
6403 C->getLocStart(),
6404 C->getLParenLoc(),
6405 C->getLocEnd());
6406}
6407
Douglas Gregorebe10102009-08-20 07:17:43 +00006408//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00006409// Expression transformation
6410//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00006411template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006412ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006413TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006414 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006415}
Mike Stump11289f42009-09-09 15:08:12 +00006416
6417template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006418ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006419TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregorea972d32011-02-28 21:54:11 +00006420 NestedNameSpecifierLoc QualifierLoc;
6421 if (E->getQualifierLoc()) {
6422 QualifierLoc
6423 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6424 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00006425 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00006426 }
John McCallce546572009-12-08 09:08:17 +00006427
6428 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006429 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6430 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006431 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00006432 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006433
John McCall815039a2010-08-17 21:27:17 +00006434 DeclarationNameInfo NameInfo = E->getNameInfo();
6435 if (NameInfo.getName()) {
6436 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6437 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00006438 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00006439 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006440
6441 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00006442 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00006443 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006444 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00006445 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00006446
6447 // Mark it referenced in the new context regardless.
6448 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00006449 SemaRef.MarkDeclRefReferenced(E);
John McCallce546572009-12-08 09:08:17 +00006450
John McCallc3007a22010-10-26 07:05:15 +00006451 return SemaRef.Owned(E);
Douglas Gregor4bd90e52009-10-23 18:54:35 +00006452 }
John McCallce546572009-12-08 09:08:17 +00006453
6454 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCallb3774b52010-08-19 23:49:38 +00006455 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00006456 TemplateArgs = &TransArgs;
6457 TransArgs.setLAngleLoc(E->getLAngleLoc());
6458 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006459 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6460 E->getNumTemplateArgs(),
6461 TransArgs))
6462 return ExprError();
John McCallce546572009-12-08 09:08:17 +00006463 }
6464
Chad Rosier1dcde962012-08-08 18:46:20 +00006465 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregorea972d32011-02-28 21:54:11 +00006466 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00006467}
Mike Stump11289f42009-09-09 15:08:12 +00006468
Douglas Gregora16548e2009-08-11 05:31:07 +00006469template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006470ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006471TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00006472 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006473}
Mike Stump11289f42009-09-09 15:08:12 +00006474
Douglas Gregora16548e2009-08-11 05:31:07 +00006475template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006476ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006477TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00006478 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006479}
Mike Stump11289f42009-09-09 15:08:12 +00006480
Douglas Gregora16548e2009-08-11 05:31:07 +00006481template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006482ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006483TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00006484 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006485}
Mike Stump11289f42009-09-09 15:08:12 +00006486
Douglas Gregora16548e2009-08-11 05:31:07 +00006487template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006488ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006489TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00006490 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006491}
Mike Stump11289f42009-09-09 15:08:12 +00006492
Douglas Gregora16548e2009-08-11 05:31:07 +00006493template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006494ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006495TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00006496 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006497}
6498
6499template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006500ExprResult
Richard Smithc67fdd42012-03-07 08:35:16 +00006501TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
Argyrios Kyrtzidis25049092013-04-09 01:17:02 +00006502 if (FunctionDecl *FD = E->getDirectCallee())
6503 SemaRef.MarkFunctionReferenced(E->getLocStart(), FD);
Richard Smithc67fdd42012-03-07 08:35:16 +00006504 return SemaRef.MaybeBindToTemporary(E);
6505}
6506
6507template<typename Derived>
6508ExprResult
Peter Collingbourne91147592011-04-15 00:35:48 +00006509TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
6510 ExprResult ControllingExpr =
6511 getDerived().TransformExpr(E->getControllingExpr());
6512 if (ControllingExpr.isInvalid())
6513 return ExprError();
6514
Chris Lattner01cf8db2011-07-20 06:58:45 +00006515 SmallVector<Expr *, 4> AssocExprs;
6516 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbourne91147592011-04-15 00:35:48 +00006517 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
6518 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
6519 if (TS) {
6520 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
6521 if (!AssocType)
6522 return ExprError();
6523 AssocTypes.push_back(AssocType);
6524 } else {
6525 AssocTypes.push_back(0);
6526 }
6527
6528 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
6529 if (AssocExpr.isInvalid())
6530 return ExprError();
6531 AssocExprs.push_back(AssocExpr.release());
6532 }
6533
6534 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
6535 E->getDefaultLoc(),
6536 E->getRParenLoc(),
6537 ControllingExpr.release(),
Dmitri Gribenko82360372013-05-10 13:06:58 +00006538 AssocTypes,
6539 AssocExprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00006540}
6541
6542template<typename Derived>
6543ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006544TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006545 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006546 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006547 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006548
Douglas Gregora16548e2009-08-11 05:31:07 +00006549 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006550 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006551
John McCallb268a282010-08-23 23:25:46 +00006552 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006553 E->getRParen());
6554}
6555
Richard Smithdb2630f2012-10-21 03:28:35 +00006556/// \brief The operand of a unary address-of operator has special rules: it's
6557/// allowed to refer to a non-static member of a class even if there's no 'this'
6558/// object available.
6559template<typename Derived>
6560ExprResult
6561TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
6562 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
6563 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true);
6564 else
6565 return getDerived().TransformExpr(E);
6566}
6567
Mike Stump11289f42009-09-09 15:08:12 +00006568template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006569ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006570TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smitheebe125f2013-05-21 23:29:46 +00006571 ExprResult SubExpr;
6572 if (E->getOpcode() == UO_AddrOf)
6573 SubExpr = TransformAddressOfOperand(E->getSubExpr());
6574 else
6575 SubExpr = TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006576 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006577 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006578
Douglas Gregora16548e2009-08-11 05:31:07 +00006579 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006580 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006581
Douglas Gregora16548e2009-08-11 05:31:07 +00006582 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
6583 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00006584 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006585}
Mike Stump11289f42009-09-09 15:08:12 +00006586
Douglas Gregora16548e2009-08-11 05:31:07 +00006587template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006588ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00006589TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
6590 // Transform the type.
6591 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
6592 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00006593 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006594
Douglas Gregor882211c2010-04-28 22:16:22 +00006595 // Transform all of the components into components similar to what the
6596 // parser uses.
Chad Rosier1dcde962012-08-08 18:46:20 +00006597 // FIXME: It would be slightly more efficient in the non-dependent case to
6598 // just map FieldDecls, rather than requiring the rebuilder to look for
6599 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00006600 // template code that we don't care.
6601 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00006602 typedef Sema::OffsetOfComponent Component;
Douglas Gregor882211c2010-04-28 22:16:22 +00006603 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner01cf8db2011-07-20 06:58:45 +00006604 SmallVector<Component, 4> Components;
Douglas Gregor882211c2010-04-28 22:16:22 +00006605 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
6606 const Node &ON = E->getComponent(I);
6607 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00006608 Comp.isBrackets = true;
Abramo Bagnara6b6f0512011-03-12 09:45:03 +00006609 Comp.LocStart = ON.getSourceRange().getBegin();
6610 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor882211c2010-04-28 22:16:22 +00006611 switch (ON.getKind()) {
6612 case Node::Array: {
6613 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00006614 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00006615 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006616 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006617
Douglas Gregor882211c2010-04-28 22:16:22 +00006618 ExprChanged = ExprChanged || Index.get() != FromIndex;
6619 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00006620 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00006621 break;
6622 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006623
Douglas Gregor882211c2010-04-28 22:16:22 +00006624 case Node::Field:
6625 case Node::Identifier:
6626 Comp.isBrackets = false;
6627 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00006628 if (!Comp.U.IdentInfo)
6629 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00006630
Douglas Gregor882211c2010-04-28 22:16:22 +00006631 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006632
Douglas Gregord1702062010-04-29 00:18:15 +00006633 case Node::Base:
6634 // Will be recomputed during the rebuild.
6635 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00006636 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006637
Douglas Gregor882211c2010-04-28 22:16:22 +00006638 Components.push_back(Comp);
6639 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006640
Douglas Gregor882211c2010-04-28 22:16:22 +00006641 // If nothing changed, retain the existing expression.
6642 if (!getDerived().AlwaysRebuild() &&
6643 Type == E->getTypeSourceInfo() &&
6644 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00006645 return SemaRef.Owned(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00006646
Douglas Gregor882211c2010-04-28 22:16:22 +00006647 // Build a new offsetof expression.
6648 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
6649 Components.data(), Components.size(),
6650 E->getRParenLoc());
6651}
6652
6653template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006654ExprResult
John McCall8d69a212010-11-15 23:31:06 +00006655TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
6656 assert(getDerived().AlreadyTransformed(E->getType()) &&
6657 "opaque value expression requires transformation");
6658 return SemaRef.Owned(E);
6659}
6660
6661template<typename Derived>
6662ExprResult
John McCallfe96e0b2011-11-06 09:01:30 +00006663TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCalle9290822011-11-30 04:42:31 +00006664 // Rebuild the syntactic form. The original syntactic form has
6665 // opaque-value expressions in it, so strip those away and rebuild
6666 // the result. This is a really awful way of doing this, but the
6667 // better solution (rebuilding the semantic expressions and
6668 // rebinding OVEs as necessary) doesn't work; we'd need
6669 // TreeTransform to not strip away implicit conversions.
6670 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
6671 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCallfe96e0b2011-11-06 09:01:30 +00006672 if (result.isInvalid()) return ExprError();
6673
6674 // If that gives us a pseudo-object result back, the pseudo-object
6675 // expression must have been an lvalue-to-rvalue conversion which we
6676 // should reapply.
6677 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
6678 result = SemaRef.checkPseudoObjectRValue(result.take());
6679
6680 return result;
6681}
6682
6683template<typename Derived>
6684ExprResult
Peter Collingbournee190dee2011-03-11 19:24:49 +00006685TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
6686 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006687 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00006688 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00006689
John McCallbcd03502009-12-07 02:54:59 +00006690 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00006691 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00006692 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006693
John McCall4c98fd82009-11-04 07:28:41 +00006694 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCallc3007a22010-10-26 07:05:15 +00006695 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006696
Peter Collingbournee190dee2011-03-11 19:24:49 +00006697 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
6698 E->getKind(),
6699 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00006700 }
Mike Stump11289f42009-09-09 15:08:12 +00006701
Eli Friedmane4f22df2012-02-29 04:03:55 +00006702 // C++0x [expr.sizeof]p1:
6703 // The operand is either an expression, which is an unevaluated operand
6704 // [...]
Eli Friedman15681d62012-09-26 04:34:21 +00006705 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
6706 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00006707
Eli Friedmane4f22df2012-02-29 04:03:55 +00006708 ExprResult SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
6709 if (SubExpr.isInvalid())
6710 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006711
Eli Friedmane4f22df2012-02-29 04:03:55 +00006712 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
6713 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006714
Peter Collingbournee190dee2011-03-11 19:24:49 +00006715 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
6716 E->getOperatorLoc(),
6717 E->getKind(),
6718 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00006719}
Mike Stump11289f42009-09-09 15:08:12 +00006720
Douglas Gregora16548e2009-08-11 05:31:07 +00006721template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006722ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006723TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006724 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006725 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006726 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006727
John McCalldadc5752010-08-24 06:29:42 +00006728 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006729 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006730 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006731
6732
Douglas Gregora16548e2009-08-11 05:31:07 +00006733 if (!getDerived().AlwaysRebuild() &&
6734 LHS.get() == E->getLHS() &&
6735 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00006736 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006737
John McCallb268a282010-08-23 23:25:46 +00006738 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006739 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00006740 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006741 E->getRBracketLoc());
6742}
Mike Stump11289f42009-09-09 15:08:12 +00006743
6744template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006745ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006746TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006747 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00006748 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00006749 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006750 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006751
6752 // Transform arguments.
6753 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006754 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00006755 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00006756 &ArgChanged))
6757 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006758
Douglas Gregora16548e2009-08-11 05:31:07 +00006759 if (!getDerived().AlwaysRebuild() &&
6760 Callee.get() == E->getCallee() &&
6761 !ArgChanged)
Dmitri Gribenko76bb5cabfa2012-09-10 21:20:09 +00006762 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00006763
Douglas Gregora16548e2009-08-11 05:31:07 +00006764 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00006765 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00006766 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00006767 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006768 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00006769 E->getRParenLoc());
6770}
Mike Stump11289f42009-09-09 15:08:12 +00006771
6772template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006773ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006774TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006775 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00006776 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006777 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006778
Douglas Gregorea972d32011-02-28 21:54:11 +00006779 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorf405d7e2009-08-31 23:41:50 +00006780 if (E->hasQualifier()) {
Douglas Gregorea972d32011-02-28 21:54:11 +00006781 QualifierLoc
6782 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00006783
Douglas Gregorea972d32011-02-28 21:54:11 +00006784 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00006785 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00006786 }
Abramo Bagnara7945c982012-01-27 09:46:47 +00006787 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00006788
Eli Friedman2cfcef62009-12-04 06:40:45 +00006789 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006790 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
6791 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006792 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00006793 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006794
John McCall16df1e52010-03-30 21:47:33 +00006795 NamedDecl *FoundDecl = E->getFoundDecl();
6796 if (FoundDecl == E->getMemberDecl()) {
6797 FoundDecl = Member;
6798 } else {
6799 FoundDecl = cast_or_null<NamedDecl>(
6800 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
6801 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00006802 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00006803 }
6804
Douglas Gregora16548e2009-08-11 05:31:07 +00006805 if (!getDerived().AlwaysRebuild() &&
6806 Base.get() == E->getBase() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00006807 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00006808 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00006809 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00006810 !E->hasExplicitTemplateArgs()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006811
Anders Carlsson9c45ad72009-12-22 05:24:09 +00006812 // Mark it referenced in the new context regardless.
6813 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00006814 SemaRef.MarkMemberReferenced(E);
6815
John McCallc3007a22010-10-26 07:05:15 +00006816 return SemaRef.Owned(E);
Anders Carlsson9c45ad72009-12-22 05:24:09 +00006817 }
Douglas Gregora16548e2009-08-11 05:31:07 +00006818
John McCall6b51f282009-11-23 01:53:49 +00006819 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00006820 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00006821 TransArgs.setLAngleLoc(E->getLAngleLoc());
6822 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006823 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6824 E->getNumTemplateArgs(),
6825 TransArgs))
6826 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00006827 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006828
Douglas Gregora16548e2009-08-11 05:31:07 +00006829 // FIXME: Bogus source location for the operator
6830 SourceLocation FakeOperatorLoc
6831 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
6832
John McCall38836f02010-01-15 08:34:02 +00006833 // FIXME: to do this check properly, we will need to preserve the
6834 // first-qualifier-in-scope here, just in case we had a dependent
6835 // base (and therefore couldn't do the check) and a
6836 // nested-name-qualifier (and therefore could do the lookup).
6837 NamedDecl *FirstQualifierInScope = 0;
6838
John McCallb268a282010-08-23 23:25:46 +00006839 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00006840 E->isArrow(),
Douglas Gregorea972d32011-02-28 21:54:11 +00006841 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00006842 TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006843 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00006844 Member,
John McCall16df1e52010-03-30 21:47:33 +00006845 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00006846 (E->hasExplicitTemplateArgs()
John McCall6b51f282009-11-23 01:53:49 +00006847 ? &TransArgs : 0),
John McCall38836f02010-01-15 08:34:02 +00006848 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00006849}
Mike Stump11289f42009-09-09 15:08:12 +00006850
Douglas Gregora16548e2009-08-11 05:31:07 +00006851template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006852ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006853TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00006854 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006855 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006856 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006857
John McCalldadc5752010-08-24 06:29:42 +00006858 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006859 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006860 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006861
Douglas Gregora16548e2009-08-11 05:31:07 +00006862 if (!getDerived().AlwaysRebuild() &&
6863 LHS.get() == E->getLHS() &&
6864 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00006865 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006866
Lang Hames5de91cc2012-10-02 04:45:10 +00006867 Sema::FPContractStateRAII FPContractState(getSema());
6868 getSema().FPFeatures.fp_contract = E->isFPContractable();
6869
Douglas Gregora16548e2009-08-11 05:31:07 +00006870 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00006871 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006872}
6873
Mike Stump11289f42009-09-09 15:08:12 +00006874template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006875ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006876TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00006877 CompoundAssignOperator *E) {
6878 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006879}
Mike Stump11289f42009-09-09 15:08:12 +00006880
Douglas Gregora16548e2009-08-11 05:31:07 +00006881template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00006882ExprResult TreeTransform<Derived>::
6883TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
6884 // Just rebuild the common and RHS expressions and see whether we
6885 // get any changes.
6886
6887 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
6888 if (commonExpr.isInvalid())
6889 return ExprError();
6890
6891 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
6892 if (rhs.isInvalid())
6893 return ExprError();
6894
6895 if (!getDerived().AlwaysRebuild() &&
6896 commonExpr.get() == e->getCommon() &&
6897 rhs.get() == e->getFalseExpr())
6898 return SemaRef.Owned(e);
6899
6900 return getDerived().RebuildConditionalOperator(commonExpr.take(),
6901 e->getQuestionLoc(),
6902 0,
6903 e->getColonLoc(),
6904 rhs.get());
6905}
6906
6907template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006908ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006909TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00006910 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00006911 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006912 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006913
John McCalldadc5752010-08-24 06:29:42 +00006914 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006915 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006916 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006917
John McCalldadc5752010-08-24 06:29:42 +00006918 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006919 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006920 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006921
Douglas Gregora16548e2009-08-11 05:31:07 +00006922 if (!getDerived().AlwaysRebuild() &&
6923 Cond.get() == E->getCond() &&
6924 LHS.get() == E->getLHS() &&
6925 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00006926 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006927
John McCallb268a282010-08-23 23:25:46 +00006928 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00006929 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00006930 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00006931 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00006932 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006933}
Mike Stump11289f42009-09-09 15:08:12 +00006934
6935template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006936ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006937TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00006938 // Implicit casts are eliminated during transformation, since they
6939 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00006940 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006941}
Mike Stump11289f42009-09-09 15:08:12 +00006942
Douglas Gregora16548e2009-08-11 05:31:07 +00006943template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006944ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006945TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006946 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6947 if (!Type)
6948 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006949
John McCalldadc5752010-08-24 06:29:42 +00006950 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00006951 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006952 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006953 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006954
Douglas Gregora16548e2009-08-11 05:31:07 +00006955 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006956 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006957 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006958 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006959
John McCall97513962010-01-15 18:39:57 +00006960 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006961 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00006962 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006963 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006964}
Mike Stump11289f42009-09-09 15:08:12 +00006965
Douglas Gregora16548e2009-08-11 05:31:07 +00006966template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006967ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006968TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00006969 TypeSourceInfo *OldT = E->getTypeSourceInfo();
6970 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
6971 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00006972 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006973
John McCalldadc5752010-08-24 06:29:42 +00006974 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00006975 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006976 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006977
Douglas Gregora16548e2009-08-11 05:31:07 +00006978 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00006979 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006980 Init.get() == E->getInitializer())
Douglas Gregorc7f46f22011-12-10 00:23:21 +00006981 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006982
John McCall5d7aa7f2010-01-19 22:33:45 +00006983 // Note: the expression type doesn't necessarily match the
6984 // type-as-written, but that's okay, because it should always be
6985 // derivable from the initializer.
6986
John McCalle15bbff2010-01-18 19:35:47 +00006987 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00006988 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00006989 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006990}
Mike Stump11289f42009-09-09 15:08:12 +00006991
Douglas Gregora16548e2009-08-11 05:31:07 +00006992template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006993ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006994TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006995 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00006996 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006997 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006998
Douglas Gregora16548e2009-08-11 05:31:07 +00006999 if (!getDerived().AlwaysRebuild() &&
7000 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007001 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007002
Douglas Gregora16548e2009-08-11 05:31:07 +00007003 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00007004 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00007005 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00007006 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00007007 E->getAccessorLoc(),
7008 E->getAccessor());
7009}
Mike Stump11289f42009-09-09 15:08:12 +00007010
Douglas Gregora16548e2009-08-11 05:31:07 +00007011template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007012ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007013TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007014 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00007015
Benjamin Kramerf0623432012-08-23 22:51:59 +00007016 SmallVector<Expr*, 4> Inits;
Chad Rosier1dcde962012-08-08 18:46:20 +00007017 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00007018 Inits, &InitChanged))
7019 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007020
Douglas Gregora16548e2009-08-11 05:31:07 +00007021 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCallc3007a22010-10-26 07:05:15 +00007022 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007023
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007024 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00007025 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00007026}
Mike Stump11289f42009-09-09 15:08:12 +00007027
Douglas Gregora16548e2009-08-11 05:31:07 +00007028template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007029ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007030TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007031 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00007032
Douglas Gregorebe10102009-08-20 07:17:43 +00007033 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00007034 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00007035 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007036 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007037
Douglas Gregorebe10102009-08-20 07:17:43 +00007038 // transform the designators.
Benjamin Kramerf0623432012-08-23 22:51:59 +00007039 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregora16548e2009-08-11 05:31:07 +00007040 bool ExprChanged = false;
7041 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
7042 DEnd = E->designators_end();
7043 D != DEnd; ++D) {
7044 if (D->isFieldDesignator()) {
7045 Desig.AddDesignator(Designator::getField(D->getFieldName(),
7046 D->getDotLoc(),
7047 D->getFieldLoc()));
7048 continue;
7049 }
Mike Stump11289f42009-09-09 15:08:12 +00007050
Douglas Gregora16548e2009-08-11 05:31:07 +00007051 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00007052 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00007053 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007054 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007055
7056 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007057 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00007058
Douglas Gregora16548e2009-08-11 05:31:07 +00007059 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
7060 ArrayExprs.push_back(Index.release());
7061 continue;
7062 }
Mike Stump11289f42009-09-09 15:08:12 +00007063
Douglas Gregora16548e2009-08-11 05:31:07 +00007064 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00007065 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00007066 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
7067 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007068 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007069
John McCalldadc5752010-08-24 06:29:42 +00007070 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00007071 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007072 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007073
7074 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007075 End.get(),
7076 D->getLBracketLoc(),
7077 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00007078
Douglas Gregora16548e2009-08-11 05:31:07 +00007079 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
7080 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00007081
Douglas Gregora16548e2009-08-11 05:31:07 +00007082 ArrayExprs.push_back(Start.release());
7083 ArrayExprs.push_back(End.release());
7084 }
Mike Stump11289f42009-09-09 15:08:12 +00007085
Douglas Gregora16548e2009-08-11 05:31:07 +00007086 if (!getDerived().AlwaysRebuild() &&
7087 Init.get() == E->getInit() &&
7088 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00007089 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007090
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007091 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00007092 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00007093 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007094}
Mike Stump11289f42009-09-09 15:08:12 +00007095
Douglas Gregora16548e2009-08-11 05:31:07 +00007096template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007097ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007098TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007099 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00007100 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier1dcde962012-08-08 18:46:20 +00007101
Douglas Gregor3da3c062009-10-28 00:29:27 +00007102 // FIXME: Will we ever have proper type location here? Will we actually
7103 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00007104 QualType T = getDerived().TransformType(E->getType());
7105 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00007106 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007107
Douglas Gregora16548e2009-08-11 05:31:07 +00007108 if (!getDerived().AlwaysRebuild() &&
7109 T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00007110 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007111
Douglas Gregora16548e2009-08-11 05:31:07 +00007112 return getDerived().RebuildImplicitValueInitExpr(T);
7113}
Mike Stump11289f42009-09-09 15:08:12 +00007114
Douglas Gregora16548e2009-08-11 05:31:07 +00007115template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007116ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007117TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00007118 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
7119 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007120 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007121
John McCalldadc5752010-08-24 06:29:42 +00007122 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007123 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007124 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007125
Douglas Gregora16548e2009-08-11 05:31:07 +00007126 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00007127 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007128 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00007129 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007130
John McCallb268a282010-08-23 23:25:46 +00007131 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00007132 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007133}
7134
7135template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007136ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007137TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007138 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007139 SmallVector<Expr*, 4> Inits;
Douglas Gregora3efea12011-01-03 19:04:46 +00007140 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
7141 &ArgumentChanged))
7142 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007143
Douglas Gregora16548e2009-08-11 05:31:07 +00007144 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007145 Inits,
Douglas Gregora16548e2009-08-11 05:31:07 +00007146 E->getRParenLoc());
7147}
Mike Stump11289f42009-09-09 15:08:12 +00007148
Douglas Gregora16548e2009-08-11 05:31:07 +00007149/// \brief Transform an address-of-label expression.
7150///
7151/// By default, the transformation of an address-of-label expression always
7152/// rebuilds the expression, so that the label identifier can be resolved to
7153/// the corresponding label statement by semantic analysis.
7154template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007155ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007156TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +00007157 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
7158 E->getLabel());
7159 if (!LD)
7160 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007161
Douglas Gregora16548e2009-08-11 05:31:07 +00007162 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00007163 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +00007164}
Mike Stump11289f42009-09-09 15:08:12 +00007165
7166template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00007167ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007168TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalled7b2782012-04-06 18:20:53 +00007169 SemaRef.ActOnStartStmtExpr();
John McCalldadc5752010-08-24 06:29:42 +00007170 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00007171 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCalled7b2782012-04-06 18:20:53 +00007172 if (SubStmt.isInvalid()) {
7173 SemaRef.ActOnStmtExprError();
John McCallfaf5fb42010-08-26 23:41:50 +00007174 return ExprError();
John McCalled7b2782012-04-06 18:20:53 +00007175 }
Mike Stump11289f42009-09-09 15:08:12 +00007176
Douglas Gregora16548e2009-08-11 05:31:07 +00007177 if (!getDerived().AlwaysRebuild() &&
John McCalled7b2782012-04-06 18:20:53 +00007178 SubStmt.get() == E->getSubStmt()) {
7179 // Calling this an 'error' is unintuitive, but it does the right thing.
7180 SemaRef.ActOnStmtExprError();
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007181 return SemaRef.MaybeBindToTemporary(E);
John McCalled7b2782012-04-06 18:20:53 +00007182 }
Mike Stump11289f42009-09-09 15:08:12 +00007183
7184 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007185 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007186 E->getRParenLoc());
7187}
Mike Stump11289f42009-09-09 15:08:12 +00007188
Douglas Gregora16548e2009-08-11 05:31:07 +00007189template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007190ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007191TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007192 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00007193 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007194 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007195
John McCalldadc5752010-08-24 06:29:42 +00007196 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007197 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007198 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007199
John McCalldadc5752010-08-24 06:29:42 +00007200 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007201 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007202 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007203
Douglas Gregora16548e2009-08-11 05:31:07 +00007204 if (!getDerived().AlwaysRebuild() &&
7205 Cond.get() == E->getCond() &&
7206 LHS.get() == E->getLHS() &&
7207 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00007208 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007209
Douglas Gregora16548e2009-08-11 05:31:07 +00007210 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00007211 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007212 E->getRParenLoc());
7213}
Mike Stump11289f42009-09-09 15:08:12 +00007214
Douglas Gregora16548e2009-08-11 05:31:07 +00007215template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007216ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007217TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007218 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007219}
7220
7221template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007222ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007223TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007224 switch (E->getOperator()) {
7225 case OO_New:
7226 case OO_Delete:
7227 case OO_Array_New:
7228 case OO_Array_Delete:
7229 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier1dcde962012-08-08 18:46:20 +00007230
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007231 case OO_Call: {
7232 // This is a call to an object's operator().
7233 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
7234
7235 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00007236 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007237 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007238 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007239
7240 // FIXME: Poor location information
7241 SourceLocation FakeLParenLoc
7242 = SemaRef.PP.getLocForEndOfToken(
7243 static_cast<Expr *>(Object.get())->getLocEnd());
7244
7245 // Transform the call arguments.
Benjamin Kramerf0623432012-08-23 22:51:59 +00007246 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00007247 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregora3efea12011-01-03 19:04:46 +00007248 Args))
7249 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007250
John McCallb268a282010-08-23 23:25:46 +00007251 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007252 Args,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007253 E->getLocEnd());
7254 }
7255
7256#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
7257 case OO_##Name:
7258#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
7259#include "clang/Basic/OperatorKinds.def"
7260 case OO_Subscript:
7261 // Handled below.
7262 break;
7263
7264 case OO_Conditional:
7265 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007266
7267 case OO_None:
7268 case NUM_OVERLOADED_OPERATORS:
7269 llvm_unreachable("not an overloaded operator?");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007270 }
7271
John McCalldadc5752010-08-24 06:29:42 +00007272 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00007273 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007274 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007275
Richard Smithdb2630f2012-10-21 03:28:35 +00007276 ExprResult First;
7277 if (E->getOperator() == OO_Amp)
7278 First = getDerived().TransformAddressOfOperand(E->getArg(0));
7279 else
7280 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00007281 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007282 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007283
John McCalldadc5752010-08-24 06:29:42 +00007284 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00007285 if (E->getNumArgs() == 2) {
7286 Second = getDerived().TransformExpr(E->getArg(1));
7287 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007288 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007289 }
Mike Stump11289f42009-09-09 15:08:12 +00007290
Douglas Gregora16548e2009-08-11 05:31:07 +00007291 if (!getDerived().AlwaysRebuild() &&
7292 Callee.get() == E->getCallee() &&
7293 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00007294 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007295 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00007296
Lang Hames5de91cc2012-10-02 04:45:10 +00007297 Sema::FPContractStateRAII FPContractState(getSema());
7298 getSema().FPFeatures.fp_contract = E->isFPContractable();
7299
Douglas Gregora16548e2009-08-11 05:31:07 +00007300 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
7301 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00007302 Callee.get(),
7303 First.get(),
7304 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007305}
Mike Stump11289f42009-09-09 15:08:12 +00007306
Douglas Gregora16548e2009-08-11 05:31:07 +00007307template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007308ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007309TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
7310 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007311}
Mike Stump11289f42009-09-09 15:08:12 +00007312
Douglas Gregora16548e2009-08-11 05:31:07 +00007313template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007314ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +00007315TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
7316 // Transform the callee.
7317 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
7318 if (Callee.isInvalid())
7319 return ExprError();
7320
7321 // Transform exec config.
7322 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
7323 if (EC.isInvalid())
7324 return ExprError();
7325
7326 // Transform arguments.
7327 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007328 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00007329 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00007330 &ArgChanged))
7331 return ExprError();
7332
7333 if (!getDerived().AlwaysRebuild() &&
7334 Callee.get() == E->getCallee() &&
7335 !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007336 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbourne41f85462011-02-09 21:07:24 +00007337
7338 // FIXME: Wrong source location information for the '('.
7339 SourceLocation FakeLParenLoc
7340 = ((Expr *)Callee.get())->getSourceRange().getBegin();
7341 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007342 Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00007343 E->getRParenLoc(), EC.get());
7344}
7345
7346template<typename Derived>
7347ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007348TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007349 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7350 if (!Type)
7351 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007352
John McCalldadc5752010-08-24 06:29:42 +00007353 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00007354 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007355 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007356 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007357
Douglas Gregora16548e2009-08-11 05:31:07 +00007358 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007359 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007360 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00007361 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007362 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00007363 E->getStmtClass(),
Fariborz Jahanianf0738712013-02-22 22:02:53 +00007364 E->getAngleBrackets().getBegin(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007365 Type,
Fariborz Jahanianf0738712013-02-22 22:02:53 +00007366 E->getAngleBrackets().getEnd(),
7367 // FIXME. this should be '(' location
7368 E->getAngleBrackets().getEnd(),
John McCallb268a282010-08-23 23:25:46 +00007369 SubExpr.get(),
Abramo Bagnara9fb43862012-10-15 21:08:58 +00007370 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007371}
Mike Stump11289f42009-09-09 15:08:12 +00007372
Douglas Gregora16548e2009-08-11 05:31:07 +00007373template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007374ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007375TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
7376 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007377}
Mike Stump11289f42009-09-09 15:08:12 +00007378
7379template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007380ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007381TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
7382 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00007383}
7384
Douglas Gregora16548e2009-08-11 05:31:07 +00007385template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007386ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007387TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007388 CXXReinterpretCastExpr *E) {
7389 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007390}
Mike Stump11289f42009-09-09 15:08:12 +00007391
Douglas Gregora16548e2009-08-11 05:31:07 +00007392template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007393ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007394TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
7395 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007396}
Mike Stump11289f42009-09-09 15:08:12 +00007397
Douglas Gregora16548e2009-08-11 05:31:07 +00007398template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007399ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007400TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007401 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007402 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7403 if (!Type)
7404 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007405
John McCalldadc5752010-08-24 06:29:42 +00007406 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00007407 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007408 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007409 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007410
Douglas Gregora16548e2009-08-11 05:31:07 +00007411 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007412 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007413 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00007414 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007415
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007416 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Eli Friedman89fe0d52013-08-15 22:02:56 +00007417 E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007418 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007419 E->getRParenLoc());
7420}
Mike Stump11289f42009-09-09 15:08:12 +00007421
Douglas Gregora16548e2009-08-11 05:31:07 +00007422template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007423ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007424TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007425 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00007426 TypeSourceInfo *TInfo
7427 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7428 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007429 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007430
Douglas Gregora16548e2009-08-11 05:31:07 +00007431 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00007432 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00007433 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007434
Douglas Gregor9da64192010-04-26 22:37:10 +00007435 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7436 E->getLocStart(),
7437 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00007438 E->getLocEnd());
7439 }
Mike Stump11289f42009-09-09 15:08:12 +00007440
Eli Friedman456f0182012-01-20 01:26:23 +00007441 // We don't know whether the subexpression is potentially evaluated until
7442 // after we perform semantic analysis. We speculatively assume it is
7443 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregora16548e2009-08-11 05:31:07 +00007444 // potentially evaluated.
Eli Friedman15681d62012-09-26 04:34:21 +00007445 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
7446 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00007447
John McCalldadc5752010-08-24 06:29:42 +00007448 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00007449 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007450 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007451
Douglas Gregora16548e2009-08-11 05:31:07 +00007452 if (!getDerived().AlwaysRebuild() &&
7453 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00007454 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007455
Douglas Gregor9da64192010-04-26 22:37:10 +00007456 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7457 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00007458 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007459 E->getLocEnd());
7460}
7461
7462template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007463ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00007464TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
7465 if (E->isTypeOperand()) {
7466 TypeSourceInfo *TInfo
7467 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7468 if (!TInfo)
7469 return ExprError();
7470
7471 if (!getDerived().AlwaysRebuild() &&
7472 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00007473 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00007474
Douglas Gregor69735112011-03-06 17:40:41 +00007475 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet9f4f2072010-09-08 12:20:18 +00007476 E->getLocStart(),
7477 TInfo,
7478 E->getLocEnd());
7479 }
7480
Francois Pichet9f4f2072010-09-08 12:20:18 +00007481 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7482
7483 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
7484 if (SubExpr.isInvalid())
7485 return ExprError();
7486
7487 if (!getDerived().AlwaysRebuild() &&
7488 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00007489 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00007490
7491 return getDerived().RebuildCXXUuidofExpr(E->getType(),
7492 E->getLocStart(),
7493 SubExpr.get(),
7494 E->getLocEnd());
7495}
7496
7497template<typename Derived>
7498ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007499TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007500 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007501}
Mike Stump11289f42009-09-09 15:08:12 +00007502
Douglas Gregora16548e2009-08-11 05:31:07 +00007503template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007504ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007505TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007506 CXXNullPtrLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007507 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007508}
Mike Stump11289f42009-09-09 15:08:12 +00007509
Douglas Gregora16548e2009-08-11 05:31:07 +00007510template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007511ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007512TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Richard Smithc3d2ebb2013-06-07 02:33:37 +00007513 QualType T = getSema().getCurrentThisType();
Mike Stump11289f42009-09-09 15:08:12 +00007514
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00007515 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
7516 // Make sure that we capture 'this'.
7517 getSema().CheckCXXThisCapture(E->getLocStart());
John McCallc3007a22010-10-26 07:05:15 +00007518 return SemaRef.Owned(E);
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00007519 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007520
Douglas Gregorb15af892010-01-07 23:12:05 +00007521 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00007522}
Mike Stump11289f42009-09-09 15:08:12 +00007523
Douglas Gregora16548e2009-08-11 05:31:07 +00007524template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007525ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007526TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007527 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007528 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007529 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007530
Douglas Gregora16548e2009-08-11 05:31:07 +00007531 if (!getDerived().AlwaysRebuild() &&
7532 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00007533 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007534
Douglas Gregor53e191ed2011-07-06 22:04:06 +00007535 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
7536 E->isThrownVariableInScope());
Douglas Gregora16548e2009-08-11 05:31:07 +00007537}
Mike Stump11289f42009-09-09 15:08:12 +00007538
Douglas Gregora16548e2009-08-11 05:31:07 +00007539template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007540ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007541TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00007542 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007543 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
7544 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007545 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00007546 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007547
Chandler Carruth794da4c2010-02-08 06:42:49 +00007548 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007549 Param == E->getParam())
John McCallc3007a22010-10-26 07:05:15 +00007550 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007551
Douglas Gregor033f6752009-12-23 23:03:06 +00007552 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00007553}
Mike Stump11289f42009-09-09 15:08:12 +00007554
Douglas Gregora16548e2009-08-11 05:31:07 +00007555template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007556ExprResult
Richard Smith852c9db2013-04-20 22:23:05 +00007557TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
7558 FieldDecl *Field
7559 = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(),
7560 E->getField()));
7561 if (!Field)
7562 return ExprError();
7563
7564 if (!getDerived().AlwaysRebuild() && Field == E->getField())
7565 return SemaRef.Owned(E);
7566
7567 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
7568}
7569
7570template<typename Derived>
7571ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00007572TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
7573 CXXScalarValueInitExpr *E) {
7574 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7575 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007576 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007577
Douglas Gregora16548e2009-08-11 05:31:07 +00007578 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00007579 T == E->getTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00007580 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007581
Chad Rosier1dcde962012-08-08 18:46:20 +00007582 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregor2b88c112010-09-08 00:15:04 +00007583 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00007584 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007585}
Mike Stump11289f42009-09-09 15:08:12 +00007586
Douglas Gregora16548e2009-08-11 05:31:07 +00007587template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007588ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007589TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007590 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00007591 TypeSourceInfo *AllocTypeInfo
7592 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
7593 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007594 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007595
Douglas Gregora16548e2009-08-11 05:31:07 +00007596 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00007597 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00007598 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007599 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007600
Douglas Gregora16548e2009-08-11 05:31:07 +00007601 // Transform the placement arguments (if any).
7602 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007603 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier1dcde962012-08-08 18:46:20 +00007604 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregora3efea12011-01-03 19:04:46 +00007605 E->getNumPlacementArgs(), true,
7606 PlacementArgs, &ArgumentChanged))
Sebastian Redl6047f072012-02-16 12:22:20 +00007607 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007608
Sebastian Redl6047f072012-02-16 12:22:20 +00007609 // Transform the initializer (if any).
7610 Expr *OldInit = E->getInitializer();
7611 ExprResult NewInit;
7612 if (OldInit)
7613 NewInit = getDerived().TransformExpr(OldInit);
7614 if (NewInit.isInvalid())
7615 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007616
Sebastian Redl6047f072012-02-16 12:22:20 +00007617 // Transform new operator and delete operator.
Douglas Gregord2d9da02010-02-26 00:38:10 +00007618 FunctionDecl *OperatorNew = 0;
7619 if (E->getOperatorNew()) {
7620 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007621 getDerived().TransformDecl(E->getLocStart(),
7622 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00007623 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00007624 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00007625 }
7626
7627 FunctionDecl *OperatorDelete = 0;
7628 if (E->getOperatorDelete()) {
7629 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007630 getDerived().TransformDecl(E->getLocStart(),
7631 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00007632 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00007633 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00007634 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007635
Douglas Gregora16548e2009-08-11 05:31:07 +00007636 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00007637 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007638 ArraySize.get() == E->getArraySize() &&
Sebastian Redl6047f072012-02-16 12:22:20 +00007639 NewInit.get() == OldInit &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00007640 OperatorNew == E->getOperatorNew() &&
7641 OperatorDelete == E->getOperatorDelete() &&
7642 !ArgumentChanged) {
7643 // Mark any declarations we need as referenced.
7644 // FIXME: instantiation-specific.
Douglas Gregord2d9da02010-02-26 00:38:10 +00007645 if (OperatorNew)
Eli Friedmanfa0df832012-02-02 03:46:19 +00007646 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregord2d9da02010-02-26 00:38:10 +00007647 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00007648 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00007649
Sebastian Redl6047f072012-02-16 12:22:20 +00007650 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor72912fb2011-07-26 15:11:03 +00007651 QualType ElementType
7652 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
7653 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
7654 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
7655 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedmanfa0df832012-02-02 03:46:19 +00007656 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor72912fb2011-07-26 15:11:03 +00007657 }
7658 }
7659 }
Sebastian Redl6047f072012-02-16 12:22:20 +00007660
John McCallc3007a22010-10-26 07:05:15 +00007661 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00007662 }
Mike Stump11289f42009-09-09 15:08:12 +00007663
Douglas Gregor0744ef62010-09-07 21:49:58 +00007664 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00007665 if (!ArraySize.get()) {
7666 // If no array size was specified, but the new expression was
7667 // instantiated with an array type (e.g., "new T" where T is
7668 // instantiated with "int[4]"), extract the outer bound from the
7669 // array type as our array size. We do this with constant and
7670 // dependently-sized array types.
7671 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
7672 if (!ArrayT) {
7673 // Do nothing
7674 } else if (const ConstantArrayType *ConsArrayT
7675 = dyn_cast<ConstantArrayType>(ArrayT)) {
Chad Rosier1dcde962012-08-08 18:46:20 +00007676 ArraySize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00007677 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
Chad Rosier1dcde962012-08-08 18:46:20 +00007678 ConsArrayT->getSize(),
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00007679 SemaRef.Context.getSizeType(),
7680 /*FIXME:*/E->getLocStart()));
Douglas Gregor2e9c7952009-12-22 17:13:37 +00007681 AllocType = ConsArrayT->getElementType();
7682 } else if (const DependentSizedArrayType *DepArrayT
7683 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
7684 if (DepArrayT->getSizeExpr()) {
John McCallc3007a22010-10-26 07:05:15 +00007685 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00007686 AllocType = DepArrayT->getElementType();
7687 }
7688 }
7689 }
Sebastian Redl6047f072012-02-16 12:22:20 +00007690
Douglas Gregora16548e2009-08-11 05:31:07 +00007691 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
7692 E->isGlobalNew(),
7693 /*FIXME:*/E->getLocStart(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007694 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00007695 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00007696 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007697 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00007698 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00007699 ArraySize.get(),
Sebastian Redl6047f072012-02-16 12:22:20 +00007700 E->getDirectInitRange(),
7701 NewInit.take());
Douglas Gregora16548e2009-08-11 05:31:07 +00007702}
Mike Stump11289f42009-09-09 15:08:12 +00007703
Douglas Gregora16548e2009-08-11 05:31:07 +00007704template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007705ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007706TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007707 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00007708 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007709 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007710
Douglas Gregord2d9da02010-02-26 00:38:10 +00007711 // Transform the delete operator, if known.
7712 FunctionDecl *OperatorDelete = 0;
7713 if (E->getOperatorDelete()) {
7714 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007715 getDerived().TransformDecl(E->getLocStart(),
7716 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00007717 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00007718 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00007719 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007720
Douglas Gregora16548e2009-08-11 05:31:07 +00007721 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00007722 Operand.get() == E->getArgument() &&
7723 OperatorDelete == E->getOperatorDelete()) {
7724 // Mark any declarations we need as referenced.
7725 // FIXME: instantiation-specific.
7726 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00007727 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00007728
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00007729 if (!E->getArgument()->isTypeDependent()) {
7730 QualType Destroyed = SemaRef.Context.getBaseElementType(
7731 E->getDestroyedType());
7732 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
7733 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +00007734 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedmanfa0df832012-02-02 03:46:19 +00007735 SemaRef.LookupDestructor(Record));
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00007736 }
7737 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007738
John McCallc3007a22010-10-26 07:05:15 +00007739 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00007740 }
Mike Stump11289f42009-09-09 15:08:12 +00007741
Douglas Gregora16548e2009-08-11 05:31:07 +00007742 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
7743 E->isGlobalDelete(),
7744 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00007745 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007746}
Mike Stump11289f42009-09-09 15:08:12 +00007747
Douglas Gregora16548e2009-08-11 05:31:07 +00007748template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007749ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00007750TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007751 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007752 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00007753 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007754 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007755
John McCallba7bf592010-08-24 05:47:05 +00007756 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00007757 bool MayBePseudoDestructor = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00007758 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00007759 E->getOperatorLoc(),
7760 E->isArrow()? tok::arrow : tok::period,
7761 ObjectTypePtr,
7762 MayBePseudoDestructor);
7763 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007764 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007765
John McCallba7bf592010-08-24 05:47:05 +00007766 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +00007767 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
7768 if (QualifierLoc) {
7769 QualifierLoc
7770 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
7771 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +00007772 return ExprError();
7773 }
Douglas Gregora6ce6082011-02-25 18:19:59 +00007774 CXXScopeSpec SS;
7775 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00007776
Douglas Gregor678f90d2010-02-25 01:56:36 +00007777 PseudoDestructorTypeStorage Destroyed;
7778 if (E->getDestroyedTypeInfo()) {
7779 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00007780 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregor579c15f2011-03-02 18:32:08 +00007781 ObjectType, 0, SS);
Douglas Gregor678f90d2010-02-25 01:56:36 +00007782 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007783 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00007784 Destroyed = DestroyedTypeInfo;
Douglas Gregorf39a8dd2011-11-09 02:19:47 +00007785 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregor678f90d2010-02-25 01:56:36 +00007786 // We aren't likely to be able to resolve the identifier down to a type
7787 // now anyway, so just retain the identifier.
7788 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
7789 E->getDestroyedTypeLoc());
7790 } else {
7791 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +00007792 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00007793 *E->getDestroyedTypeIdentifier(),
7794 E->getDestroyedTypeLoc(),
7795 /*Scope=*/0,
7796 SS, ObjectTypePtr,
7797 false);
7798 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007799 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007800
Douglas Gregor678f90d2010-02-25 01:56:36 +00007801 Destroyed
7802 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
7803 E->getDestroyedTypeLoc());
7804 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007805
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007806 TypeSourceInfo *ScopeTypeInfo = 0;
7807 if (E->getScopeTypeInfo()) {
Douglas Gregora88c55b2013-03-08 21:25:01 +00007808 CXXScopeSpec EmptySS;
7809 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
7810 E->getScopeTypeInfo(), ObjectType, 0, EmptySS);
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007811 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007812 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00007813 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007814
John McCallb268a282010-08-23 23:25:46 +00007815 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00007816 E->getOperatorLoc(),
7817 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +00007818 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007819 ScopeTypeInfo,
7820 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00007821 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00007822 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00007823}
Mike Stump11289f42009-09-09 15:08:12 +00007824
Douglas Gregorad8a3362009-09-04 17:36:40 +00007825template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007826ExprResult
John McCalld14a8642009-11-21 08:51:07 +00007827TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007828 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00007829 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
7830 Sema::LookupOrdinaryName);
7831
7832 // Transform all the decls.
7833 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
7834 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007835 NamedDecl *InstD = static_cast<NamedDecl*>(
7836 getDerived().TransformDecl(Old->getNameLoc(),
7837 *I));
John McCall84d87672009-12-10 09:41:52 +00007838 if (!InstD) {
7839 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7840 // This can happen because of dependent hiding.
7841 if (isa<UsingShadowDecl>(*I))
7842 continue;
Serge Pavlov82605302013-09-04 04:50:29 +00007843 else {
7844 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00007845 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00007846 }
John McCall84d87672009-12-10 09:41:52 +00007847 }
John McCalle66edc12009-11-24 19:00:30 +00007848
7849 // Expand using declarations.
7850 if (isa<UsingDecl>(InstD)) {
7851 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +00007852 for (auto *I : UD->shadows())
7853 R.addDecl(I);
John McCalle66edc12009-11-24 19:00:30 +00007854 continue;
7855 }
7856
7857 R.addDecl(InstD);
7858 }
7859
7860 // Resolve a kind, but don't do any further analysis. If it's
7861 // ambiguous, the callee needs to deal with it.
7862 R.resolveKind();
7863
7864 // Rebuild the nested-name qualifier, if present.
7865 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00007866 if (Old->getQualifierLoc()) {
7867 NestedNameSpecifierLoc QualifierLoc
7868 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7869 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007870 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007871
Douglas Gregor0da1d432011-02-28 20:01:57 +00007872 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00007873 }
7874
Douglas Gregor9262f472010-04-27 18:19:34 +00007875 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00007876 CXXRecordDecl *NamingClass
7877 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
7878 Old->getNameLoc(),
7879 Old->getNamingClass()));
Serge Pavlov82605302013-09-04 04:50:29 +00007880 if (!NamingClass) {
7881 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00007882 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00007883 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007884
Douglas Gregorda7be082010-04-27 16:10:10 +00007885 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00007886 }
7887
Abramo Bagnara7945c982012-01-27 09:46:47 +00007888 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
7889
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00007890 // If we have neither explicit template arguments, nor the template keyword,
7891 // it's a normal declaration name.
7892 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
John McCalle66edc12009-11-24 19:00:30 +00007893 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
7894
7895 // If we have template arguments, rebuild them, then rebuild the
7896 // templateid expression.
7897 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola3dd531d2012-08-28 04:13:54 +00007898 if (Old->hasExplicitTemplateArgs() &&
7899 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregor62e06f22010-12-20 17:31:10 +00007900 Old->getNumTemplateArgs(),
Serge Pavlov82605302013-09-04 04:50:29 +00007901 TransArgs)) {
7902 R.clear();
Douglas Gregor62e06f22010-12-20 17:31:10 +00007903 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00007904 }
John McCalle66edc12009-11-24 19:00:30 +00007905
Abramo Bagnara7945c982012-01-27 09:46:47 +00007906 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00007907 Old->requiresADL(), &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00007908}
Mike Stump11289f42009-09-09 15:08:12 +00007909
Douglas Gregora16548e2009-08-11 05:31:07 +00007910template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007911ExprResult
Douglas Gregor29c42f22012-02-24 07:38:34 +00007912TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
7913 bool ArgChanged = false;
Dmitri Gribenkof8579502013-01-12 19:30:44 +00007914 SmallVector<TypeSourceInfo *, 4> Args;
Douglas Gregor29c42f22012-02-24 07:38:34 +00007915 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
7916 TypeSourceInfo *From = E->getArg(I);
7917 TypeLoc FromTL = From->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00007918 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
Douglas Gregor29c42f22012-02-24 07:38:34 +00007919 TypeLocBuilder TLB;
7920 TLB.reserve(FromTL.getFullDataSize());
7921 QualType To = getDerived().TransformType(TLB, FromTL);
7922 if (To.isNull())
7923 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007924
Douglas Gregor29c42f22012-02-24 07:38:34 +00007925 if (To == From->getType())
7926 Args.push_back(From);
7927 else {
7928 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7929 ArgChanged = true;
7930 }
7931 continue;
7932 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007933
Douglas Gregor29c42f22012-02-24 07:38:34 +00007934 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00007935
Douglas Gregor29c42f22012-02-24 07:38:34 +00007936 // We have a pack expansion. Instantiate it.
David Blaikie6adc78e2013-02-18 22:06:02 +00007937 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
Douglas Gregor29c42f22012-02-24 07:38:34 +00007938 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
7939 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
7940 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00007941
Douglas Gregor29c42f22012-02-24 07:38:34 +00007942 // Determine whether the set of unexpanded parameter packs can and should
7943 // be expanded.
7944 bool Expand = true;
7945 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00007946 Optional<unsigned> OrigNumExpansions =
7947 ExpansionTL.getTypePtr()->getNumExpansions();
7948 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor29c42f22012-02-24 07:38:34 +00007949 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
7950 PatternTL.getSourceRange(),
7951 Unexpanded,
7952 Expand, RetainExpansion,
7953 NumExpansions))
7954 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007955
Douglas Gregor29c42f22012-02-24 07:38:34 +00007956 if (!Expand) {
7957 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00007958 // transformation on the pack expansion, producing another pack
Douglas Gregor29c42f22012-02-24 07:38:34 +00007959 // expansion.
7960 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier1dcde962012-08-08 18:46:20 +00007961
Douglas Gregor29c42f22012-02-24 07:38:34 +00007962 TypeLocBuilder TLB;
7963 TLB.reserve(From->getTypeLoc().getFullDataSize());
7964
7965 QualType To = getDerived().TransformType(TLB, PatternTL);
7966 if (To.isNull())
7967 return ExprError();
7968
Chad Rosier1dcde962012-08-08 18:46:20 +00007969 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00007970 PatternTL.getSourceRange(),
7971 ExpansionTL.getEllipsisLoc(),
7972 NumExpansions);
7973 if (To.isNull())
7974 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007975
Douglas Gregor29c42f22012-02-24 07:38:34 +00007976 PackExpansionTypeLoc ToExpansionTL
7977 = TLB.push<PackExpansionTypeLoc>(To);
7978 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7979 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7980 continue;
7981 }
7982
7983 // Expand the pack expansion by substituting for each argument in the
7984 // pack(s).
7985 for (unsigned I = 0; I != *NumExpansions; ++I) {
7986 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
7987 TypeLocBuilder TLB;
7988 TLB.reserve(PatternTL.getFullDataSize());
7989 QualType To = getDerived().TransformType(TLB, PatternTL);
7990 if (To.isNull())
7991 return ExprError();
7992
Eli Friedman5e05c4a2013-07-19 21:49:32 +00007993 if (To->containsUnexpandedParameterPack()) {
7994 To = getDerived().RebuildPackExpansionType(To,
7995 PatternTL.getSourceRange(),
7996 ExpansionTL.getEllipsisLoc(),
7997 NumExpansions);
7998 if (To.isNull())
7999 return ExprError();
8000
8001 PackExpansionTypeLoc ToExpansionTL
8002 = TLB.push<PackExpansionTypeLoc>(To);
8003 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8004 }
8005
Douglas Gregor29c42f22012-02-24 07:38:34 +00008006 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8007 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008008
Douglas Gregor29c42f22012-02-24 07:38:34 +00008009 if (!RetainExpansion)
8010 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00008011
Douglas Gregor29c42f22012-02-24 07:38:34 +00008012 // If we're supposed to retain a pack expansion, do so by temporarily
8013 // forgetting the partially-substituted parameter pack.
8014 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
8015
8016 TypeLocBuilder TLB;
8017 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00008018
Douglas Gregor29c42f22012-02-24 07:38:34 +00008019 QualType To = getDerived().TransformType(TLB, PatternTL);
8020 if (To.isNull())
8021 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008022
8023 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00008024 PatternTL.getSourceRange(),
8025 ExpansionTL.getEllipsisLoc(),
8026 NumExpansions);
8027 if (To.isNull())
8028 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008029
Douglas Gregor29c42f22012-02-24 07:38:34 +00008030 PackExpansionTypeLoc ToExpansionTL
8031 = TLB.push<PackExpansionTypeLoc>(To);
8032 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8033 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8034 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008035
Douglas Gregor29c42f22012-02-24 07:38:34 +00008036 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8037 return SemaRef.Owned(E);
8038
8039 return getDerived().RebuildTypeTrait(E->getTrait(),
8040 E->getLocStart(),
8041 Args,
8042 E->getLocEnd());
8043}
8044
8045template<typename Derived>
8046ExprResult
John Wiegley6242b6a2011-04-28 00:16:57 +00008047TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
8048 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
8049 if (!T)
8050 return ExprError();
8051
8052 if (!getDerived().AlwaysRebuild() &&
8053 T == E->getQueriedTypeSourceInfo())
8054 return SemaRef.Owned(E);
8055
8056 ExprResult SubExpr;
8057 {
8058 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8059 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
8060 if (SubExpr.isInvalid())
8061 return ExprError();
8062
8063 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
8064 return SemaRef.Owned(E);
8065 }
8066
8067 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
8068 E->getLocStart(),
8069 T,
8070 SubExpr.get(),
8071 E->getLocEnd());
8072}
8073
8074template<typename Derived>
8075ExprResult
John Wiegleyf9f65842011-04-25 06:54:41 +00008076TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
8077 ExprResult SubExpr;
8078 {
8079 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8080 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
8081 if (SubExpr.isInvalid())
8082 return ExprError();
8083
8084 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
8085 return SemaRef.Owned(E);
8086 }
8087
8088 return getDerived().RebuildExpressionTrait(
8089 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
8090}
8091
8092template<typename Derived>
8093ExprResult
John McCall8cd78132009-11-19 22:55:06 +00008094TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008095 DependentScopeDeclRefExpr *E) {
Richard Smithdb2630f2012-10-21 03:28:35 +00008096 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand*/false);
8097}
8098
8099template<typename Derived>
8100ExprResult
8101TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
8102 DependentScopeDeclRefExpr *E,
8103 bool IsAddressOfOperand) {
Reid Kleckner916ac4d2013-10-15 18:38:02 +00008104 assert(E->getQualifierLoc());
Douglas Gregor3a43fd62011-02-25 20:49:16 +00008105 NestedNameSpecifierLoc QualifierLoc
8106 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
8107 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008108 return ExprError();
Abramo Bagnara7945c982012-01-27 09:46:47 +00008109 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00008110
John McCall31f82722010-11-12 08:19:04 +00008111 // TODO: If this is a conversion-function-id, verify that the
8112 // destination type name (if present) resolves the same way after
8113 // instantiation as it did in the local scope.
8114
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008115 DeclarationNameInfo NameInfo
8116 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
8117 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00008118 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008119
John McCalle66edc12009-11-24 19:00:30 +00008120 if (!E->hasExplicitTemplateArgs()) {
8121 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3a43fd62011-02-25 20:49:16 +00008122 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008123 // Note: it is sufficient to compare the Name component of NameInfo:
8124 // if name has not changed, DNLoc has not changed either.
8125 NameInfo.getName() == E->getDeclName())
John McCallc3007a22010-10-26 07:05:15 +00008126 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00008127
Douglas Gregor3a43fd62011-02-25 20:49:16 +00008128 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008129 TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008130 NameInfo,
Richard Smithdb2630f2012-10-21 03:28:35 +00008131 /*TemplateArgs*/ 0,
8132 IsAddressOfOperand);
Douglas Gregord019ff62009-10-22 17:20:55 +00008133 }
John McCall6b51f282009-11-23 01:53:49 +00008134
8135 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008136 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8137 E->getNumTemplateArgs(),
8138 TransArgs))
8139 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008140
Douglas Gregor3a43fd62011-02-25 20:49:16 +00008141 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008142 TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008143 NameInfo,
Richard Smithdb2630f2012-10-21 03:28:35 +00008144 &TransArgs,
8145 IsAddressOfOperand);
Douglas Gregora16548e2009-08-11 05:31:07 +00008146}
8147
8148template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008149ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008150TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithd59b8322012-12-19 01:39:02 +00008151 // CXXConstructExprs other than for list-initialization and
8152 // CXXTemporaryObjectExpr are always implicit, so when we have
8153 // a 1-argument construction we just transform that argument.
Richard Smithdd2ca572012-11-26 08:32:48 +00008154 if ((E->getNumArgs() == 1 ||
8155 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithd59b8322012-12-19 01:39:02 +00008156 (!getDerived().DropCallArgument(E->getArg(0))) &&
8157 !E->isListInitialization())
Douglas Gregordb56b912010-02-03 03:01:57 +00008158 return getDerived().TransformExpr(E->getArg(0));
8159
Douglas Gregora16548e2009-08-11 05:31:07 +00008160 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
8161
8162 QualType T = getDerived().TransformType(E->getType());
8163 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00008164 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008165
8166 CXXConstructorDecl *Constructor
8167 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008168 getDerived().TransformDecl(E->getLocStart(),
8169 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008170 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00008171 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008172
Douglas Gregora16548e2009-08-11 05:31:07 +00008173 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008174 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00008175 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00008176 &ArgumentChanged))
8177 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008178
Douglas Gregora16548e2009-08-11 05:31:07 +00008179 if (!getDerived().AlwaysRebuild() &&
8180 T == E->getType() &&
8181 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00008182 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00008183 // Mark the constructor as referenced.
8184 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00008185 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00008186 return SemaRef.Owned(E);
Douglas Gregorde550352010-02-26 00:01:57 +00008187 }
Mike Stump11289f42009-09-09 15:08:12 +00008188
Douglas Gregordb121ba2009-12-14 16:27:04 +00008189 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
8190 Constructor, E->isElidable(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008191 Args,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00008192 E->hadMultipleCandidates(),
Richard Smithd59b8322012-12-19 01:39:02 +00008193 E->isListInitialization(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00008194 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00008195 E->getConstructionKind(),
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00008196 E->getParenOrBraceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00008197}
Mike Stump11289f42009-09-09 15:08:12 +00008198
Douglas Gregora16548e2009-08-11 05:31:07 +00008199/// \brief Transform a C++ temporary-binding expression.
8200///
Douglas Gregor363b1512009-12-24 18:51:59 +00008201/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
8202/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00008203template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008204ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008205TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00008206 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008207}
Mike Stump11289f42009-09-09 15:08:12 +00008208
John McCall5d413782010-12-06 08:20:24 +00008209/// \brief Transform a C++ expression that contains cleanups that should
8210/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +00008211///
John McCall5d413782010-12-06 08:20:24 +00008212/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +00008213/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00008214template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008215ExprResult
John McCall5d413782010-12-06 08:20:24 +00008216TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00008217 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008218}
Mike Stump11289f42009-09-09 15:08:12 +00008219
Douglas Gregora16548e2009-08-11 05:31:07 +00008220template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008221ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008222TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00008223 CXXTemporaryObjectExpr *E) {
8224 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8225 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00008226 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008227
Douglas Gregora16548e2009-08-11 05:31:07 +00008228 CXXConstructorDecl *Constructor
8229 = cast_or_null<CXXConstructorDecl>(
Chad Rosier1dcde962012-08-08 18:46:20 +00008230 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008231 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008232 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00008233 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008234
Douglas Gregora16548e2009-08-11 05:31:07 +00008235 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008236 SmallVector<Expr*, 8> Args;
Douglas Gregora16548e2009-08-11 05:31:07 +00008237 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +00008238 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00008239 &ArgumentChanged))
8240 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008241
Douglas Gregora16548e2009-08-11 05:31:07 +00008242 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00008243 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008244 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00008245 !ArgumentChanged) {
8246 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00008247 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00008248 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00008249 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008250
Richard Smithd59b8322012-12-19 01:39:02 +00008251 // FIXME: Pass in E->isListInitialization().
Douglas Gregor2b88c112010-09-08 00:15:04 +00008252 return getDerived().RebuildCXXTemporaryObjectExpr(T,
8253 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008254 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00008255 E->getLocEnd());
8256}
Mike Stump11289f42009-09-09 15:08:12 +00008257
Douglas Gregora16548e2009-08-11 05:31:07 +00008258template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008259ExprResult
Douglas Gregore31e6062012-02-07 10:09:13 +00008260TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008261
8262 // Transform any init-capture expressions before entering the scope of the
8263 // lambda body, because they are not semantically within that scope.
8264 SmallVector<InitCaptureInfoTy, 8> InitCaptureExprsAndTypes;
8265 InitCaptureExprsAndTypes.resize(E->explicit_capture_end() -
8266 E->explicit_capture_begin());
8267
8268 for (LambdaExpr::capture_iterator C = E->capture_begin(),
8269 CEnd = E->capture_end();
8270 C != CEnd; ++C) {
8271 if (!C->isInitCapture())
8272 continue;
8273 EnterExpressionEvaluationContext EEEC(getSema(),
8274 Sema::PotentiallyEvaluated);
8275 ExprResult NewExprInitResult = getDerived().TransformInitializer(
8276 C->getCapturedVar()->getInit(),
8277 C->getCapturedVar()->getInitStyle() == VarDecl::CallInit);
8278
8279 if (NewExprInitResult.isInvalid())
8280 return ExprError();
8281 Expr *NewExprInit = NewExprInitResult.get();
8282
8283 VarDecl *OldVD = C->getCapturedVar();
8284 QualType NewInitCaptureType =
8285 getSema().performLambdaInitCaptureInitialization(C->getLocation(),
8286 OldVD->getType()->isReferenceType(), OldVD->getIdentifier(),
8287 NewExprInit);
8288 NewExprInitResult = NewExprInit;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008289 InitCaptureExprsAndTypes[C - E->capture_begin()] =
8290 std::make_pair(NewExprInitResult, NewInitCaptureType);
8291
8292 }
8293
Faisal Vali524ca282013-11-12 01:40:44 +00008294 LambdaScopeInfo *LSI = getSema().PushLambdaScope();
Faisal Vali2cba1332013-10-23 06:44:28 +00008295 // Transform the template parameters, and add them to the current
8296 // instantiation scope. The null case is handled correctly.
8297 LSI->GLTemplateParameterList = getDerived().TransformTemplateParameterList(
8298 E->getTemplateParameterList());
8299
8300 // Check to see if the TypeSourceInfo of the call operator needs to
8301 // be transformed, and if so do the transformation in the
8302 // CurrentInstantiationScope.
8303
8304 TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo();
8305 FunctionProtoTypeLoc OldCallOpFPTL =
8306 OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>();
8307 TypeSourceInfo *NewCallOpTSI = 0;
8308
8309 const bool CallOpWasAlreadyTransformed =
8310 getDerived().AlreadyTransformed(OldCallOpTSI->getType());
8311
8312 // Use the Old Call Operator's TypeSourceInfo if it is already transformed.
8313 if (CallOpWasAlreadyTransformed)
8314 NewCallOpTSI = OldCallOpTSI;
8315 else {
8316 // Transform the TypeSourceInfo of the Original Lambda's Call Operator.
8317 // The transformation MUST be done in the CurrentInstantiationScope since
8318 // it introduces a mapping of the original to the newly created
8319 // transformed parameters.
8320
8321 TypeLocBuilder NewCallOpTLBuilder;
8322 QualType NewCallOpType = TransformFunctionProtoType(NewCallOpTLBuilder,
8323 OldCallOpFPTL,
8324 0, 0);
8325 NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context,
8326 NewCallOpType);
Faisal Vali2b391ab2013-09-26 19:54:12 +00008327 }
Faisal Vali2cba1332013-10-23 06:44:28 +00008328 // Extract the ParmVarDecls from the NewCallOpTSI and add them to
8329 // the vector below - this will be used to synthesize the
8330 // NewCallOperator. Additionally, add the parameters of the untransformed
8331 // lambda call operator to the CurrentInstantiationScope.
8332 SmallVector<ParmVarDecl *, 4> Params;
8333 {
8334 FunctionProtoTypeLoc NewCallOpFPTL =
8335 NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>();
8336 ParmVarDecl **NewParamDeclArray = NewCallOpFPTL.getParmArray();
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00008337 const unsigned NewNumArgs = NewCallOpFPTL.getNumParams();
Faisal Vali2cba1332013-10-23 06:44:28 +00008338
8339 for (unsigned I = 0; I < NewNumArgs; ++I) {
8340 // If this call operator's type does not require transformation,
8341 // the parameters do not get added to the current instantiation scope,
8342 // - so ADD them! This allows the following to compile when the enclosing
8343 // template is specialized and the entire lambda expression has to be
8344 // transformed.
8345 // template<class T> void foo(T t) {
8346 // auto L = [](auto a) {
8347 // auto M = [](char b) { <-- note: non-generic lambda
8348 // auto N = [](auto c) {
8349 // int x = sizeof(a);
8350 // x = sizeof(b); <-- specifically this line
8351 // x = sizeof(c);
8352 // };
8353 // };
8354 // };
8355 // }
8356 // foo('a')
8357 if (CallOpWasAlreadyTransformed)
8358 getDerived().transformedLocalDecl(NewParamDeclArray[I],
8359 NewParamDeclArray[I]);
8360 // Add to Params array, so these parameters can be used to create
8361 // the newly transformed call operator.
8362 Params.push_back(NewParamDeclArray[I]);
8363 }
8364 }
8365
8366 if (!NewCallOpTSI)
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008367 return ExprError();
8368
Eli Friedmand564afb2012-09-19 01:18:11 +00008369 // Create the local class that will describe the lambda.
8370 CXXRecordDecl *Class
8371 = getSema().createLambdaClosureType(E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +00008372 NewCallOpTSI,
Faisal Valic1a6dc42013-10-23 16:10:50 +00008373 /*KnownDependent=*/false,
8374 E->getCaptureDefault());
8375
Eli Friedmand564afb2012-09-19 01:18:11 +00008376 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
8377
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008378 // Build the call operator.
Faisal Vali2cba1332013-10-23 06:44:28 +00008379 CXXMethodDecl *NewCallOperator
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008380 = getSema().startLambdaDefinition(Class, E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +00008381 NewCallOpTSI,
Douglas Gregoradb376e2012-02-14 22:28:59 +00008382 E->getCallOperator()->getLocEnd(),
Richard Smith505df232012-07-22 23:45:10 +00008383 Params);
Faisal Vali2cba1332013-10-23 06:44:28 +00008384 LSI->CallOperator = NewCallOperator;
Rafael Espindola4b35f272013-10-04 14:28:51 +00008385
Faisal Vali2cba1332013-10-23 06:44:28 +00008386 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
8387
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008388 return getDerived().TransformLambdaScope(E, NewCallOperator,
8389 InitCaptureExprsAndTypes);
Richard Smith2589b9802012-07-25 03:56:55 +00008390}
8391
8392template<typename Derived>
8393ExprResult
8394TreeTransform<Derived>::TransformLambdaScope(LambdaExpr *E,
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008395 CXXMethodDecl *CallOperator,
8396 ArrayRef<InitCaptureInfoTy> InitCaptureExprsAndTypes) {
Richard Smithba71c082013-05-16 06:20:58 +00008397 bool Invalid = false;
8398
Douglas Gregorb4328232012-02-14 00:00:48 +00008399 // Introduce the context of the call operator.
Richard Smith7ff2bcb2014-01-24 01:54:52 +00008400 Sema::ContextRAII SavedContext(getSema(), CallOperator,
8401 /*NewThisContext*/false);
Douglas Gregorb4328232012-02-14 00:00:48 +00008402
Faisal Vali2b391ab2013-09-26 19:54:12 +00008403 LambdaScopeInfo *const LSI = getSema().getCurLambda();
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008404 // Enter the scope of the lambda.
Faisal Vali2b391ab2013-09-26 19:54:12 +00008405 getSema().buildLambdaScope(LSI, CallOperator, E->getIntroducerRange(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008406 E->getCaptureDefault(),
James Dennettddd36ff2013-08-09 23:08:25 +00008407 E->getCaptureDefaultLoc(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008408 E->hasExplicitParameters(),
8409 E->hasExplicitResultType(),
8410 E->isMutable());
Chad Rosier1dcde962012-08-08 18:46:20 +00008411
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008412 // Transform captures.
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008413 bool FinishedExplicitCaptures = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00008414 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008415 CEnd = E->capture_end();
8416 C != CEnd; ++C) {
8417 // When we hit the first implicit capture, tell Sema that we've finished
8418 // the list of explicit captures.
8419 if (!FinishedExplicitCaptures && C->isImplicit()) {
8420 getSema().finishLambdaExplicitCaptures(LSI);
8421 FinishedExplicitCaptures = true;
8422 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008423
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008424 // Capturing 'this' is trivial.
8425 if (C->capturesThis()) {
8426 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
8427 continue;
8428 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008429
Richard Smithba71c082013-05-16 06:20:58 +00008430 // Rebuild init-captures, including the implied field declaration.
8431 if (C->isInitCapture()) {
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008432
8433 InitCaptureInfoTy InitExprTypePair =
8434 InitCaptureExprsAndTypes[C - E->capture_begin()];
8435 ExprResult Init = InitExprTypePair.first;
8436 QualType InitQualType = InitExprTypePair.second;
8437 if (Init.isInvalid() || InitQualType.isNull()) {
Richard Smithba71c082013-05-16 06:20:58 +00008438 Invalid = true;
8439 continue;
8440 }
Richard Smithbb13c9a2013-09-28 04:02:39 +00008441 VarDecl *OldVD = C->getCapturedVar();
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008442 VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl(
8443 OldVD->getLocation(), InitExprTypePair.second,
8444 OldVD->getIdentifier(), Init.get());
Richard Smithbb13c9a2013-09-28 04:02:39 +00008445 if (!NewVD)
Richard Smithba71c082013-05-16 06:20:58 +00008446 Invalid = true;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008447 else {
Richard Smithbb13c9a2013-09-28 04:02:39 +00008448 getDerived().transformedLocalDecl(OldVD, NewVD);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008449 }
Richard Smithbb13c9a2013-09-28 04:02:39 +00008450 getSema().buildInitCaptureField(LSI, NewVD);
Richard Smithba71c082013-05-16 06:20:58 +00008451 continue;
8452 }
8453
8454 assert(C->capturesVariable() && "unexpected kind of lambda capture");
8455
Douglas Gregor3e308b12012-02-14 19:27:52 +00008456 // Determine the capture kind for Sema.
8457 Sema::TryCaptureKind Kind
8458 = C->isImplicit()? Sema::TryCapture_Implicit
8459 : C->getCaptureKind() == LCK_ByCopy
8460 ? Sema::TryCapture_ExplicitByVal
8461 : Sema::TryCapture_ExplicitByRef;
8462 SourceLocation EllipsisLoc;
8463 if (C->isPackExpansion()) {
8464 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
8465 bool ShouldExpand = false;
8466 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00008467 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +00008468 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
8469 C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +00008470 Unexpanded,
8471 ShouldExpand, RetainExpansion,
Richard Smithba71c082013-05-16 06:20:58 +00008472 NumExpansions)) {
8473 Invalid = true;
8474 continue;
8475 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008476
Douglas Gregor3e308b12012-02-14 19:27:52 +00008477 if (ShouldExpand) {
8478 // The transform has determined that we should perform an expansion;
8479 // transform and capture each of the arguments.
8480 // expansion of the pattern. Do so.
8481 VarDecl *Pack = C->getCapturedVar();
8482 for (unsigned I = 0; I != *NumExpansions; ++I) {
8483 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8484 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +00008485 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +00008486 Pack));
8487 if (!CapturedVar) {
8488 Invalid = true;
8489 continue;
8490 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008491
Douglas Gregor3e308b12012-02-14 19:27:52 +00008492 // Capture the transformed variable.
Chad Rosier1dcde962012-08-08 18:46:20 +00008493 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
8494 }
Douglas Gregor3e308b12012-02-14 19:27:52 +00008495 continue;
8496 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008497
Douglas Gregor3e308b12012-02-14 19:27:52 +00008498 EllipsisLoc = C->getEllipsisLoc();
8499 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008500
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008501 // Transform the captured variable.
8502 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +00008503 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008504 C->getCapturedVar()));
8505 if (!CapturedVar) {
8506 Invalid = true;
8507 continue;
8508 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008509
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008510 // Capture the transformed variable.
Douglas Gregorfdf598e2012-02-18 09:37:24 +00008511 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008512 }
8513 if (!FinishedExplicitCaptures)
8514 getSema().finishLambdaExplicitCaptures(LSI);
8515
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008516
8517 // Enter a new evaluation context to insulate the lambda from any
8518 // cleanups from the enclosing full-expression.
Chad Rosier1dcde962012-08-08 18:46:20 +00008519 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008520
8521 if (Invalid) {
Chad Rosier1dcde962012-08-08 18:46:20 +00008522 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008523 /*IsInstantiation=*/true);
8524 return ExprError();
8525 }
8526
8527 // Instantiate the body of the lambda expression.
Douglas Gregorb4328232012-02-14 00:00:48 +00008528 StmtResult Body = getDerived().TransformStmt(E->getBody());
8529 if (Body.isInvalid()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00008530 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
Douglas Gregorb4328232012-02-14 00:00:48 +00008531 /*IsInstantiation=*/true);
Chad Rosier1dcde962012-08-08 18:46:20 +00008532 return ExprError();
Douglas Gregorb4328232012-02-14 00:00:48 +00008533 }
Douglas Gregor7fcbd902012-02-21 00:37:24 +00008534
Chad Rosier1dcde962012-08-08 18:46:20 +00008535 return getSema().ActOnLambdaExpr(E->getLocStart(), Body.take(),
Douglas Gregorb61e8092012-04-04 17:40:10 +00008536 /*CurScope=*/0, /*IsInstantiation=*/true);
Douglas Gregore31e6062012-02-07 10:09:13 +00008537}
8538
8539template<typename Derived>
8540ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008541TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008542 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00008543 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8544 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00008545 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008546
Douglas Gregora16548e2009-08-11 05:31:07 +00008547 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008548 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +00008549 Args.reserve(E->arg_size());
Chad Rosier1dcde962012-08-08 18:46:20 +00008550 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00008551 &ArgumentChanged))
8552 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008553
Douglas Gregora16548e2009-08-11 05:31:07 +00008554 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00008555 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008556 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00008557 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00008558
Douglas Gregora16548e2009-08-11 05:31:07 +00008559 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +00008560 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +00008561 E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008562 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00008563 E->getRParenLoc());
8564}
Mike Stump11289f42009-09-09 15:08:12 +00008565
Douglas Gregora16548e2009-08-11 05:31:07 +00008566template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008567ExprResult
John McCall8cd78132009-11-19 22:55:06 +00008568TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008569 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008570 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00008571 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00008572 Expr *OldBase;
8573 QualType BaseType;
8574 QualType ObjectType;
8575 if (!E->isImplicitAccess()) {
8576 OldBase = E->getBase();
8577 Base = getDerived().TransformExpr(OldBase);
8578 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008579 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008580
John McCall2d74de92009-12-01 22:10:20 +00008581 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +00008582 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +00008583 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00008584 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00008585 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00008586 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00008587 ObjectTy,
8588 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00008589 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008590 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00008591
John McCallba7bf592010-08-24 05:47:05 +00008592 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +00008593 BaseType = ((Expr*) Base.get())->getType();
8594 } else {
8595 OldBase = 0;
8596 BaseType = getDerived().TransformType(E->getBaseType());
8597 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
8598 }
Mike Stump11289f42009-09-09 15:08:12 +00008599
Douglas Gregora5cb6da2009-10-20 05:58:46 +00008600 // Transform the first part of the nested-name-specifier that qualifies
8601 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00008602 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00008603 = getDerived().TransformFirstQualifierInScope(
Douglas Gregore16af532011-02-28 18:50:33 +00008604 E->getFirstQualifierFoundInScope(),
8605 E->getQualifierLoc().getBeginLoc());
Mike Stump11289f42009-09-09 15:08:12 +00008606
Douglas Gregore16af532011-02-28 18:50:33 +00008607 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00008608 if (E->getQualifier()) {
Douglas Gregore16af532011-02-28 18:50:33 +00008609 QualifierLoc
8610 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
8611 ObjectType,
8612 FirstQualifierInScope);
8613 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008614 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +00008615 }
Mike Stump11289f42009-09-09 15:08:12 +00008616
Abramo Bagnara7945c982012-01-27 09:46:47 +00008617 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
8618
John McCall31f82722010-11-12 08:19:04 +00008619 // TODO: If this is a conversion-function-id, verify that the
8620 // destination type name (if present) resolves the same way after
8621 // instantiation as it did in the local scope.
8622
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008623 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +00008624 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008625 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00008626 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008627
John McCall2d74de92009-12-01 22:10:20 +00008628 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00008629 // This is a reference to a member without an explicitly-specified
8630 // template argument list. Optimize for this common case.
8631 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00008632 Base.get() == OldBase &&
8633 BaseType == E->getBaseType() &&
Douglas Gregore16af532011-02-28 18:50:33 +00008634 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008635 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00008636 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCallc3007a22010-10-26 07:05:15 +00008637 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00008638
John McCallb268a282010-08-23 23:25:46 +00008639 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00008640 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00008641 E->isArrow(),
8642 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00008643 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008644 TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00008645 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008646 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00008647 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00008648 }
8649
John McCall6b51f282009-11-23 01:53:49 +00008650 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008651 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8652 E->getNumTemplateArgs(),
8653 TransArgs))
8654 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008655
John McCallb268a282010-08-23 23:25:46 +00008656 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00008657 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00008658 E->isArrow(),
8659 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00008660 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008661 TemplateKWLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +00008662 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008663 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00008664 &TransArgs);
8665}
8666
8667template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008668ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008669TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00008670 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00008671 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00008672 QualType BaseType;
8673 if (!Old->isImplicitAccess()) {
8674 Base = getDerived().TransformExpr(Old->getBase());
8675 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008676 return ExprError();
Richard Smithcab9a7d2011-10-26 19:06:56 +00008677 Base = getSema().PerformMemberExprBaseConversion(Base.take(),
8678 Old->isArrow());
8679 if (Base.isInvalid())
8680 return ExprError();
8681 BaseType = Base.get()->getType();
John McCall2d74de92009-12-01 22:10:20 +00008682 } else {
8683 BaseType = getDerived().TransformType(Old->getBaseType());
8684 }
John McCall10eae182009-11-30 22:42:35 +00008685
Douglas Gregor0da1d432011-02-28 20:01:57 +00008686 NestedNameSpecifierLoc QualifierLoc;
8687 if (Old->getQualifierLoc()) {
8688 QualifierLoc
8689 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
8690 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008691 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00008692 }
8693
Abramo Bagnara7945c982012-01-27 09:46:47 +00008694 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
8695
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008696 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +00008697 Sema::LookupOrdinaryName);
8698
8699 // Transform all the decls.
8700 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
8701 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008702 NamedDecl *InstD = static_cast<NamedDecl*>(
8703 getDerived().TransformDecl(Old->getMemberLoc(),
8704 *I));
John McCall84d87672009-12-10 09:41:52 +00008705 if (!InstD) {
8706 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
8707 // This can happen because of dependent hiding.
8708 if (isa<UsingShadowDecl>(*I))
8709 continue;
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00008710 else {
8711 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00008712 return ExprError();
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00008713 }
John McCall84d87672009-12-10 09:41:52 +00008714 }
John McCall10eae182009-11-30 22:42:35 +00008715
8716 // Expand using declarations.
8717 if (isa<UsingDecl>(InstD)) {
8718 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +00008719 for (auto *I : UD->shadows())
8720 R.addDecl(I);
John McCall10eae182009-11-30 22:42:35 +00008721 continue;
8722 }
8723
8724 R.addDecl(InstD);
8725 }
8726
8727 R.resolveKind();
8728
Douglas Gregor9262f472010-04-27 18:19:34 +00008729 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00008730 if (Old->getNamingClass()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00008731 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00008732 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00008733 Old->getMemberLoc(),
8734 Old->getNamingClass()));
8735 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00008736 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008737
Douglas Gregorda7be082010-04-27 16:10:10 +00008738 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00008739 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008740
John McCall10eae182009-11-30 22:42:35 +00008741 TemplateArgumentListInfo TransArgs;
8742 if (Old->hasExplicitTemplateArgs()) {
8743 TransArgs.setLAngleLoc(Old->getLAngleLoc());
8744 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008745 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
8746 Old->getNumTemplateArgs(),
8747 TransArgs))
8748 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00008749 }
John McCall38836f02010-01-15 08:34:02 +00008750
8751 // FIXME: to do this check properly, we will need to preserve the
8752 // first-qualifier-in-scope here, just in case we had a dependent
8753 // base (and therefore couldn't do the check) and a
8754 // nested-name-qualifier (and therefore could do the lookup).
8755 NamedDecl *FirstQualifierInScope = 0;
Chad Rosier1dcde962012-08-08 18:46:20 +00008756
John McCallb268a282010-08-23 23:25:46 +00008757 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00008758 BaseType,
John McCall10eae182009-11-30 22:42:35 +00008759 Old->getOperatorLoc(),
8760 Old->isArrow(),
Douglas Gregor0da1d432011-02-28 20:01:57 +00008761 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008762 TemplateKWLoc,
John McCall38836f02010-01-15 08:34:02 +00008763 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00008764 R,
8765 (Old->hasExplicitTemplateArgs()
8766 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00008767}
8768
8769template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008770ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +00008771TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Alexis Hunt414e3e32011-05-31 19:54:49 +00008772 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00008773 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
8774 if (SubExpr.isInvalid())
8775 return ExprError();
8776
8777 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCallc3007a22010-10-26 07:05:15 +00008778 return SemaRef.Owned(E);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00008779
8780 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
8781}
8782
8783template<typename Derived>
8784ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +00008785TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +00008786 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
8787 if (Pattern.isInvalid())
8788 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008789
Douglas Gregor0f836ea2011-01-13 00:19:55 +00008790 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
8791 return SemaRef.Owned(E);
8792
Douglas Gregorb8840002011-01-14 21:20:45 +00008793 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
8794 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +00008795}
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008796
8797template<typename Derived>
8798ExprResult
8799TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
8800 // If E is not value-dependent, then nothing will change when we transform it.
8801 // Note: This is an instantiation-centric view.
8802 if (!E->isValueDependent())
8803 return SemaRef.Owned(E);
8804
8805 // Note: None of the implementations of TryExpandParameterPacks can ever
8806 // produce a diagnostic when given only a single unexpanded parameter pack,
Chad Rosier1dcde962012-08-08 18:46:20 +00008807 // so
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008808 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
8809 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00008810 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00008811 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +00008812 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikieb9c168a2011-09-22 02:34:54 +00008813 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00008814 ShouldExpand, RetainExpansion,
8815 NumExpansions))
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008816 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008817
Douglas Gregorab96bcf2011-10-10 18:59:29 +00008818 if (RetainExpansion)
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008819 return SemaRef.Owned(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00008820
Douglas Gregorab96bcf2011-10-10 18:59:29 +00008821 NamedDecl *Pack = E->getPack();
8822 if (!ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00008823 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
Douglas Gregorab96bcf2011-10-10 18:59:29 +00008824 Pack));
8825 if (!Pack)
8826 return ExprError();
8827 }
8828
Chad Rosier1dcde962012-08-08 18:46:20 +00008829
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008830 // We now know the length of the parameter pack, so build a new expression
8831 // that stores that length.
Chad Rosier1dcde962012-08-08 18:46:20 +00008832 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
8833 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregorab96bcf2011-10-10 18:59:29 +00008834 NumExpansions);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008835}
8836
Douglas Gregore8e9dd62011-01-03 17:17:50 +00008837template<typename Derived>
8838ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +00008839TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
8840 SubstNonTypeTemplateParmPackExpr *E) {
8841 // Default behavior is to do nothing with this transformation.
8842 return SemaRef.Owned(E);
8843}
8844
8845template<typename Derived>
8846ExprResult
John McCall7c454bb2011-07-15 05:09:51 +00008847TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
8848 SubstNonTypeTemplateParmExpr *E) {
8849 // Default behavior is to do nothing with this transformation.
8850 return SemaRef.Owned(E);
8851}
8852
8853template<typename Derived>
8854ExprResult
Richard Smithb15fe3a2012-09-12 00:56:43 +00008855TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
8856 // Default behavior is to do nothing with this transformation.
8857 return SemaRef.Owned(E);
8858}
8859
8860template<typename Derived>
8861ExprResult
Douglas Gregorfe314812011-06-21 17:03:29 +00008862TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
8863 MaterializeTemporaryExpr *E) {
8864 return getDerived().TransformExpr(E->GetTemporaryExpr());
8865}
Chad Rosier1dcde962012-08-08 18:46:20 +00008866
Douglas Gregorfe314812011-06-21 17:03:29 +00008867template<typename Derived>
8868ExprResult
Richard Smithcc1b96d2013-06-12 22:31:48 +00008869TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
8870 CXXStdInitializerListExpr *E) {
8871 return getDerived().TransformExpr(E->getSubExpr());
8872}
8873
8874template<typename Derived>
8875ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008876TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00008877 return SemaRef.MaybeBindToTemporary(E);
8878}
8879
8880template<typename Derived>
8881ExprResult
8882TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Jordy Rose8986c5992012-03-12 17:53:02 +00008883 return SemaRef.Owned(E);
Ted Kremeneke65b0862012-03-06 20:05:56 +00008884}
8885
8886template<typename Derived>
8887ExprResult
Patrick Beard0caa3942012-04-19 00:25:12 +00008888TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
8889 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
8890 if (SubExpr.isInvalid())
8891 return ExprError();
8892
8893 if (!getDerived().AlwaysRebuild() &&
8894 SubExpr.get() == E->getSubExpr())
8895 return SemaRef.Owned(E);
8896
8897 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremeneke65b0862012-03-06 20:05:56 +00008898}
8899
8900template<typename Derived>
8901ExprResult
8902TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
8903 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +00008904 SmallVector<Expr *, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +00008905 bool ArgChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00008906 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremeneke65b0862012-03-06 20:05:56 +00008907 /*IsCall=*/false, Elements, &ArgChanged))
8908 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008909
Ted Kremeneke65b0862012-03-06 20:05:56 +00008910 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8911 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00008912
Ted Kremeneke65b0862012-03-06 20:05:56 +00008913 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
8914 Elements.data(),
8915 Elements.size());
8916}
8917
8918template<typename Derived>
8919ExprResult
8920TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier1dcde962012-08-08 18:46:20 +00008921 ObjCDictionaryLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00008922 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +00008923 SmallVector<ObjCDictionaryElement, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +00008924 bool ArgChanged = false;
8925 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
8926 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier1dcde962012-08-08 18:46:20 +00008927
Ted Kremeneke65b0862012-03-06 20:05:56 +00008928 if (OrigElement.isPackExpansion()) {
8929 // This key/value element is a pack expansion.
8930 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
8931 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
8932 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
8933 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
8934
8935 // Determine whether the set of unexpanded parameter packs can
8936 // and should be expanded.
8937 bool Expand = true;
8938 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00008939 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
8940 Optional<unsigned> NumExpansions = OrigNumExpansions;
Ted Kremeneke65b0862012-03-06 20:05:56 +00008941 SourceRange PatternRange(OrigElement.Key->getLocStart(),
8942 OrigElement.Value->getLocEnd());
8943 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
8944 PatternRange,
8945 Unexpanded,
8946 Expand, RetainExpansion,
8947 NumExpansions))
8948 return ExprError();
8949
8950 if (!Expand) {
8951 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00008952 // transformation on the pack expansion, producing another pack
Ted Kremeneke65b0862012-03-06 20:05:56 +00008953 // expansion.
8954 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
8955 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8956 if (Key.isInvalid())
8957 return ExprError();
8958
8959 if (Key.get() != OrigElement.Key)
8960 ArgChanged = true;
8961
8962 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8963 if (Value.isInvalid())
8964 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008965
Ted Kremeneke65b0862012-03-06 20:05:56 +00008966 if (Value.get() != OrigElement.Value)
8967 ArgChanged = true;
8968
Chad Rosier1dcde962012-08-08 18:46:20 +00008969 ObjCDictionaryElement Expansion = {
Ted Kremeneke65b0862012-03-06 20:05:56 +00008970 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
8971 };
8972 Elements.push_back(Expansion);
8973 continue;
8974 }
8975
8976 // Record right away that the argument was changed. This needs
8977 // to happen even if the array expands to nothing.
8978 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00008979
Ted Kremeneke65b0862012-03-06 20:05:56 +00008980 // The transform has determined that we should perform an elementwise
8981 // expansion of the pattern. Do so.
8982 for (unsigned I = 0; I != *NumExpansions; ++I) {
8983 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8984 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8985 if (Key.isInvalid())
8986 return ExprError();
8987
8988 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8989 if (Value.isInvalid())
8990 return ExprError();
8991
Chad Rosier1dcde962012-08-08 18:46:20 +00008992 ObjCDictionaryElement Element = {
Ted Kremeneke65b0862012-03-06 20:05:56 +00008993 Key.get(), Value.get(), SourceLocation(), NumExpansions
8994 };
8995
8996 // If any unexpanded parameter packs remain, we still have a
8997 // pack expansion.
8998 if (Key.get()->containsUnexpandedParameterPack() ||
8999 Value.get()->containsUnexpandedParameterPack())
9000 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier1dcde962012-08-08 18:46:20 +00009001
Ted Kremeneke65b0862012-03-06 20:05:56 +00009002 Elements.push_back(Element);
9003 }
9004
9005 // We've finished with this pack expansion.
9006 continue;
9007 }
9008
9009 // Transform and check key.
9010 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
9011 if (Key.isInvalid())
9012 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009013
Ted Kremeneke65b0862012-03-06 20:05:56 +00009014 if (Key.get() != OrigElement.Key)
9015 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009016
Ted Kremeneke65b0862012-03-06 20:05:56 +00009017 // Transform and check value.
9018 ExprResult Value
9019 = getDerived().TransformExpr(OrigElement.Value);
9020 if (Value.isInvalid())
9021 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009022
Ted Kremeneke65b0862012-03-06 20:05:56 +00009023 if (Value.get() != OrigElement.Value)
9024 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009025
9026 ObjCDictionaryElement Element = {
David Blaikie7a30dc52013-02-21 01:47:18 +00009027 Key.get(), Value.get(), SourceLocation(), None
Ted Kremeneke65b0862012-03-06 20:05:56 +00009028 };
9029 Elements.push_back(Element);
9030 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009031
Ted Kremeneke65b0862012-03-06 20:05:56 +00009032 if (!getDerived().AlwaysRebuild() && !ArgChanged)
9033 return SemaRef.MaybeBindToTemporary(E);
9034
9035 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
9036 Elements.data(),
9037 Elements.size());
Douglas Gregora16548e2009-08-11 05:31:07 +00009038}
9039
Mike Stump11289f42009-09-09 15:08:12 +00009040template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009041ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009042TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00009043 TypeSourceInfo *EncodedTypeInfo
9044 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
9045 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009046 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009047
Douglas Gregora16548e2009-08-11 05:31:07 +00009048 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00009049 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00009050 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009051
9052 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00009053 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00009054 E->getRParenLoc());
9055}
Mike Stump11289f42009-09-09 15:08:12 +00009056
Douglas Gregora16548e2009-08-11 05:31:07 +00009057template<typename Derived>
John McCall31168b02011-06-15 23:02:42 +00009058ExprResult TreeTransform<Derived>::
9059TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
John McCallbc489892013-04-11 02:14:26 +00009060 // This is a kind of implicit conversion, and it needs to get dropped
9061 // and recomputed for the same general reasons that ImplicitCastExprs
9062 // do, as well a more specific one: this expression is only valid when
9063 // it appears *immediately* as an argument expression.
9064 return getDerived().TransformExpr(E->getSubExpr());
John McCall31168b02011-06-15 23:02:42 +00009065}
9066
9067template<typename Derived>
9068ExprResult TreeTransform<Derived>::
9069TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier1dcde962012-08-08 18:46:20 +00009070 TypeSourceInfo *TSInfo
John McCall31168b02011-06-15 23:02:42 +00009071 = getDerived().TransformType(E->getTypeInfoAsWritten());
9072 if (!TSInfo)
9073 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009074
John McCall31168b02011-06-15 23:02:42 +00009075 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier1dcde962012-08-08 18:46:20 +00009076 if (Result.isInvalid())
John McCall31168b02011-06-15 23:02:42 +00009077 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009078
John McCall31168b02011-06-15 23:02:42 +00009079 if (!getDerived().AlwaysRebuild() &&
9080 TSInfo == E->getTypeInfoAsWritten() &&
9081 Result.get() == E->getSubExpr())
9082 return SemaRef.Owned(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009083
John McCall31168b02011-06-15 23:02:42 +00009084 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier1dcde962012-08-08 18:46:20 +00009085 E->getBridgeKeywordLoc(), TSInfo,
John McCall31168b02011-06-15 23:02:42 +00009086 Result.get());
9087}
9088
9089template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009090ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009091TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009092 // Transform arguments.
9093 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009094 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +00009095 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +00009096 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009097 &ArgChanged))
9098 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009099
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009100 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
9101 // Class message: transform the receiver type.
9102 TypeSourceInfo *ReceiverTypeInfo
9103 = getDerived().TransformType(E->getClassReceiverTypeInfo());
9104 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009105 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009106
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009107 // If nothing changed, just retain the existing message send.
9108 if (!getDerived().AlwaysRebuild() &&
9109 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009110 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009111
9112 // Build a new class message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009113 SmallVector<SourceLocation, 16> SelLocs;
9114 E->getSelectorLocs(SelLocs);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009115 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
9116 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009117 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009118 E->getMethodDecl(),
9119 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009120 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009121 E->getRightLoc());
9122 }
9123
9124 // Instance message: transform the receiver
9125 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
9126 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +00009127 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009128 = getDerived().TransformExpr(E->getInstanceReceiver());
9129 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009130 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009131
9132 // If nothing changed, just retain the existing message send.
9133 if (!getDerived().AlwaysRebuild() &&
9134 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009135 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009136
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009137 // Build a new instance message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009138 SmallVector<SourceLocation, 16> SelLocs;
9139 E->getSelectorLocs(SelLocs);
John McCallb268a282010-08-23 23:25:46 +00009140 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009141 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009142 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009143 E->getMethodDecl(),
9144 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009145 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009146 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00009147}
9148
Mike Stump11289f42009-09-09 15:08:12 +00009149template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009150ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009151TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00009152 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009153}
9154
Mike Stump11289f42009-09-09 15:08:12 +00009155template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009156ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009157TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00009158 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009159}
9160
Mike Stump11289f42009-09-09 15:08:12 +00009161template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009162ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009163TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00009164 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00009165 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00009166 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009167 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +00009168
9169 // We don't need to transform the ivar; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +00009170
Douglas Gregord51d90d2010-04-26 20:11:03 +00009171 // If nothing changed, just retain the existing expression.
9172 if (!getDerived().AlwaysRebuild() &&
9173 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00009174 return SemaRef.Owned(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009175
John McCallb268a282010-08-23 23:25:46 +00009176 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00009177 E->getLocation(),
9178 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +00009179}
9180
Mike Stump11289f42009-09-09 15:08:12 +00009181template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009182ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009183TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +00009184 // 'super' and types never change. Property never changes. Just
9185 // retain the existing expression.
9186 if (!E->isObjectReceiver())
John McCallc3007a22010-10-26 07:05:15 +00009187 return SemaRef.Owned(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009188
Douglas Gregor9faee212010-04-26 20:47:02 +00009189 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00009190 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +00009191 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009192 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009193
Douglas Gregor9faee212010-04-26 20:47:02 +00009194 // We don't need to transform the property; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +00009195
Douglas Gregor9faee212010-04-26 20:47:02 +00009196 // If nothing changed, just retain the existing expression.
9197 if (!getDerived().AlwaysRebuild() &&
9198 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00009199 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009200
John McCallb7bd14f2010-12-02 01:19:52 +00009201 if (E->isExplicitProperty())
9202 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
9203 E->getExplicitProperty(),
9204 E->getLocation());
9205
9206 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall526ab472011-10-25 17:37:35 +00009207 SemaRef.Context.PseudoObjectTy,
John McCallb7bd14f2010-12-02 01:19:52 +00009208 E->getImplicitPropertyGetter(),
9209 E->getImplicitPropertySetter(),
9210 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00009211}
9212
Mike Stump11289f42009-09-09 15:08:12 +00009213template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009214ExprResult
Ted Kremeneke65b0862012-03-06 20:05:56 +00009215TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
9216 // Transform the base expression.
9217 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
9218 if (Base.isInvalid())
9219 return ExprError();
9220
9221 // Transform the key expression.
9222 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
9223 if (Key.isInvalid())
9224 return ExprError();
9225
9226 // If nothing changed, just retain the existing expression.
9227 if (!getDerived().AlwaysRebuild() &&
9228 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
9229 return SemaRef.Owned(E);
9230
Chad Rosier1dcde962012-08-08 18:46:20 +00009231 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremeneke65b0862012-03-06 20:05:56 +00009232 Base.get(), Key.get(),
9233 E->getAtIndexMethodDecl(),
9234 E->setAtIndexMethodDecl());
9235}
9236
9237template<typename Derived>
9238ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009239TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00009240 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00009241 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00009242 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009243 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009244
Douglas Gregord51d90d2010-04-26 20:11:03 +00009245 // If nothing changed, just retain the existing expression.
9246 if (!getDerived().AlwaysRebuild() &&
9247 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00009248 return SemaRef.Owned(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009249
John McCallb268a282010-08-23 23:25:46 +00009250 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00009251 E->getOpLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00009252 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +00009253}
9254
Mike Stump11289f42009-09-09 15:08:12 +00009255template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009256ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009257TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009258 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009259 SmallVector<Expr*, 8> SubExprs;
Douglas Gregora3efea12011-01-03 19:04:46 +00009260 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier1dcde962012-08-08 18:46:20 +00009261 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00009262 SubExprs, &ArgumentChanged))
9263 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009264
Douglas Gregora16548e2009-08-11 05:31:07 +00009265 if (!getDerived().AlwaysRebuild() &&
9266 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00009267 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00009268
Douglas Gregora16548e2009-08-11 05:31:07 +00009269 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009270 SubExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00009271 E->getRParenLoc());
9272}
9273
Mike Stump11289f42009-09-09 15:08:12 +00009274template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009275ExprResult
Hal Finkelc4d7c822013-09-18 03:29:45 +00009276TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) {
9277 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
9278 if (SrcExpr.isInvalid())
9279 return ExprError();
9280
9281 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
9282 if (!Type)
9283 return ExprError();
9284
9285 if (!getDerived().AlwaysRebuild() &&
9286 Type == E->getTypeSourceInfo() &&
9287 SrcExpr.get() == E->getSrcExpr())
9288 return SemaRef.Owned(E);
9289
9290 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
9291 SrcExpr.get(), Type,
9292 E->getRParenLoc());
9293}
9294
9295template<typename Derived>
9296ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009297TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +00009298 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier1dcde962012-08-08 18:46:20 +00009299
John McCall490112f2011-02-04 18:33:18 +00009300 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
9301 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
9302
9303 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahaniandd5eb9d2011-12-03 17:47:53 +00009304 blockScope->TheDecl->setBlockMissingReturnType(
9305 oldBlock->blockMissingReturnType());
Chad Rosier1dcde962012-08-08 18:46:20 +00009306
Chris Lattner01cf8db2011-07-20 06:58:45 +00009307 SmallVector<ParmVarDecl*, 4> params;
9308 SmallVector<QualType, 4> paramTypes;
Chad Rosier1dcde962012-08-08 18:46:20 +00009309
Fariborz Jahanian1babe772010-07-09 18:44:02 +00009310 // Parameter substitution.
John McCall490112f2011-02-04 18:33:18 +00009311 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
9312 oldBlock->param_begin(),
9313 oldBlock->param_size(),
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +00009314 0, paramTypes, &params)) {
9315 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009316 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +00009317 }
John McCall490112f2011-02-04 18:33:18 +00009318
Jordan Rosea0a86be2013-03-08 22:25:36 +00009319 const FunctionProtoType *exprFunctionType = E->getFunctionType();
Eli Friedman34b49062012-01-26 03:00:14 +00009320 QualType exprResultType =
Alp Toker314cc812014-01-25 16:55:45 +00009321 getDerived().TransformType(exprFunctionType->getReturnType());
Douglas Gregor476e3022011-01-19 21:32:01 +00009322
Jordan Rose5c382722013-03-08 21:51:21 +00009323 QualType functionType =
9324 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +00009325 exprFunctionType->getExtProtoInfo());
John McCall490112f2011-02-04 18:33:18 +00009326 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +00009327
9328 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +00009329 if (!params.empty())
David Blaikie9c70e042011-09-21 18:16:56 +00009330 blockScope->TheDecl->setParams(params);
Eli Friedman34b49062012-01-26 03:00:14 +00009331
9332 if (!oldBlock->blockMissingReturnType()) {
9333 blockScope->HasImplicitReturnType = false;
9334 blockScope->ReturnType = exprResultType;
9335 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009336
John McCall3882ace2011-01-05 12:14:39 +00009337 // Transform the body
John McCall490112f2011-02-04 18:33:18 +00009338 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +00009339 if (body.isInvalid()) {
9340 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
John McCall3882ace2011-01-05 12:14:39 +00009341 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +00009342 }
John McCall3882ace2011-01-05 12:14:39 +00009343
John McCall490112f2011-02-04 18:33:18 +00009344#ifndef NDEBUG
9345 // In builds with assertions, make sure that we captured everything we
9346 // captured before.
Douglas Gregor4385d8b2011-05-20 15:32:55 +00009347 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
9348 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
9349 e = oldBlock->capture_end(); i != e; ++i) {
9350 VarDecl *oldCapture = i->getVariable();
John McCall490112f2011-02-04 18:33:18 +00009351
Douglas Gregor4385d8b2011-05-20 15:32:55 +00009352 // Ignore parameter packs.
9353 if (isa<ParmVarDecl>(oldCapture) &&
9354 cast<ParmVarDecl>(oldCapture)->isParameterPack())
9355 continue;
John McCall490112f2011-02-04 18:33:18 +00009356
Douglas Gregor4385d8b2011-05-20 15:32:55 +00009357 VarDecl *newCapture =
9358 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
9359 oldCapture));
9360 assert(blockScope->CaptureMap.count(newCapture));
9361 }
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00009362 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCall490112f2011-02-04 18:33:18 +00009363 }
9364#endif
9365
9366 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
9367 /*Scope=*/0);
Douglas Gregora16548e2009-08-11 05:31:07 +00009368}
9369
Mike Stump11289f42009-09-09 15:08:12 +00009370template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009371ExprResult
Tanya Lattner55808c12011-06-04 00:47:47 +00009372TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikie83d382b2011-09-23 05:06:16 +00009373 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner55808c12011-06-04 00:47:47 +00009374}
Eli Friedmandf14b3a2011-10-11 02:20:01 +00009375
9376template<typename Derived>
9377ExprResult
9378TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedman8d3e43f2011-10-14 22:48:56 +00009379 QualType RetTy = getDerived().TransformType(E->getType());
9380 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009381 SmallVector<Expr*, 8> SubExprs;
Eli Friedman8d3e43f2011-10-14 22:48:56 +00009382 SubExprs.reserve(E->getNumSubExprs());
9383 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
9384 SubExprs, &ArgumentChanged))
9385 return ExprError();
9386
9387 if (!getDerived().AlwaysRebuild() &&
9388 !ArgumentChanged)
9389 return SemaRef.Owned(E);
9390
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009391 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedman8d3e43f2011-10-14 22:48:56 +00009392 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedmandf14b3a2011-10-11 02:20:01 +00009393}
Chad Rosier1dcde962012-08-08 18:46:20 +00009394
Douglas Gregora16548e2009-08-11 05:31:07 +00009395//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00009396// Type reconstruction
9397//===----------------------------------------------------------------------===//
9398
Mike Stump11289f42009-09-09 15:08:12 +00009399template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00009400QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
9401 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00009402 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009403 getDerived().getBaseEntity());
9404}
9405
Mike Stump11289f42009-09-09 15:08:12 +00009406template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00009407QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
9408 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00009409 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009410 getDerived().getBaseEntity());
9411}
9412
Mike Stump11289f42009-09-09 15:08:12 +00009413template<typename Derived>
9414QualType
John McCall70dd5f62009-10-30 00:06:24 +00009415TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
9416 bool WrittenAsLValue,
9417 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00009418 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +00009419 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00009420}
9421
9422template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009423QualType
John McCall70dd5f62009-10-30 00:06:24 +00009424TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
9425 QualType ClassType,
9426 SourceLocation Sigil) {
Reid Kleckner0503a872013-12-05 01:23:43 +00009427 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil,
9428 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00009429}
9430
9431template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009432QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00009433TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
9434 ArrayType::ArraySizeModifier SizeMod,
9435 const llvm::APInt *Size,
9436 Expr *SizeExpr,
9437 unsigned IndexTypeQuals,
9438 SourceRange BracketsRange) {
9439 if (SizeExpr || !Size)
9440 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
9441 IndexTypeQuals, BracketsRange,
9442 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00009443
9444 QualType Types[] = {
9445 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
9446 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
9447 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00009448 };
Craig Toppere5ce8312013-07-15 03:38:40 +00009449 const unsigned NumTypes = llvm::array_lengthof(Types);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009450 QualType SizeType;
9451 for (unsigned I = 0; I != NumTypes; ++I)
9452 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
9453 SizeType = Types[I];
9454 break;
9455 }
Mike Stump11289f42009-09-09 15:08:12 +00009456
Eli Friedman9562f392012-01-25 23:20:27 +00009457 // Note that we can return a VariableArrayType here in the case where
9458 // the element type was a dependent VariableArrayType.
9459 IntegerLiteral *ArraySize
9460 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
9461 /*FIXME*/BracketsRange.getBegin());
9462 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009463 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00009464 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00009465}
Mike Stump11289f42009-09-09 15:08:12 +00009466
Douglas Gregord6ff3322009-08-04 16:50:30 +00009467template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009468QualType
9469TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009470 ArrayType::ArraySizeModifier SizeMod,
9471 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00009472 unsigned IndexTypeQuals,
9473 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00009474 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00009475 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009476}
9477
9478template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009479QualType
Mike Stump11289f42009-09-09 15:08:12 +00009480TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009481 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00009482 unsigned IndexTypeQuals,
9483 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00009484 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00009485 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009486}
Mike Stump11289f42009-09-09 15:08:12 +00009487
Douglas Gregord6ff3322009-08-04 16:50:30 +00009488template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009489QualType
9490TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009491 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00009492 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009493 unsigned IndexTypeQuals,
9494 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00009495 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00009496 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009497 IndexTypeQuals, BracketsRange);
9498}
9499
9500template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009501QualType
9502TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009503 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00009504 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009505 unsigned IndexTypeQuals,
9506 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00009507 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00009508 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009509 IndexTypeQuals, BracketsRange);
9510}
9511
9512template<typename Derived>
9513QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +00009514 unsigned NumElements,
9515 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00009516 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +00009517 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009518}
Mike Stump11289f42009-09-09 15:08:12 +00009519
Douglas Gregord6ff3322009-08-04 16:50:30 +00009520template<typename Derived>
9521QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
9522 unsigned NumElements,
9523 SourceLocation AttributeLoc) {
9524 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
9525 NumElements, true);
9526 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00009527 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
9528 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +00009529 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009530}
Mike Stump11289f42009-09-09 15:08:12 +00009531
Douglas Gregord6ff3322009-08-04 16:50:30 +00009532template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009533QualType
9534TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +00009535 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009536 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +00009537 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009538}
Mike Stump11289f42009-09-09 15:08:12 +00009539
Douglas Gregord6ff3322009-08-04 16:50:30 +00009540template<typename Derived>
Jordan Rose5c382722013-03-08 21:51:21 +00009541QualType TreeTransform<Derived>::RebuildFunctionProtoType(
9542 QualType T,
9543 llvm::MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +00009544 const FunctionProtoType::ExtProtoInfo &EPI) {
9545 return SemaRef.BuildFunctionType(T, ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009546 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +00009547 getDerived().getBaseEntity(),
Jordan Rosea0a86be2013-03-08 22:25:36 +00009548 EPI);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009549}
Mike Stump11289f42009-09-09 15:08:12 +00009550
Douglas Gregord6ff3322009-08-04 16:50:30 +00009551template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00009552QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
9553 return SemaRef.Context.getFunctionNoProtoType(T);
9554}
9555
9556template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00009557QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
9558 assert(D && "no decl found");
9559 if (D->isInvalidDecl()) return QualType();
9560
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009561 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +00009562 TypeDecl *Ty;
9563 if (isa<UsingDecl>(D)) {
9564 UsingDecl *Using = cast<UsingDecl>(D);
Enea Zaffanellae05a3cf2013-07-22 10:54:09 +00009565 assert(Using->hasTypename() &&
John McCallb96ec562009-12-04 22:46:56 +00009566 "UnresolvedUsingTypenameDecl transformed to non-typename using");
9567
9568 // A valid resolved using typename decl points to exactly one type decl.
9569 assert(++Using->shadow_begin() == Using->shadow_end());
9570 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +00009571
John McCallb96ec562009-12-04 22:46:56 +00009572 } else {
9573 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
9574 "UnresolvedUsingTypenameDecl transformed to non-using decl");
9575 Ty = cast<UnresolvedUsingTypenameDecl>(D);
9576 }
9577
9578 return SemaRef.Context.getTypeDeclType(Ty);
9579}
9580
9581template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00009582QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
9583 SourceLocation Loc) {
9584 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009585}
9586
9587template<typename Derived>
9588QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
9589 return SemaRef.Context.getTypeOfType(Underlying);
9590}
9591
9592template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00009593QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
9594 SourceLocation Loc) {
9595 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009596}
9597
9598template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00009599QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
9600 UnaryTransformType::UTTKind UKind,
9601 SourceLocation Loc) {
9602 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
9603}
9604
9605template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00009606QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00009607 TemplateName Template,
9608 SourceLocation TemplateNameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +00009609 TemplateArgumentListInfo &TemplateArgs) {
John McCall6b51f282009-11-23 01:53:49 +00009610 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009611}
Mike Stump11289f42009-09-09 15:08:12 +00009612
Douglas Gregor1135c352009-08-06 05:28:30 +00009613template<typename Derived>
Eli Friedman0dfb8892011-10-06 23:00:33 +00009614QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
9615 SourceLocation KWLoc) {
9616 return SemaRef.BuildAtomicType(ValueType, KWLoc);
9617}
9618
9619template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009620TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00009621TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +00009622 bool TemplateKW,
9623 TemplateDecl *Template) {
Douglas Gregor9db53502011-03-02 18:07:45 +00009624 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00009625 Template);
9626}
9627
9628template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009629TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00009630TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
9631 const IdentifierInfo &Name,
9632 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +00009633 QualType ObjectType,
9634 NamedDecl *FirstQualifierInScope) {
Douglas Gregor9db53502011-03-02 18:07:45 +00009635 UnqualifiedId TemplateName;
9636 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregorbb119652010-06-16 23:00:59 +00009637 Sema::TemplateTy Template;
Abramo Bagnara7945c982012-01-27 09:46:47 +00009638 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregorbb119652010-06-16 23:00:59 +00009639 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009640 SS, TemplateKWLoc, TemplateName,
John McCallba7bf592010-08-24 05:47:05 +00009641 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00009642 /*EnteringContext=*/false,
9643 Template);
John McCall31f82722010-11-12 08:19:04 +00009644 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +00009645}
Mike Stump11289f42009-09-09 15:08:12 +00009646
Douglas Gregora16548e2009-08-11 05:31:07 +00009647template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00009648TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00009649TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +00009650 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +00009651 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +00009652 QualType ObjectType) {
Douglas Gregor71395fa2009-11-04 00:56:37 +00009653 UnqualifiedId Name;
Douglas Gregor9db53502011-03-02 18:07:45 +00009654 // FIXME: Bogus location information.
Abramo Bagnara7945c982012-01-27 09:46:47 +00009655 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregor9db53502011-03-02 18:07:45 +00009656 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnara7945c982012-01-27 09:46:47 +00009657 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregorbb119652010-06-16 23:00:59 +00009658 Sema::TemplateTy Template;
9659 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009660 SS, TemplateKWLoc, Name,
John McCallba7bf592010-08-24 05:47:05 +00009661 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00009662 /*EnteringContext=*/false,
9663 Template);
Serge Pavlov9ddb76e2013-08-27 13:15:56 +00009664 return Template.get();
Douglas Gregor71395fa2009-11-04 00:56:37 +00009665}
Chad Rosier1dcde962012-08-08 18:46:20 +00009666
Douglas Gregor71395fa2009-11-04 00:56:37 +00009667template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009668ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009669TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
9670 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00009671 Expr *OrigCallee,
9672 Expr *First,
9673 Expr *Second) {
9674 Expr *Callee = OrigCallee->IgnoreParenCasts();
9675 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00009676
Douglas Gregora16548e2009-08-11 05:31:07 +00009677 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00009678 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +00009679 if (!First->getType()->isOverloadableType() &&
9680 !Second->getType()->isOverloadableType())
9681 return getSema().CreateBuiltinArraySubscriptExpr(First,
9682 Callee->getLocStart(),
9683 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00009684 } else if (Op == OO_Arrow) {
9685 // -> is never a builtin operation.
John McCallb268a282010-08-23 23:25:46 +00009686 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
9687 } else if (Second == 0 || isPostIncDec) {
9688 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009689 // The argument is not of overloadable type, so try to create a
9690 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +00009691 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00009692 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00009693
John McCallb268a282010-08-23 23:25:46 +00009694 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00009695 }
9696 } else {
John McCallb268a282010-08-23 23:25:46 +00009697 if (!First->getType()->isOverloadableType() &&
9698 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009699 // Neither of the arguments is an overloadable type, so try to
9700 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +00009701 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00009702 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00009703 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +00009704 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009705 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009706
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009707 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00009708 }
9709 }
Mike Stump11289f42009-09-09 15:08:12 +00009710
9711 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00009712 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00009713 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00009714
John McCallb268a282010-08-23 23:25:46 +00009715 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +00009716 assert(ULE->requiresADL());
9717
9718 // FIXME: Do we have to check
9719 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall4c4c1df2010-01-26 03:27:55 +00009720 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00009721 } else {
Richard Smith58db83d2012-11-28 21:47:39 +00009722 // If we've resolved this to a particular non-member function, just call
9723 // that function. If we resolved it to a member function,
9724 // CreateOverloaded* will find that function for us.
9725 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
9726 if (!isa<CXXMethodDecl>(ND))
9727 Functions.addDecl(ND);
John McCalld14a8642009-11-21 08:51:07 +00009728 }
Mike Stump11289f42009-09-09 15:08:12 +00009729
Douglas Gregora16548e2009-08-11 05:31:07 +00009730 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +00009731 Expr *Args[2] = { First, Second };
9732 unsigned NumArgs = 1 + (Second != 0);
Mike Stump11289f42009-09-09 15:08:12 +00009733
Douglas Gregora16548e2009-08-11 05:31:07 +00009734 // Create the overloaded operator invocation for unary operators.
9735 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +00009736 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00009737 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +00009738 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00009739 }
Mike Stump11289f42009-09-09 15:08:12 +00009740
Douglas Gregore9d62932011-07-15 16:25:15 +00009741 if (Op == OO_Subscript) {
9742 SourceLocation LBrace;
9743 SourceLocation RBrace;
9744
9745 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
9746 DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
9747 LBrace = SourceLocation::getFromRawEncoding(
9748 NameLoc.CXXOperatorName.BeginOpNameLoc);
9749 RBrace = SourceLocation::getFromRawEncoding(
9750 NameLoc.CXXOperatorName.EndOpNameLoc);
9751 } else {
9752 LBrace = Callee->getLocStart();
9753 RBrace = OpLoc;
9754 }
9755
9756 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
9757 First, Second);
9758 }
Sebastian Redladba46e2009-10-29 20:17:01 +00009759
Douglas Gregora16548e2009-08-11 05:31:07 +00009760 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +00009761 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00009762 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00009763 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
9764 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009765 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009766
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009767 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00009768}
Mike Stump11289f42009-09-09 15:08:12 +00009769
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009770template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00009771ExprResult
John McCallb268a282010-08-23 23:25:46 +00009772TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009773 SourceLocation OperatorLoc,
9774 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +00009775 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009776 TypeSourceInfo *ScopeType,
9777 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00009778 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00009779 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +00009780 QualType BaseType = Base->getType();
9781 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009782 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier1dcde962012-08-08 18:46:20 +00009783 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +00009784 !BaseType->getAs<PointerType>()->getPointeeType()
9785 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009786 // This pseudo-destructor expression is still a pseudo-destructor.
John McCallb268a282010-08-23 23:25:46 +00009787 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009788 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00009789 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00009790 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009791 /*FIXME?*/true);
9792 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009793
Douglas Gregor678f90d2010-02-25 01:56:36 +00009794 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009795 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
9796 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
9797 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
9798 NameInfo.setNamedTypeInfo(DestroyedType);
9799
Richard Smith8e4a3862012-05-15 06:15:11 +00009800 // The scope type is now known to be a valid nested name specifier
9801 // component. Tack it on to the end of the nested name specifier.
9802 if (ScopeType)
9803 SS.Extend(SemaRef.Context, SourceLocation(),
9804 ScopeType->getTypeLoc(), CCLoc);
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009805
Abramo Bagnara7945c982012-01-27 09:46:47 +00009806 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCallb268a282010-08-23 23:25:46 +00009807 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009808 OperatorLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009809 SS, TemplateKWLoc,
9810 /*FIXME: FirstQualifier*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009811 NameInfo,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009812 /*TemplateArgs*/ 0);
9813}
9814
Tareq A. Siraj24110cc2013-04-16 18:53:08 +00009815template<typename Derived>
9816StmtResult
9817TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
Wei Pan17fbf6e2013-05-04 03:59:06 +00009818 SourceLocation Loc = S->getLocStart();
9819 unsigned NumParams = S->getCapturedDecl()->getNumParams();
9820 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/0,
9821 S->getCapturedRegionKind(), NumParams);
9822 StmtResult Body = getDerived().TransformStmt(S->getCapturedStmt());
9823
9824 if (Body.isInvalid()) {
9825 getSema().ActOnCapturedRegionError();
9826 return StmtError();
9827 }
9828
9829 return getSema().ActOnCapturedRegionEnd(Body.take());
Tareq A. Siraj24110cc2013-04-16 18:53:08 +00009830}
9831
Douglas Gregord6ff3322009-08-04 16:50:30 +00009832} // end namespace clang
9833
9834#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H