blob: 60da5f3210ead9a2a03f21fe731abcb0383ffb5f [file] [log] [blame]
Chris Lattnercab02a62011-02-17 20:34:02 +00001//===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Chris Lattnercab02a62011-02-17 20:34:02 +00007//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00008//
9// This file implements a semantic tree transformation that takes a given
10// AST and rebuilds it, possibly transforming some nodes in the process.
11//
Chris Lattnercab02a62011-02-17 20:34:02 +000012//===----------------------------------------------------------------------===//
13
Douglas Gregord6ff3322009-08-04 16:50:30 +000014#ifndef LLVM_CLANG_SEMA_TREETRANSFORM_H
15#define LLVM_CLANG_SEMA_TREETRANSFORM_H
16
Chandler Carruth3a022472012-12-04 09:13:33 +000017#include "TypeLocBuilder.h"
Douglas Gregor2b6ca462009-09-03 21:38:09 +000018#include "clang/AST/Decl.h"
John McCallde6836a2010-08-24 07:21:54 +000019#include "clang/AST/DeclObjC.h"
Richard Smith3f1b5d02011-05-05 21:57:07 +000020#include "clang/AST/DeclTemplate.h"
Douglas Gregor766b0bb2009-08-06 22:17:10 +000021#include "clang/AST/Expr.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000022#include "clang/AST/ExprCXX.h"
23#include "clang/AST/ExprObjC.h"
Douglas Gregorebe10102009-08-20 07:17:43 +000024#include "clang/AST/Stmt.h"
25#include "clang/AST/StmtCXX.h"
26#include "clang/AST/StmtObjC.h"
Alexey Bataev5ec3eb12013-07-19 03:13:43 +000027#include "clang/AST/StmtOpenMP.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000028#include "clang/Lex/Preprocessor.h"
Chandler Carruth3a022472012-12-04 09:13:33 +000029#include "clang/Sema/Designator.h"
30#include "clang/Sema/Lookup.h"
31#include "clang/Sema/Ownership.h"
32#include "clang/Sema/ParsedTemplate.h"
33#include "clang/Sema/ScopeInfo.h"
34#include "clang/Sema/SemaDiagnostic.h"
35#include "clang/Sema/SemaInternal.h"
David Blaikieb9c168a2011-09-22 02:34:54 +000036#include "llvm/ADT/ArrayRef.h"
John McCall550e0c22009-10-21 00:40:46 +000037#include "llvm/Support/ErrorHandling.h"
Douglas Gregord6ff3322009-08-04 16:50:30 +000038#include <algorithm>
39
40namespace clang {
John McCallaab3e412010-08-25 08:40:02 +000041using namespace sema;
Mike Stump11289f42009-09-09 15:08:12 +000042
Douglas Gregord6ff3322009-08-04 16:50:30 +000043/// \brief A semantic tree transformation that allows one to transform one
44/// abstract syntax tree into another.
45///
Mike Stump11289f42009-09-09 15:08:12 +000046/// A new tree transformation is defined by creating a new subclass \c X of
47/// \c TreeTransform<X> and then overriding certain operations to provide
48/// behavior specific to that transformation. For example, template
Douglas Gregord6ff3322009-08-04 16:50:30 +000049/// instantiation is implemented as a tree transformation where the
50/// transformation of TemplateTypeParmType nodes involves substituting the
51/// template arguments for their corresponding template parameters; a similar
52/// transformation is performed for non-type template parameters and
53/// template template parameters.
54///
55/// This tree-transformation template uses static polymorphism to allow
Mike Stump11289f42009-09-09 15:08:12 +000056/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregord6ff3322009-08-04 16:50:30 +000057/// override any of the transformation or rebuild operators by providing an
58/// operation with the same signature as the default implementation. The
59/// overridding function should not be virtual.
60///
61/// Semantic tree transformations are split into two stages, either of which
62/// can be replaced by a subclass. The "transform" step transforms an AST node
63/// or the parts of an AST node using the various transformation functions,
64/// then passes the pieces on to the "rebuild" step, which constructs a new AST
65/// node of the appropriate kind from the pieces. The default transformation
66/// routines recursively transform the operands to composite AST nodes (e.g.,
67/// the pointee type of a PointerType node) and, if any of those operand nodes
68/// were changed by the transformation, invokes the rebuild operation to create
69/// a new AST node.
70///
Mike Stump11289f42009-09-09 15:08:12 +000071/// Subclasses can customize the transformation at various levels. The
Douglas Gregore922c772009-08-04 22:27:00 +000072/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregorfd35cde2011-03-02 18:50:38 +000073/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(),
Douglas Gregord6ff3322009-08-04 16:50:30 +000074/// TransformTemplateName(), or TransformTemplateArgument() with entirely
75/// new implementations.
76///
77/// For more fine-grained transformations, subclasses can replace any of the
78/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
Douglas Gregorebe10102009-08-20 07:17:43 +000079/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregord6ff3322009-08-04 16:50:30 +000080/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump11289f42009-09-09 15:08:12 +000081/// to substitute template arguments for their corresponding template
Douglas Gregord6ff3322009-08-04 16:50:30 +000082/// parameters. Additionally, subclasses can override the \c RebuildXXX
83/// functions to control how AST nodes are rebuilt when their operands change.
84/// By default, \c TreeTransform will invoke semantic analysis to rebuild
85/// AST nodes. However, certain other tree transformations (e.g, cloning) may
86/// be able to use more efficient rebuild steps.
87///
88/// There are a handful of other functions that can be overridden, allowing one
Mike Stump11289f42009-09-09 15:08:12 +000089/// to avoid traversing nodes that don't need any transformation
Douglas Gregord6ff3322009-08-04 16:50:30 +000090/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
91/// operands have not changed (\c AlwaysRebuild()), and customize the
92/// default locations and entity names used for type-checking
93/// (\c getBaseLocation(), \c getBaseEntity()).
Douglas Gregord6ff3322009-08-04 16:50:30 +000094template<typename Derived>
95class TreeTransform {
Douglas Gregora8bac7f2011-01-10 07:32:04 +000096 /// \brief Private RAII object that helps us forget and then re-remember
97 /// the template argument corresponding to a partially-substituted parameter
98 /// pack.
99 class ForgetPartiallySubstitutedPackRAII {
100 Derived &Self;
101 TemplateArgument Old;
Chad Rosier1dcde962012-08-08 18:46:20 +0000102
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000103 public:
104 ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) {
105 Old = Self.ForgetPartiallySubstitutedPack();
106 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000107
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000108 ~ForgetPartiallySubstitutedPackRAII() {
109 Self.RememberPartiallySubstitutedPack(Old);
110 }
111 };
Chad Rosier1dcde962012-08-08 18:46:20 +0000112
Douglas Gregord6ff3322009-08-04 16:50:30 +0000113protected:
114 Sema &SemaRef;
Chad Rosier1dcde962012-08-08 18:46:20 +0000115
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000116 /// \brief The set of local declarations that have been transformed, for
117 /// cases where we are forced to build new declarations within the transformer
118 /// rather than in the subclass (e.g., lambda closure types).
119 llvm::DenseMap<Decl *, Decl *> TransformedLocalDecls;
Chad Rosier1dcde962012-08-08 18:46:20 +0000120
Mike Stump11289f42009-09-09 15:08:12 +0000121public:
Douglas Gregord6ff3322009-08-04 16:50:30 +0000122 /// \brief Initializes a new tree transformer.
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000123 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump11289f42009-09-09 15:08:12 +0000124
Douglas Gregord6ff3322009-08-04 16:50:30 +0000125 /// \brief Retrieves a reference to the derived class.
126 Derived &getDerived() { return static_cast<Derived&>(*this); }
127
128 /// \brief Retrieves a reference to the derived class.
Mike Stump11289f42009-09-09 15:08:12 +0000129 const Derived &getDerived() const {
130 return static_cast<const Derived&>(*this);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000131 }
132
John McCalldadc5752010-08-24 06:29:42 +0000133 static inline ExprResult Owned(Expr *E) { return E; }
134 static inline StmtResult Owned(Stmt *S) { return S; }
John McCallb268a282010-08-23 23:25:46 +0000135
Douglas Gregord6ff3322009-08-04 16:50:30 +0000136 /// \brief Retrieves a reference to the semantic analysis object used for
137 /// this tree transform.
138 Sema &getSema() const { return SemaRef; }
Mike Stump11289f42009-09-09 15:08:12 +0000139
Douglas Gregord6ff3322009-08-04 16:50:30 +0000140 /// \brief Whether the transformation should always rebuild AST nodes, even
141 /// if none of the children have changed.
142 ///
143 /// Subclasses may override this function to specify when the transformation
144 /// should rebuild all AST nodes.
Richard Smith2aa81a72013-11-07 20:07:17 +0000145 ///
146 /// We must always rebuild all AST nodes when performing variadic template
147 /// pack expansion, in order to avoid violating the AST invariant that each
148 /// statement node appears at most once in its containing declaration.
149 bool AlwaysRebuild() { return SemaRef.ArgumentPackSubstitutionIndex != -1; }
Mike Stump11289f42009-09-09 15:08:12 +0000150
Douglas Gregord6ff3322009-08-04 16:50:30 +0000151 /// \brief Returns the location of the entity being transformed, if that
152 /// information was not available elsewhere in the AST.
153 ///
Mike Stump11289f42009-09-09 15:08:12 +0000154 /// By default, returns no source-location information. Subclasses can
Douglas Gregord6ff3322009-08-04 16:50:30 +0000155 /// provide an alternative implementation that provides better location
156 /// information.
157 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump11289f42009-09-09 15:08:12 +0000158
Douglas Gregord6ff3322009-08-04 16:50:30 +0000159 /// \brief Returns the name of the entity being transformed, if that
160 /// information was not available elsewhere in the AST.
161 ///
162 /// By default, returns an empty name. Subclasses can provide an alternative
163 /// implementation with a more precise name.
164 DeclarationName getBaseEntity() { return DeclarationName(); }
165
Douglas Gregora16548e2009-08-11 05:31:07 +0000166 /// \brief Sets the "base" location and entity when that
167 /// information is known based on another transformation.
168 ///
169 /// By default, the source location and entity are ignored. Subclasses can
170 /// override this function to provide a customized implementation.
171 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump11289f42009-09-09 15:08:12 +0000172
Douglas Gregora16548e2009-08-11 05:31:07 +0000173 /// \brief RAII object that temporarily sets the base location and entity
174 /// used for reporting diagnostics in types.
175 class TemporaryBase {
176 TreeTransform &Self;
177 SourceLocation OldLocation;
178 DeclarationName OldEntity;
Mike Stump11289f42009-09-09 15:08:12 +0000179
Douglas Gregora16548e2009-08-11 05:31:07 +0000180 public:
181 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump11289f42009-09-09 15:08:12 +0000182 DeclarationName Entity) : Self(Self) {
Douglas Gregora16548e2009-08-11 05:31:07 +0000183 OldLocation = Self.getDerived().getBaseLocation();
184 OldEntity = Self.getDerived().getBaseEntity();
Chad Rosier1dcde962012-08-08 18:46:20 +0000185
Douglas Gregora518d5b2011-01-25 17:51:48 +0000186 if (Location.isValid())
187 Self.getDerived().setBase(Location, Entity);
Douglas Gregora16548e2009-08-11 05:31:07 +0000188 }
Mike Stump11289f42009-09-09 15:08:12 +0000189
Douglas Gregora16548e2009-08-11 05:31:07 +0000190 ~TemporaryBase() {
191 Self.getDerived().setBase(OldLocation, OldEntity);
192 }
193 };
Mike Stump11289f42009-09-09 15:08:12 +0000194
195 /// \brief Determine whether the given type \p T has already been
Douglas Gregord6ff3322009-08-04 16:50:30 +0000196 /// transformed.
197 ///
198 /// Subclasses can provide an alternative implementation of this routine
Mike Stump11289f42009-09-09 15:08:12 +0000199 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregord6ff3322009-08-04 16:50:30 +0000200 /// not change. For example, template instantiation need not traverse
201 /// non-dependent types.
202 bool AlreadyTransformed(QualType T) {
203 return T.isNull();
204 }
205
Douglas Gregord196a582009-12-14 19:27:10 +0000206 /// \brief Determine whether the given call argument should be dropped, e.g.,
207 /// because it is a default argument.
208 ///
209 /// Subclasses can provide an alternative implementation of this routine to
210 /// determine which kinds of call arguments get dropped. By default,
211 /// CXXDefaultArgument nodes are dropped (prior to transformation).
212 bool DropCallArgument(Expr *E) {
213 return E->isDefaultArgument();
214 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000215
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000216 /// \brief Determine whether we should expand a pack expansion with the
217 /// given set of parameter packs into separate arguments by repeatedly
218 /// transforming the pattern.
219 ///
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000220 /// By default, the transformer never tries to expand pack expansions.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000221 /// Subclasses can override this routine to provide different behavior.
222 ///
223 /// \param EllipsisLoc The location of the ellipsis that identifies the
224 /// pack expansion.
225 ///
226 /// \param PatternRange The source range that covers the entire pattern of
227 /// the pack expansion.
228 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000229 /// \param Unexpanded The set of unexpanded parameter packs within the
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000230 /// pattern.
231 ///
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000232 /// \param ShouldExpand Will be set to \c true if the transformer should
233 /// expand the corresponding pack expansions into separate arguments. When
234 /// set, \c NumExpansions must also be set.
235 ///
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000236 /// \param RetainExpansion Whether the caller should add an unexpanded
237 /// pack expansion after all of the expanded arguments. This is used
238 /// when extending explicitly-specified template argument packs per
239 /// C++0x [temp.arg.explicit]p9.
240 ///
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000241 /// \param NumExpansions The number of separate arguments that will be in
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000242 /// the expanded form of the corresponding pack expansion. This is both an
243 /// input and an output parameter, which can be set by the caller if the
244 /// number of expansions is known a priori (e.g., due to a prior substitution)
245 /// and will be set by the callee when the number of expansions is known.
246 /// The callee must set this value when \c ShouldExpand is \c true; it may
247 /// set this value in other cases.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000248 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000249 /// \returns true if an error occurred (e.g., because the parameter packs
250 /// are to be instantiated with arguments of different lengths), false
251 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000252 /// must be set.
253 bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
254 SourceRange PatternRange,
Dmitri Gribenkof8579502013-01-12 19:30:44 +0000255 ArrayRef<UnexpandedParameterPack> Unexpanded,
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000256 bool &ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000257 bool &RetainExpansion,
David Blaikie05785d12013-02-20 22:23:23 +0000258 Optional<unsigned> &NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000259 ShouldExpand = false;
260 return false;
261 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000262
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000263 /// \brief "Forget" about the partially-substituted pack template argument,
264 /// when performing an instantiation that must preserve the parameter pack
265 /// use.
266 ///
267 /// This routine is meant to be overridden by the template instantiator.
268 TemplateArgument ForgetPartiallySubstitutedPack() {
269 return TemplateArgument();
270 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000271
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000272 /// \brief "Remember" the partially-substituted pack template argument
273 /// after performing an instantiation that must preserve the parameter pack
274 /// use.
275 ///
276 /// This routine is meant to be overridden by the template instantiator.
277 void RememberPartiallySubstitutedPack(TemplateArgument Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000278
Douglas Gregorf3010112011-01-07 16:43:16 +0000279 /// \brief Note to the derived class when a function parameter pack is
280 /// being expanded.
281 void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000282
Douglas Gregord6ff3322009-08-04 16:50:30 +0000283 /// \brief Transforms the given type into another type.
284 ///
John McCall550e0c22009-10-21 00:40:46 +0000285 /// By default, this routine transforms a type by creating a
John McCallbcd03502009-12-07 02:54:59 +0000286 /// TypeSourceInfo for it and delegating to the appropriate
John McCall550e0c22009-10-21 00:40:46 +0000287 /// function. This is expensive, but we don't mind, because
288 /// this method is deprecated anyway; all users should be
John McCallbcd03502009-12-07 02:54:59 +0000289 /// switched to storing TypeSourceInfos.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000290 ///
291 /// \returns the transformed type.
John McCall31f82722010-11-12 08:19:04 +0000292 QualType TransformType(QualType T);
Mike Stump11289f42009-09-09 15:08:12 +0000293
John McCall550e0c22009-10-21 00:40:46 +0000294 /// \brief Transforms the given type-with-location into a new
295 /// type-with-location.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000296 ///
John McCall550e0c22009-10-21 00:40:46 +0000297 /// By default, this routine transforms a type by delegating to the
298 /// appropriate TransformXXXType to build a new type. Subclasses
299 /// may override this function (to take over all type
300 /// transformations) or some set of the TransformXXXType functions
301 /// to alter the transformation.
John McCall31f82722010-11-12 08:19:04 +0000302 TypeSourceInfo *TransformType(TypeSourceInfo *DI);
John McCall550e0c22009-10-21 00:40:46 +0000303
304 /// \brief Transform the given type-with-location into a new
305 /// type, collecting location information in the given builder
306 /// as necessary.
307 ///
John McCall31f82722010-11-12 08:19:04 +0000308 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
Mike Stump11289f42009-09-09 15:08:12 +0000309
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000310 /// \brief Transform the given statement.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000311 ///
Mike Stump11289f42009-09-09 15:08:12 +0000312 /// By default, this routine transforms a statement by delegating to the
Douglas Gregorebe10102009-08-20 07:17:43 +0000313 /// appropriate TransformXXXStmt function to transform a specific kind of
314 /// statement or the TransformExpr() function to transform an expression.
315 /// Subclasses may override this function to transform statements using some
316 /// other mechanism.
317 ///
318 /// \returns the transformed statement.
John McCalldadc5752010-08-24 06:29:42 +0000319 StmtResult TransformStmt(Stmt *S);
Mike Stump11289f42009-09-09 15:08:12 +0000320
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000321 /// \brief Transform the given statement.
322 ///
323 /// By default, this routine transforms a statement by delegating to the
324 /// appropriate TransformOMPXXXClause function to transform a specific kind
325 /// of clause. Subclasses may override this function to transform statements
326 /// using some other mechanism.
327 ///
328 /// \returns the transformed OpenMP clause.
329 OMPClause *TransformOMPClause(OMPClause *S);
330
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000331 /// \brief Transform the given expression.
332 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000333 /// By default, this routine transforms an expression by delegating to the
334 /// appropriate TransformXXXExpr function to build a new expression.
335 /// Subclasses may override this function to transform expressions using some
336 /// other mechanism.
337 ///
338 /// \returns the transformed expression.
John McCalldadc5752010-08-24 06:29:42 +0000339 ExprResult TransformExpr(Expr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000340
Richard Smithd59b8322012-12-19 01:39:02 +0000341 /// \brief Transform the given initializer.
342 ///
343 /// By default, this routine transforms an initializer by stripping off the
344 /// semantic nodes added by initialization, then passing the result to
345 /// TransformExpr or TransformExprs.
346 ///
347 /// \returns the transformed initializer.
348 ExprResult TransformInitializer(Expr *Init, bool CXXDirectInit);
349
Douglas Gregora3efea12011-01-03 19:04:46 +0000350 /// \brief Transform the given list of expressions.
351 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000352 /// This routine transforms a list of expressions by invoking
353 /// \c TransformExpr() for each subexpression. However, it also provides
Douglas Gregora3efea12011-01-03 19:04:46 +0000354 /// support for variadic templates by expanding any pack expansions (if the
355 /// derived class permits such expansion) along the way. When pack expansions
356 /// are present, the number of outputs may not equal the number of inputs.
357 ///
358 /// \param Inputs The set of expressions to be transformed.
359 ///
360 /// \param NumInputs The number of expressions in \c Inputs.
361 ///
362 /// \param IsCall If \c true, then this transform is being performed on
Chad Rosier1dcde962012-08-08 18:46:20 +0000363 /// function-call arguments, and any arguments that should be dropped, will
Douglas Gregora3efea12011-01-03 19:04:46 +0000364 /// be.
365 ///
366 /// \param Outputs The transformed input expressions will be added to this
367 /// vector.
368 ///
369 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
370 /// due to transformation.
371 ///
372 /// \returns true if an error occurred, false otherwise.
373 bool TransformExprs(Expr **Inputs, unsigned NumInputs, bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +0000374 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregora3efea12011-01-03 19:04:46 +0000375 bool *ArgChanged = 0);
Chad Rosier1dcde962012-08-08 18:46:20 +0000376
Douglas Gregord6ff3322009-08-04 16:50:30 +0000377 /// \brief Transform the given declaration, which is referenced from a type
378 /// or expression.
379 ///
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000380 /// By default, acts as the identity function on declarations, unless the
381 /// transformer has had to transform the declaration itself. Subclasses
Douglas Gregor1135c352009-08-06 05:28:30 +0000382 /// may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000383 Decl *TransformDecl(SourceLocation Loc, Decl *D) {
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000384 llvm::DenseMap<Decl *, Decl *>::iterator Known
385 = TransformedLocalDecls.find(D);
386 if (Known != TransformedLocalDecls.end())
387 return Known->second;
Chad Rosier1dcde962012-08-08 18:46:20 +0000388
389 return D;
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000390 }
Douglas Gregorebe10102009-08-20 07:17:43 +0000391
Chad Rosier1dcde962012-08-08 18:46:20 +0000392 /// \brief Transform the attributes associated with the given declaration and
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000393 /// place them on the new declaration.
394 ///
395 /// By default, this operation does nothing. Subclasses may override this
396 /// behavior to transform attributes.
397 void transformAttrs(Decl *Old, Decl *New) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000398
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000399 /// \brief Note that a local declaration has been transformed by this
400 /// transformer.
401 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000402 /// Local declarations are typically transformed via a call to
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000403 /// TransformDefinition. However, in some cases (e.g., lambda expressions),
404 /// the transformer itself has to transform the declarations. This routine
405 /// can be overridden by a subclass that keeps track of such mappings.
406 void transformedLocalDecl(Decl *Old, Decl *New) {
407 TransformedLocalDecls[Old] = New;
408 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000409
Douglas Gregorebe10102009-08-20 07:17:43 +0000410 /// \brief Transform the definition of the given declaration.
411 ///
Mike Stump11289f42009-09-09 15:08:12 +0000412 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregorebe10102009-08-20 07:17:43 +0000413 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000414 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
415 return getDerived().TransformDecl(Loc, D);
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000416 }
Mike Stump11289f42009-09-09 15:08:12 +0000417
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000418 /// \brief Transform the given declaration, which was the first part of a
419 /// nested-name-specifier in a member access expression.
420 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000421 /// This specific declaration transformation only applies to the first
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000422 /// identifier in a nested-name-specifier of a member access expression, e.g.,
423 /// the \c T in \c x->T::member
424 ///
425 /// By default, invokes TransformDecl() to transform the declaration.
426 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000427 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
428 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000429 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000430
Douglas Gregor14454802011-02-25 02:25:35 +0000431 /// \brief Transform the given nested-name-specifier with source-location
432 /// information.
433 ///
434 /// By default, transforms all of the types and declarations within the
435 /// nested-name-specifier. Subclasses may override this function to provide
436 /// alternate behavior.
437 NestedNameSpecifierLoc TransformNestedNameSpecifierLoc(
438 NestedNameSpecifierLoc NNS,
439 QualType ObjectType = QualType(),
440 NamedDecl *FirstQualifierInScope = 0);
441
Douglas Gregorf816bd72009-09-03 22:13:48 +0000442 /// \brief Transform the given declaration name.
443 ///
444 /// By default, transforms the types of conversion function, constructor,
445 /// and destructor names and then (if needed) rebuilds the declaration name.
446 /// Identifiers and selectors are returned unmodified. Sublcasses may
447 /// override this function to provide alternate behavior.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000448 DeclarationNameInfo
John McCall31f82722010-11-12 08:19:04 +0000449 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump11289f42009-09-09 15:08:12 +0000450
Douglas Gregord6ff3322009-08-04 16:50:30 +0000451 /// \brief Transform the given template name.
Mike Stump11289f42009-09-09 15:08:12 +0000452 ///
Douglas Gregor9db53502011-03-02 18:07:45 +0000453 /// \param SS The nested-name-specifier that qualifies the template
454 /// name. This nested-name-specifier must already have been transformed.
455 ///
456 /// \param Name The template name to transform.
457 ///
458 /// \param NameLoc The source location of the template name.
459 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000460 /// \param ObjectType If we're translating a template name within a member
Douglas Gregor9db53502011-03-02 18:07:45 +0000461 /// access expression, this is the type of the object whose member template
462 /// is being referenced.
463 ///
464 /// \param FirstQualifierInScope If the first part of a nested-name-specifier
465 /// also refers to a name within the current (lexical) scope, this is the
466 /// declaration it refers to.
467 ///
468 /// By default, transforms the template name by transforming the declarations
469 /// and nested-name-specifiers that occur within the template name.
470 /// Subclasses may override this function to provide alternate behavior.
471 TemplateName TransformTemplateName(CXXScopeSpec &SS,
472 TemplateName Name,
Abramo Bagnara7945c982012-01-27 09:46:47 +0000473 SourceLocation NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +0000474 QualType ObjectType = QualType(),
475 NamedDecl *FirstQualifierInScope = 0);
476
Douglas Gregord6ff3322009-08-04 16:50:30 +0000477 /// \brief Transform the given template argument.
478 ///
Mike Stump11289f42009-09-09 15:08:12 +0000479 /// By default, this operation transforms the type, expression, or
480 /// declaration stored within the template argument and constructs a
Douglas Gregore922c772009-08-04 22:27:00 +0000481 /// new template argument from the transformed result. Subclasses may
482 /// override this function to provide alternate behavior.
John McCall0ad16662009-10-29 08:12:44 +0000483 ///
484 /// Returns true if there was an error.
485 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
486 TemplateArgumentLoc &Output);
487
Douglas Gregor62e06f22010-12-20 17:31:10 +0000488 /// \brief Transform the given set of template arguments.
489 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000490 /// By default, this operation transforms all of the template arguments
Douglas Gregor62e06f22010-12-20 17:31:10 +0000491 /// in the input set using \c TransformTemplateArgument(), and appends
492 /// the transformed arguments to the output list.
493 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000494 /// Note that this overload of \c TransformTemplateArguments() is merely
495 /// a convenience function. Subclasses that wish to override this behavior
496 /// should override the iterator-based member template version.
497 ///
Douglas Gregor62e06f22010-12-20 17:31:10 +0000498 /// \param Inputs The set of template arguments to be transformed.
499 ///
500 /// \param NumInputs The number of template arguments in \p Inputs.
501 ///
502 /// \param Outputs The set of transformed template arguments output by this
503 /// routine.
504 ///
505 /// Returns true if an error occurred.
506 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
507 unsigned NumInputs,
Douglas Gregorfe921a72010-12-20 23:36:19 +0000508 TemplateArgumentListInfo &Outputs) {
509 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs);
510 }
Douglas Gregor42cafa82010-12-20 17:42:22 +0000511
512 /// \brief Transform the given set of template arguments.
513 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000514 /// By default, this operation transforms all of the template arguments
Douglas Gregor42cafa82010-12-20 17:42:22 +0000515 /// in the input set using \c TransformTemplateArgument(), and appends
Chad Rosier1dcde962012-08-08 18:46:20 +0000516 /// the transformed arguments to the output list.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000517 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000518 /// \param First An iterator to the first template argument.
519 ///
520 /// \param Last An iterator one step past the last template argument.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000521 ///
522 /// \param Outputs The set of transformed template arguments output by this
523 /// routine.
524 ///
525 /// Returns true if an error occurred.
Douglas Gregorfe921a72010-12-20 23:36:19 +0000526 template<typename InputIterator>
527 bool TransformTemplateArguments(InputIterator First,
528 InputIterator Last,
529 TemplateArgumentListInfo &Outputs);
Douglas Gregor42cafa82010-12-20 17:42:22 +0000530
John McCall0ad16662009-10-29 08:12:44 +0000531 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
532 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
533 TemplateArgumentLoc &ArgLoc);
534
John McCallbcd03502009-12-07 02:54:59 +0000535 /// \brief Fakes up a TypeSourceInfo for a type.
536 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
537 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall0ad16662009-10-29 08:12:44 +0000538 getDerived().getBaseLocation());
539 }
Mike Stump11289f42009-09-09 15:08:12 +0000540
John McCall550e0c22009-10-21 00:40:46 +0000541#define ABSTRACT_TYPELOC(CLASS, PARENT)
542#define TYPELOC(CLASS, PARENT) \
John McCall31f82722010-11-12 08:19:04 +0000543 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCall550e0c22009-10-21 00:40:46 +0000544#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +0000545
Douglas Gregor3024f072012-04-16 07:05:22 +0000546 QualType TransformFunctionProtoType(TypeLocBuilder &TLB,
547 FunctionProtoTypeLoc TL,
548 CXXRecordDecl *ThisContext,
549 unsigned ThisTypeQuals);
550
David Majnemerfad8f482013-10-15 09:33:02 +0000551 StmtResult TransformSEHHandler(Stmt *Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +0000552
Chad Rosier1dcde962012-08-08 18:46:20 +0000553 QualType
John McCall31f82722010-11-12 08:19:04 +0000554 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
555 TemplateSpecializationTypeLoc TL,
556 TemplateName Template);
557
Chad Rosier1dcde962012-08-08 18:46:20 +0000558 QualType
John McCall31f82722010-11-12 08:19:04 +0000559 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
560 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +0000561 TemplateName Template,
562 CXXScopeSpec &SS);
Douglas Gregor5a064722011-02-28 17:23:35 +0000563
Chad Rosier1dcde962012-08-08 18:46:20 +0000564 QualType
Douglas Gregor5a064722011-02-28 17:23:35 +0000565 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
Douglas Gregora7a795b2011-03-01 20:11:18 +0000566 DependentTemplateSpecializationTypeLoc TL,
567 NestedNameSpecifierLoc QualifierLoc);
568
John McCall58f10c32010-03-11 09:03:00 +0000569 /// \brief Transforms the parameters of a function type into the
570 /// given vectors.
571 ///
572 /// The result vectors should be kept in sync; null entries in the
573 /// variables vector are acceptable.
574 ///
575 /// Return true on error.
Douglas Gregordd472162011-01-07 00:20:55 +0000576 bool TransformFunctionTypeParams(SourceLocation Loc,
577 ParmVarDecl **Params, unsigned NumParams,
578 const QualType *ParamTypes,
Chris Lattner01cf8db2011-07-20 06:58:45 +0000579 SmallVectorImpl<QualType> &PTypes,
580 SmallVectorImpl<ParmVarDecl*> *PVars);
John McCall58f10c32010-03-11 09:03:00 +0000581
582 /// \brief Transforms a single function-type parameter. Return null
583 /// on error.
John McCall8fb0d9d2011-05-01 22:35:37 +0000584 ///
585 /// \param indexAdjustment - A number to add to the parameter's
586 /// scope index; can be negative
Douglas Gregor715e4612011-01-14 22:40:04 +0000587 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +0000588 int indexAdjustment,
David Blaikie05785d12013-02-20 22:23:23 +0000589 Optional<unsigned> NumExpansions,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +0000590 bool ExpectParameterPack);
John McCall58f10c32010-03-11 09:03:00 +0000591
John McCall31f82722010-11-12 08:19:04 +0000592 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall0ad16662009-10-29 08:12:44 +0000593
John McCalldadc5752010-08-24 06:29:42 +0000594 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
595 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +0000596
597 typedef std::pair<ExprResult, QualType> InitCaptureInfoTy;
Richard Smith2589b9802012-07-25 03:56:55 +0000598 /// \brief Transform the captures and body of a lambda expression.
Faisal Vali5fb7c3c2013-12-05 01:40:41 +0000599 ExprResult TransformLambdaScope(LambdaExpr *E, CXXMethodDecl *CallOperator,
600 ArrayRef<InitCaptureInfoTy> InitCaptureExprsAndTypes);
Richard Smith2589b9802012-07-25 03:56:55 +0000601
Faisal Vali2cba1332013-10-23 06:44:28 +0000602 TemplateParameterList *TransformTemplateParameterList(
603 TemplateParameterList *TPL) {
604 return TPL;
605 }
606
Richard Smithdb2630f2012-10-21 03:28:35 +0000607 ExprResult TransformAddressOfOperand(Expr *E);
608 ExprResult TransformDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E,
609 bool IsAddressOfOperand);
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000610 StmtResult TransformOMPExecutableDirective(OMPExecutableDirective *S);
Richard Smithdb2630f2012-10-21 03:28:35 +0000611
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000612// FIXME: We use LLVM_ATTRIBUTE_NOINLINE because inlining causes a ridiculous
613// amount of stack usage with clang.
Douglas Gregorebe10102009-08-20 07:17:43 +0000614#define STMT(Node, Parent) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000615 LLVM_ATTRIBUTE_NOINLINE \
John McCalldadc5752010-08-24 06:29:42 +0000616 StmtResult Transform##Node(Node *S);
Douglas Gregora16548e2009-08-11 05:31:07 +0000617#define EXPR(Node, Parent) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000618 LLVM_ATTRIBUTE_NOINLINE \
John McCalldadc5752010-08-24 06:29:42 +0000619 ExprResult Transform##Node(Node *E);
Alexis Huntabb2ac82010-05-18 06:22:21 +0000620#define ABSTRACT_STMT(Stmt)
Alexis Hunt656bb312010-05-05 15:24:00 +0000621#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +0000622
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000623#define OPENMP_CLAUSE(Name, Class) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000624 LLVM_ATTRIBUTE_NOINLINE \
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000625 OMPClause *Transform ## Class(Class *S);
626#include "clang/Basic/OpenMPKinds.def"
627
Douglas Gregord6ff3322009-08-04 16:50:30 +0000628 /// \brief Build a new pointer type given its pointee type.
629 ///
630 /// By default, performs semantic analysis when building the pointer type.
631 /// Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000632 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000633
634 /// \brief Build a new block pointer type given its pointee type.
635 ///
Mike Stump11289f42009-09-09 15:08:12 +0000636 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000637 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000638 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000639
John McCall70dd5f62009-10-30 00:06:24 +0000640 /// \brief Build a new reference type given the type it references.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000641 ///
John McCall70dd5f62009-10-30 00:06:24 +0000642 /// By default, performs semantic analysis when building the
643 /// reference type. Subclasses may override this routine to provide
644 /// different behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000645 ///
John McCall70dd5f62009-10-30 00:06:24 +0000646 /// \param LValue whether the type was written with an lvalue sigil
647 /// or an rvalue sigil.
648 QualType RebuildReferenceType(QualType ReferentType,
649 bool LValue,
650 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000651
Douglas Gregord6ff3322009-08-04 16:50:30 +0000652 /// \brief Build a new member pointer type given the pointee type and the
653 /// class type it refers into.
654 ///
655 /// By default, performs semantic analysis when building the member pointer
656 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000657 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
658 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000659
Douglas Gregord6ff3322009-08-04 16:50:30 +0000660 /// \brief Build a new array type given the element type, size
661 /// modifier, size of the array (if known), size expression, and index type
662 /// qualifiers.
663 ///
664 /// By default, performs semantic analysis when building the array type.
665 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000666 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-08-04 16:50:30 +0000667 QualType RebuildArrayType(QualType ElementType,
668 ArrayType::ArraySizeModifier SizeMod,
669 const llvm::APInt *Size,
670 Expr *SizeExpr,
671 unsigned IndexTypeQuals,
672 SourceRange BracketsRange);
Mike Stump11289f42009-09-09 15:08:12 +0000673
Douglas Gregord6ff3322009-08-04 16:50:30 +0000674 /// \brief Build a new constant array type given the element type, size
675 /// modifier, (known) size of the array, and index type qualifiers.
676 ///
677 /// By default, performs semantic analysis when building the array type.
678 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000679 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000680 ArrayType::ArraySizeModifier SizeMod,
681 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +0000682 unsigned IndexTypeQuals,
683 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000684
Douglas Gregord6ff3322009-08-04 16:50:30 +0000685 /// \brief Build a new incomplete array type given the element type, size
686 /// modifier, and index type qualifiers.
687 ///
688 /// By default, performs semantic analysis when building the array type.
689 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000690 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000691 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +0000692 unsigned IndexTypeQuals,
693 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000694
Mike Stump11289f42009-09-09 15:08:12 +0000695 /// \brief Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000696 /// size modifier, size expression, and index type qualifiers.
697 ///
698 /// By default, performs semantic analysis when building the array type.
699 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000700 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000701 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000702 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000703 unsigned IndexTypeQuals,
704 SourceRange BracketsRange);
705
Mike Stump11289f42009-09-09 15:08:12 +0000706 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000707 /// size modifier, size expression, and index type qualifiers.
708 ///
709 /// By default, performs semantic analysis when building the array type.
710 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000711 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000712 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000713 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000714 unsigned IndexTypeQuals,
715 SourceRange BracketsRange);
716
717 /// \brief Build a new vector type given the element type and
718 /// number of elements.
719 ///
720 /// By default, performs semantic analysis when building the vector type.
721 /// Subclasses may override this routine to provide different behavior.
John Thompson22334602010-02-05 00:12:22 +0000722 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsonaeb56442010-11-10 21:56:12 +0000723 VectorType::VectorKind VecKind);
Mike Stump11289f42009-09-09 15:08:12 +0000724
Douglas Gregord6ff3322009-08-04 16:50:30 +0000725 /// \brief Build a new extended vector type given the element type and
726 /// number of elements.
727 ///
728 /// By default, performs semantic analysis when building the vector type.
729 /// Subclasses may override this routine to provide different behavior.
730 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
731 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000732
733 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000734 /// given the element type and number of elements.
735 ///
736 /// By default, performs semantic analysis when building the vector type.
737 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000738 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +0000739 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000740 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000741
Douglas Gregord6ff3322009-08-04 16:50:30 +0000742 /// \brief Build a new function type.
743 ///
744 /// By default, performs semantic analysis when building the function type.
745 /// Subclasses may override this routine to provide different behavior.
746 QualType RebuildFunctionProtoType(QualType T,
Jordan Rose5c382722013-03-08 21:51:21 +0000747 llvm::MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +0000748 const FunctionProtoType::ExtProtoInfo &EPI);
Mike Stump11289f42009-09-09 15:08:12 +0000749
John McCall550e0c22009-10-21 00:40:46 +0000750 /// \brief Build a new unprototyped function type.
751 QualType RebuildFunctionNoProtoType(QualType ResultType);
752
John McCallb96ec562009-12-04 22:46:56 +0000753 /// \brief Rebuild an unresolved typename type, given the decl that
754 /// the UnresolvedUsingTypenameDecl was transformed to.
755 QualType RebuildUnresolvedUsingType(Decl *D);
756
Douglas Gregord6ff3322009-08-04 16:50:30 +0000757 /// \brief Build a new typedef type.
Richard Smithdda56e42011-04-15 14:24:37 +0000758 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
Douglas Gregord6ff3322009-08-04 16:50:30 +0000759 return SemaRef.Context.getTypeDeclType(Typedef);
760 }
761
762 /// \brief Build a new class/struct/union type.
763 QualType RebuildRecordType(RecordDecl *Record) {
764 return SemaRef.Context.getTypeDeclType(Record);
765 }
766
767 /// \brief Build a new Enum type.
768 QualType RebuildEnumType(EnumDecl *Enum) {
769 return SemaRef.Context.getTypeDeclType(Enum);
770 }
John McCallfcc33b02009-09-05 00:15:47 +0000771
Mike Stump11289f42009-09-09 15:08:12 +0000772 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000773 ///
774 /// By default, performs semantic analysis when building the typeof type.
775 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000776 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000777
Mike Stump11289f42009-09-09 15:08:12 +0000778 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000779 ///
780 /// By default, builds a new TypeOfType with the given underlying type.
781 QualType RebuildTypeOfType(QualType Underlying);
782
Alexis Hunte852b102011-05-24 22:41:36 +0000783 /// \brief Build a new unary transform type.
784 QualType RebuildUnaryTransformType(QualType BaseType,
785 UnaryTransformType::UTTKind UKind,
786 SourceLocation Loc);
787
Richard Smith74aeef52013-04-26 16:15:35 +0000788 /// \brief Build a new C++11 decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000789 ///
790 /// By default, performs semantic analysis when building the decltype type.
791 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000792 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump11289f42009-09-09 15:08:12 +0000793
Richard Smith74aeef52013-04-26 16:15:35 +0000794 /// \brief Build a new C++11 auto type.
Richard Smith30482bc2011-02-20 03:19:35 +0000795 ///
796 /// By default, builds a new AutoType with the given deduced type.
Richard Smith74aeef52013-04-26 16:15:35 +0000797 QualType RebuildAutoType(QualType Deduced, bool IsDecltypeAuto) {
Richard Smith27d807c2013-04-30 13:56:41 +0000798 // Note, IsDependent is always false here: we implicitly convert an 'auto'
799 // which has been deduced to a dependent type into an undeduced 'auto', so
800 // that we'll retry deduction after the transformation.
Faisal Vali2b391ab2013-09-26 19:54:12 +0000801 return SemaRef.Context.getAutoType(Deduced, IsDecltypeAuto,
802 /*IsDependent*/ false);
Richard Smith30482bc2011-02-20 03:19:35 +0000803 }
804
Douglas Gregord6ff3322009-08-04 16:50:30 +0000805 /// \brief Build a new template specialization type.
806 ///
807 /// By default, performs semantic analysis when building the template
808 /// specialization type. Subclasses may override this routine to provide
809 /// different behavior.
810 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000811 SourceLocation TemplateLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000812 TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000813
Abramo Bagnara924a8f32010-12-10 16:29:40 +0000814 /// \brief Build a new parenthesized type.
815 ///
816 /// By default, builds a new ParenType type from the inner type.
817 /// Subclasses may override this routine to provide different behavior.
818 QualType RebuildParenType(QualType InnerType) {
819 return SemaRef.Context.getParenType(InnerType);
820 }
821
Douglas Gregord6ff3322009-08-04 16:50:30 +0000822 /// \brief Build a new qualified name type.
823 ///
Abramo Bagnara6150c882010-05-11 21:36:43 +0000824 /// By default, builds a new ElaboratedType type from the keyword,
825 /// the nested-name-specifier and the named type.
826 /// Subclasses may override this routine to provide different behavior.
John McCall954b5de2010-11-04 19:04:38 +0000827 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
828 ElaboratedTypeKeyword Keyword,
Douglas Gregor844cb502011-03-01 18:12:44 +0000829 NestedNameSpecifierLoc QualifierLoc,
830 QualType Named) {
Chad Rosier1dcde962012-08-08 18:46:20 +0000831 return SemaRef.Context.getElaboratedType(Keyword,
832 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor844cb502011-03-01 18:12:44 +0000833 Named);
Mike Stump11289f42009-09-09 15:08:12 +0000834 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000835
836 /// \brief Build a new typename type that refers to a template-id.
837 ///
Abramo Bagnarad7548482010-05-19 21:37:53 +0000838 /// By default, builds a new DependentNameType type from the
839 /// nested-name-specifier and the given type. Subclasses may override
840 /// this routine to provide different behavior.
John McCallc392f372010-06-11 00:33:02 +0000841 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregora7a795b2011-03-01 20:11:18 +0000842 ElaboratedTypeKeyword Keyword,
843 NestedNameSpecifierLoc QualifierLoc,
844 const IdentifierInfo *Name,
845 SourceLocation NameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000846 TemplateArgumentListInfo &Args) {
Douglas Gregora7a795b2011-03-01 20:11:18 +0000847 // Rebuild the template name.
848 // TODO: avoid TemplateName abstraction
Douglas Gregor9db53502011-03-02 18:07:45 +0000849 CXXScopeSpec SS;
850 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +0000851 TemplateName InstName
Douglas Gregor9db53502011-03-02 18:07:45 +0000852 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(), 0);
Chad Rosier1dcde962012-08-08 18:46:20 +0000853
Douglas Gregora7a795b2011-03-01 20:11:18 +0000854 if (InstName.isNull())
855 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +0000856
Douglas Gregora7a795b2011-03-01 20:11:18 +0000857 // If it's still dependent, make a dependent specialization.
858 if (InstName.getAsDependentTemplateName())
Chad Rosier1dcde962012-08-08 18:46:20 +0000859 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
860 QualifierLoc.getNestedNameSpecifier(),
861 Name,
Douglas Gregora7a795b2011-03-01 20:11:18 +0000862 Args);
Chad Rosier1dcde962012-08-08 18:46:20 +0000863
Douglas Gregora7a795b2011-03-01 20:11:18 +0000864 // Otherwise, make an elaborated type wrapping a non-dependent
865 // specialization.
866 QualType T =
867 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
868 if (T.isNull()) return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +0000869
Douglas Gregora7a795b2011-03-01 20:11:18 +0000870 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == 0)
871 return T;
Chad Rosier1dcde962012-08-08 18:46:20 +0000872
873 return SemaRef.Context.getElaboratedType(Keyword,
874 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregora7a795b2011-03-01 20:11:18 +0000875 T);
876 }
877
Douglas Gregord6ff3322009-08-04 16:50:30 +0000878 /// \brief Build a new typename type that refers to an identifier.
879 ///
880 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarad7548482010-05-19 21:37:53 +0000881 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000882 /// different behavior.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000883 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000884 SourceLocation KeywordLoc,
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000885 NestedNameSpecifierLoc QualifierLoc,
886 const IdentifierInfo *Id,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000887 SourceLocation IdLoc) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000888 CXXScopeSpec SS;
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000889 SS.Adopt(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +0000890
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000891 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000892 // If the name is still dependent, just build a new dependent name type.
893 if (!SemaRef.computeDeclContext(SS))
Chad Rosier1dcde962012-08-08 18:46:20 +0000894 return SemaRef.Context.getDependentNameType(Keyword,
895 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000896 Id);
Douglas Gregore677daf2010-03-31 22:19:08 +0000897 }
898
Abramo Bagnara6150c882010-05-11 21:36:43 +0000899 if (Keyword == ETK_None || Keyword == ETK_Typename)
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000900 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
Douglas Gregor9cbc22b2011-02-28 22:42:13 +0000901 *Id, IdLoc);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000902
903 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
904
Abramo Bagnarad7548482010-05-19 21:37:53 +0000905 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregore677daf2010-03-31 22:19:08 +0000906 // into a non-dependent elaborated-type-specifier. Find the tag we're
907 // referring to.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000908 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregore677daf2010-03-31 22:19:08 +0000909 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
910 if (!DC)
911 return QualType();
912
John McCallbf8c5192010-05-27 06:40:31 +0000913 if (SemaRef.RequireCompleteDeclContext(SS, DC))
914 return QualType();
915
Douglas Gregore677daf2010-03-31 22:19:08 +0000916 TagDecl *Tag = 0;
917 SemaRef.LookupQualifiedName(Result, DC);
918 switch (Result.getResultKind()) {
919 case LookupResult::NotFound:
920 case LookupResult::NotFoundInCurrentInstantiation:
921 break;
Chad Rosier1dcde962012-08-08 18:46:20 +0000922
Douglas Gregore677daf2010-03-31 22:19:08 +0000923 case LookupResult::Found:
924 Tag = Result.getAsSingle<TagDecl>();
925 break;
Chad Rosier1dcde962012-08-08 18:46:20 +0000926
Douglas Gregore677daf2010-03-31 22:19:08 +0000927 case LookupResult::FoundOverloaded:
928 case LookupResult::FoundUnresolvedValue:
929 llvm_unreachable("Tag lookup cannot find non-tags");
Chad Rosier1dcde962012-08-08 18:46:20 +0000930
Douglas Gregore677daf2010-03-31 22:19:08 +0000931 case LookupResult::Ambiguous:
932 // Let the LookupResult structure handle ambiguities.
933 return QualType();
934 }
935
936 if (!Tag) {
Nick Lewycky0c438082011-01-24 19:01:04 +0000937 // Check where the name exists but isn't a tag type and use that to emit
938 // better diagnostics.
939 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
940 SemaRef.LookupQualifiedName(Result, DC);
941 switch (Result.getResultKind()) {
942 case LookupResult::Found:
943 case LookupResult::FoundOverloaded:
944 case LookupResult::FoundUnresolvedValue: {
Richard Smith3f1b5d02011-05-05 21:57:07 +0000945 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
Nick Lewycky0c438082011-01-24 19:01:04 +0000946 unsigned Kind = 0;
947 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
Richard Smithdda56e42011-04-15 14:24:37 +0000948 else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2;
949 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3;
Nick Lewycky0c438082011-01-24 19:01:04 +0000950 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
951 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
952 break;
Richard Smith3f1b5d02011-05-05 21:57:07 +0000953 }
Nick Lewycky0c438082011-01-24 19:01:04 +0000954 default:
955 // FIXME: Would be nice to highlight just the source range.
956 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
957 << Kind << Id << DC;
958 break;
959 }
Douglas Gregore677daf2010-03-31 22:19:08 +0000960 return QualType();
961 }
Abramo Bagnara6150c882010-05-11 21:36:43 +0000962
Richard Trieucaa33d32011-06-10 03:11:26 +0000963 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
964 IdLoc, *Id)) {
Abramo Bagnarad7548482010-05-19 21:37:53 +0000965 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregore677daf2010-03-31 22:19:08 +0000966 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
967 return QualType();
968 }
969
970 // Build the elaborated-type-specifier type.
971 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Chad Rosier1dcde962012-08-08 18:46:20 +0000972 return SemaRef.Context.getElaboratedType(Keyword,
973 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000974 T);
Douglas Gregor1135c352009-08-06 05:28:30 +0000975 }
Mike Stump11289f42009-09-09 15:08:12 +0000976
Douglas Gregor822d0302011-01-12 17:07:58 +0000977 /// \brief Build a new pack expansion type.
978 ///
979 /// By default, builds a new PackExpansionType type from the given pattern.
980 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000981 QualType RebuildPackExpansionType(QualType Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +0000982 SourceRange PatternRange,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000983 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +0000984 Optional<unsigned> NumExpansions) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000985 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
986 NumExpansions);
Douglas Gregor822d0302011-01-12 17:07:58 +0000987 }
988
Eli Friedman0dfb8892011-10-06 23:00:33 +0000989 /// \brief Build a new atomic type given its value type.
990 ///
991 /// By default, performs semantic analysis when building the atomic type.
992 /// Subclasses may override this routine to provide different behavior.
993 QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
994
Douglas Gregor71dc5092009-08-06 06:41:21 +0000995 /// \brief Build a new template name given a nested name specifier, a flag
996 /// indicating whether the "template" keyword was provided, and the template
997 /// that the template name refers to.
998 ///
999 /// By default, builds the new template name directly. Subclasses may override
1000 /// this routine to provide different behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001001 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +00001002 bool TemplateKW,
1003 TemplateDecl *Template);
1004
Douglas Gregor71dc5092009-08-06 06:41:21 +00001005 /// \brief Build a new template name given a nested name specifier and the
1006 /// name that is referred to as a template.
1007 ///
1008 /// By default, performs semantic analysis to determine whether the name can
1009 /// be resolved to a specific template, then builds the appropriate kind of
1010 /// template name. Subclasses may override this routine to provide different
1011 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001012 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
1013 const IdentifierInfo &Name,
1014 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +00001015 QualType ObjectType,
1016 NamedDecl *FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00001017
Douglas Gregor71395fa2009-11-04 00:56:37 +00001018 /// \brief Build a new template name given a nested name specifier and the
1019 /// overloaded operator name that is referred to as a template.
1020 ///
1021 /// By default, performs semantic analysis to determine whether the name can
1022 /// be resolved to a specific template, then builds the appropriate kind of
1023 /// template name. Subclasses may override this routine to provide different
1024 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001025 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +00001026 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +00001027 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +00001028 QualType ObjectType);
Douglas Gregor5590be02011-01-15 06:45:20 +00001029
1030 /// \brief Build a new template name given a template template parameter pack
Chad Rosier1dcde962012-08-08 18:46:20 +00001031 /// and the
Douglas Gregor5590be02011-01-15 06:45:20 +00001032 ///
1033 /// By default, performs semantic analysis to determine whether the name can
1034 /// be resolved to a specific template, then builds the appropriate kind of
1035 /// template name. Subclasses may override this routine to provide different
1036 /// behavior.
1037 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
1038 const TemplateArgument &ArgPack) {
1039 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
1040 }
1041
Douglas Gregorebe10102009-08-20 07:17:43 +00001042 /// \brief Build a new compound statement.
1043 ///
1044 /// By default, performs semantic analysis to build the new statement.
1045 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001046 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001047 MultiStmtArg Statements,
1048 SourceLocation RBraceLoc,
1049 bool IsStmtExpr) {
John McCallb268a282010-08-23 23:25:46 +00001050 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00001051 IsStmtExpr);
1052 }
1053
1054 /// \brief Build a new case statement.
1055 ///
1056 /// By default, performs semantic analysis to build the new statement.
1057 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001058 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCallb268a282010-08-23 23:25:46 +00001059 Expr *LHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001060 SourceLocation EllipsisLoc,
John McCallb268a282010-08-23 23:25:46 +00001061 Expr *RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001062 SourceLocation ColonLoc) {
John McCallb268a282010-08-23 23:25:46 +00001063 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001064 ColonLoc);
1065 }
Mike Stump11289f42009-09-09 15:08:12 +00001066
Douglas Gregorebe10102009-08-20 07:17:43 +00001067 /// \brief Attach the body to a new case statement.
1068 ///
1069 /// By default, performs semantic analysis to build the new statement.
1070 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001071 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001072 getSema().ActOnCaseStmtBody(S, Body);
1073 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00001074 }
Mike Stump11289f42009-09-09 15:08:12 +00001075
Douglas Gregorebe10102009-08-20 07:17:43 +00001076 /// \brief Build a new default statement.
1077 ///
1078 /// By default, performs semantic analysis to build the new statement.
1079 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001080 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001081 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +00001082 Stmt *SubStmt) {
1083 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregorebe10102009-08-20 07:17:43 +00001084 /*CurScope=*/0);
1085 }
Mike Stump11289f42009-09-09 15:08:12 +00001086
Douglas Gregorebe10102009-08-20 07:17:43 +00001087 /// \brief Build a new label statement.
1088 ///
1089 /// By default, performs semantic analysis to build the new statement.
1090 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001091 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1092 SourceLocation ColonLoc, Stmt *SubStmt) {
1093 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregorebe10102009-08-20 07:17:43 +00001094 }
Mike Stump11289f42009-09-09 15:08:12 +00001095
Richard Smithc202b282012-04-14 00:33:13 +00001096 /// \brief Build a new label statement.
1097 ///
1098 /// By default, performs semantic analysis to build the new statement.
1099 /// Subclasses may override this routine to provide different behavior.
Alexander Kornienko20f6fc62012-07-09 10:04:07 +00001100 StmtResult RebuildAttributedStmt(SourceLocation AttrLoc,
1101 ArrayRef<const Attr*> Attrs,
Richard Smithc202b282012-04-14 00:33:13 +00001102 Stmt *SubStmt) {
1103 return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt);
1104 }
1105
Douglas Gregorebe10102009-08-20 07:17:43 +00001106 /// \brief Build a new "if" statement.
1107 ///
1108 /// By default, performs semantic analysis to build the new statement.
1109 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001110 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Chad Rosier1dcde962012-08-08 18:46:20 +00001111 VarDecl *CondVar, Stmt *Then,
Chris Lattnercab02a62011-02-17 20:34:02 +00001112 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00001113 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregorebe10102009-08-20 07:17:43 +00001114 }
Mike Stump11289f42009-09-09 15:08:12 +00001115
Douglas Gregorebe10102009-08-20 07:17:43 +00001116 /// \brief Start building a new switch statement.
1117 ///
1118 /// By default, performs semantic analysis to build the new statement.
1119 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001120 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001121 Expr *Cond, VarDecl *CondVar) {
Chad Rosier1dcde962012-08-08 18:46:20 +00001122 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCall48871652010-08-21 09:40:31 +00001123 CondVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00001124 }
Mike Stump11289f42009-09-09 15:08:12 +00001125
Douglas Gregorebe10102009-08-20 07:17:43 +00001126 /// \brief Attach the body to the switch statement.
1127 ///
1128 /// By default, performs semantic analysis to build the new statement.
1129 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001130 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001131 Stmt *Switch, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001132 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001133 }
1134
1135 /// \brief Build a new while statement.
1136 ///
1137 /// By default, performs semantic analysis to build the new statement.
1138 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001139 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1140 VarDecl *CondVar, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001141 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001142 }
Mike Stump11289f42009-09-09 15:08:12 +00001143
Douglas Gregorebe10102009-08-20 07:17:43 +00001144 /// \brief Build a new do-while statement.
1145 ///
1146 /// By default, performs semantic analysis to build the new statement.
1147 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001148 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001149 SourceLocation WhileLoc, SourceLocation LParenLoc,
1150 Expr *Cond, SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001151 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1152 Cond, RParenLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001153 }
1154
1155 /// \brief Build a new for statement.
1156 ///
1157 /// By default, performs semantic analysis to build the new statement.
1158 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001159 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
Chad Rosier1dcde962012-08-08 18:46:20 +00001160 Stmt *Init, Sema::FullExprArg Cond,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001161 VarDecl *CondVar, Sema::FullExprArg Inc,
1162 SourceLocation RParenLoc, Stmt *Body) {
Chad Rosier1dcde962012-08-08 18:46:20 +00001163 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001164 CondVar, Inc, RParenLoc, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001165 }
Mike Stump11289f42009-09-09 15:08:12 +00001166
Douglas Gregorebe10102009-08-20 07:17:43 +00001167 /// \brief Build a new goto statement.
1168 ///
1169 /// By default, performs semantic analysis to build the new statement.
1170 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001171 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1172 LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001173 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregorebe10102009-08-20 07:17:43 +00001174 }
1175
1176 /// \brief Build a new indirect goto statement.
1177 ///
1178 /// By default, performs semantic analysis to build the new statement.
1179 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001180 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001181 SourceLocation StarLoc,
1182 Expr *Target) {
John McCallb268a282010-08-23 23:25:46 +00001183 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregorebe10102009-08-20 07:17:43 +00001184 }
Mike Stump11289f42009-09-09 15:08:12 +00001185
Douglas Gregorebe10102009-08-20 07:17:43 +00001186 /// \brief Build a new return statement.
1187 ///
1188 /// By default, performs semantic analysis to build the new statement.
1189 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001190 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
John McCallb268a282010-08-23 23:25:46 +00001191 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregorebe10102009-08-20 07:17:43 +00001192 }
Mike Stump11289f42009-09-09 15:08:12 +00001193
Douglas Gregorebe10102009-08-20 07:17:43 +00001194 /// \brief Build a new declaration statement.
1195 ///
1196 /// By default, performs semantic analysis to build the new statement.
1197 /// Subclasses may override this routine to provide different behavior.
Rafael Espindolaab417692013-07-09 12:05:01 +00001198 StmtResult RebuildDeclStmt(llvm::MutableArrayRef<Decl *> Decls,
1199 SourceLocation StartLoc, SourceLocation EndLoc) {
1200 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls);
Richard Smith2abf6762011-02-23 00:37:57 +00001201 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001202 }
Mike Stump11289f42009-09-09 15:08:12 +00001203
Anders Carlssonaaeef072010-01-24 05:50:09 +00001204 /// \brief Build a new inline asm statement.
1205 ///
1206 /// By default, performs semantic analysis to build the new statement.
1207 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001208 StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
1209 bool IsVolatile, unsigned NumOutputs,
1210 unsigned NumInputs, IdentifierInfo **Names,
1211 MultiExprArg Constraints, MultiExprArg Exprs,
1212 Expr *AsmString, MultiExprArg Clobbers,
1213 SourceLocation RParenLoc) {
1214 return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1215 NumInputs, Names, Constraints, Exprs,
1216 AsmString, Clobbers, RParenLoc);
Anders Carlssonaaeef072010-01-24 05:50:09 +00001217 }
Douglas Gregor306de2f2010-04-22 23:59:56 +00001218
Chad Rosier32503022012-06-11 20:47:18 +00001219 /// \brief Build a new MS style inline asm statement.
1220 ///
1221 /// By default, performs semantic analysis to build the new statement.
1222 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001223 StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc,
John McCallf413f5e2013-05-03 00:10:13 +00001224 ArrayRef<Token> AsmToks,
1225 StringRef AsmString,
1226 unsigned NumOutputs, unsigned NumInputs,
1227 ArrayRef<StringRef> Constraints,
1228 ArrayRef<StringRef> Clobbers,
1229 ArrayRef<Expr*> Exprs,
1230 SourceLocation EndLoc) {
1231 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString,
1232 NumOutputs, NumInputs,
1233 Constraints, Clobbers, Exprs, EndLoc);
Chad Rosier32503022012-06-11 20:47:18 +00001234 }
1235
James Dennett2a4d13c2012-06-15 07:13:21 +00001236 /// \brief Build a new Objective-C \@try statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001237 ///
1238 /// By default, performs semantic analysis to build the new statement.
1239 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001240 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001241 Stmt *TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +00001242 MultiStmtArg CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001243 Stmt *Finally) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001244 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001245 Finally);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001246 }
1247
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001248 /// \brief Rebuild an Objective-C exception declaration.
1249 ///
1250 /// By default, performs semantic analysis to build the new declaration.
1251 /// Subclasses may override this routine to provide different behavior.
1252 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1253 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaradff19302011-03-08 08:55:46 +00001254 return getSema().BuildObjCExceptionDecl(TInfo, T,
1255 ExceptionDecl->getInnerLocStart(),
1256 ExceptionDecl->getLocation(),
1257 ExceptionDecl->getIdentifier());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001258 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001259
James Dennett2a4d13c2012-06-15 07:13:21 +00001260 /// \brief Build a new Objective-C \@catch statement.
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001261 ///
1262 /// By default, performs semantic analysis to build the new statement.
1263 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001264 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001265 SourceLocation RParenLoc,
1266 VarDecl *Var,
John McCallb268a282010-08-23 23:25:46 +00001267 Stmt *Body) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001268 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001269 Var, Body);
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001270 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001271
James Dennett2a4d13c2012-06-15 07:13:21 +00001272 /// \brief Build a new Objective-C \@finally statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001273 ///
1274 /// By default, performs semantic analysis to build the new statement.
1275 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001276 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001277 Stmt *Body) {
1278 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001279 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001280
James Dennett2a4d13c2012-06-15 07:13:21 +00001281 /// \brief Build a new Objective-C \@throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +00001282 ///
1283 /// By default, performs semantic analysis to build the new statement.
1284 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001285 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001286 Expr *Operand) {
1287 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregor2900c162010-04-22 21:44:01 +00001288 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001289
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001290 /// \brief Build a new OpenMP executable directive.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001291 ///
1292 /// By default, performs semantic analysis to build the new statement.
1293 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001294 StmtResult RebuildOMPExecutableDirective(OpenMPDirectiveKind Kind,
1295 ArrayRef<OMPClause *> Clauses,
1296 Stmt *AStmt,
1297 SourceLocation StartLoc,
1298 SourceLocation EndLoc) {
1299 return getSema().ActOnOpenMPExecutableDirective(Kind, Clauses, AStmt,
1300 StartLoc, EndLoc);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001301 }
1302
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001303 /// \brief Build a new OpenMP 'if' clause.
1304 ///
1305 /// By default, performs semantic analysis to build the new statement.
1306 /// Subclasses may override this routine to provide different behavior.
1307 OMPClause *RebuildOMPIfClause(Expr *Condition,
1308 SourceLocation StartLoc,
1309 SourceLocation LParenLoc,
1310 SourceLocation EndLoc) {
1311 return getSema().ActOnOpenMPIfClause(Condition, StartLoc,
1312 LParenLoc, EndLoc);
1313 }
1314
Alexey Bataev568a8332014-03-06 06:15:19 +00001315 /// \brief Build a new OpenMP 'num_threads' clause.
1316 ///
1317 /// By default, performs semantic analysis to build the new statement.
1318 /// Subclasses may override this routine to provide different behavior.
1319 OMPClause *RebuildOMPNumThreadsClause(Expr *NumThreads,
1320 SourceLocation StartLoc,
1321 SourceLocation LParenLoc,
1322 SourceLocation EndLoc) {
1323 return getSema().ActOnOpenMPNumThreadsClause(NumThreads, StartLoc,
1324 LParenLoc, EndLoc);
1325 }
1326
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001327 /// \brief Build a new OpenMP 'default' clause.
1328 ///
1329 /// By default, performs semantic analysis to build the new statement.
1330 /// Subclasses may override this routine to provide different behavior.
1331 OMPClause *RebuildOMPDefaultClause(OpenMPDefaultClauseKind Kind,
1332 SourceLocation KindKwLoc,
1333 SourceLocation StartLoc,
1334 SourceLocation LParenLoc,
1335 SourceLocation EndLoc) {
1336 return getSema().ActOnOpenMPDefaultClause(Kind, KindKwLoc,
1337 StartLoc, LParenLoc, EndLoc);
1338 }
1339
1340 /// \brief Build a new OpenMP 'private' clause.
1341 ///
1342 /// By default, performs semantic analysis to build the new statement.
1343 /// Subclasses may override this routine to provide different behavior.
1344 OMPClause *RebuildOMPPrivateClause(ArrayRef<Expr *> VarList,
1345 SourceLocation StartLoc,
1346 SourceLocation LParenLoc,
1347 SourceLocation EndLoc) {
1348 return getSema().ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc,
1349 EndLoc);
1350 }
1351
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001352 /// \brief Build a new OpenMP 'firstprivate' clause.
1353 ///
1354 /// By default, performs semantic analysis to build the new statement.
1355 /// Subclasses may override this routine to provide different behavior.
1356 OMPClause *RebuildOMPFirstprivateClause(ArrayRef<Expr *> VarList,
1357 SourceLocation StartLoc,
1358 SourceLocation LParenLoc,
1359 SourceLocation EndLoc) {
1360 return getSema().ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc,
1361 EndLoc);
1362 }
1363
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001364 /// \brief Build a new OpenMP 'shared' clause.
1365 ///
1366 /// By default, performs semantic analysis to build the new statement.
1367 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev758e55e2013-09-06 18:03:48 +00001368 OMPClause *RebuildOMPSharedClause(ArrayRef<Expr *> VarList,
1369 SourceLocation StartLoc,
1370 SourceLocation LParenLoc,
1371 SourceLocation EndLoc) {
1372 return getSema().ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc,
1373 EndLoc);
1374 }
1375
James Dennett2a4d13c2012-06-15 07:13:21 +00001376 /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
John McCalld9bb7432011-07-27 21:50:02 +00001377 ///
1378 /// By default, performs semantic analysis to build the new statement.
1379 /// Subclasses may override this routine to provide different behavior.
1380 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1381 Expr *object) {
1382 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1383 }
1384
James Dennett2a4d13c2012-06-15 07:13:21 +00001385 /// \brief Build a new Objective-C \@synchronized statement.
Douglas Gregor6148de72010-04-22 22:01:21 +00001386 ///
Douglas Gregor6148de72010-04-22 22:01:21 +00001387 /// By default, performs semantic analysis to build the new statement.
1388 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001389 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCalld9bb7432011-07-27 21:50:02 +00001390 Expr *Object, Stmt *Body) {
1391 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor6148de72010-04-22 22:01:21 +00001392 }
Douglas Gregorf68a5082010-04-22 23:10:45 +00001393
James Dennett2a4d13c2012-06-15 07:13:21 +00001394 /// \brief Build a new Objective-C \@autoreleasepool statement.
John McCall31168b02011-06-15 23:02:42 +00001395 ///
1396 /// By default, performs semantic analysis to build the new statement.
1397 /// Subclasses may override this routine to provide different behavior.
1398 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1399 Stmt *Body) {
1400 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1401 }
John McCall53848232011-07-27 01:07:15 +00001402
Douglas Gregorf68a5082010-04-22 23:10:45 +00001403 /// \brief Build a new Objective-C fast enumeration statement.
1404 ///
1405 /// By default, performs semantic analysis to build the new statement.
1406 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001407 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001408 Stmt *Element,
1409 Expr *Collection,
1410 SourceLocation RParenLoc,
1411 Stmt *Body) {
Sam Panzer2c4ca0f2012-08-16 21:47:25 +00001412 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001413 Element,
John McCallb268a282010-08-23 23:25:46 +00001414 Collection,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001415 RParenLoc);
1416 if (ForEachStmt.isInvalid())
1417 return StmtError();
1418
1419 return getSema().FinishObjCForCollectionStmt(ForEachStmt.take(), Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +00001420 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001421
Douglas Gregorebe10102009-08-20 07:17:43 +00001422 /// \brief Build a new C++ exception declaration.
1423 ///
1424 /// By default, performs semantic analysis to build the new decaration.
1425 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaradff19302011-03-08 08:55:46 +00001426 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +00001427 TypeSourceInfo *Declarator,
Abramo Bagnaradff19302011-03-08 08:55:46 +00001428 SourceLocation StartLoc,
1429 SourceLocation IdLoc,
1430 IdentifierInfo *Id) {
Douglas Gregor40965fa2011-04-14 22:32:28 +00001431 VarDecl *Var = getSema().BuildExceptionDeclaration(0, Declarator,
1432 StartLoc, IdLoc, Id);
1433 if (Var)
1434 getSema().CurContext->addDecl(Var);
1435 return Var;
Douglas Gregorebe10102009-08-20 07:17:43 +00001436 }
1437
1438 /// \brief Build a new C++ catch statement.
1439 ///
1440 /// By default, performs semantic analysis to build the new statement.
1441 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001442 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001443 VarDecl *ExceptionDecl,
1444 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00001445 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1446 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00001447 }
Mike Stump11289f42009-09-09 15:08:12 +00001448
Douglas Gregorebe10102009-08-20 07:17:43 +00001449 /// \brief Build a new C++ try statement.
1450 ///
1451 /// By default, performs semantic analysis to build the new statement.
1452 /// Subclasses may override this routine to provide different behavior.
Robert Wilhelmcafda822013-08-22 09:20:03 +00001453 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock,
1454 ArrayRef<Stmt *> Handlers) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001455 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00001456 }
Mike Stump11289f42009-09-09 15:08:12 +00001457
Richard Smith02e85f32011-04-14 22:09:26 +00001458 /// \brief Build a new C++0x range-based for statement.
1459 ///
1460 /// By default, performs semantic analysis to build the new statement.
1461 /// Subclasses may override this routine to provide different behavior.
1462 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1463 SourceLocation ColonLoc,
1464 Stmt *Range, Stmt *BeginEnd,
1465 Expr *Cond, Expr *Inc,
1466 Stmt *LoopVar,
1467 SourceLocation RParenLoc) {
Douglas Gregorf7106af2013-04-08 18:40:13 +00001468 // If we've just learned that the range is actually an Objective-C
1469 // collection, treat this as an Objective-C fast enumeration loop.
1470 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
1471 if (RangeStmt->isSingleDecl()) {
1472 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
Douglas Gregor39aaeef2013-05-02 18:35:56 +00001473 if (RangeVar->isInvalidDecl())
1474 return StmtError();
1475
Douglas Gregorf7106af2013-04-08 18:40:13 +00001476 Expr *RangeExpr = RangeVar->getInit();
1477 if (!RangeExpr->isTypeDependent() &&
1478 RangeExpr->getType()->isObjCObjectPointerType())
1479 return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, RangeExpr,
1480 RParenLoc);
1481 }
1482 }
1483 }
1484
Richard Smith02e85f32011-04-14 22:09:26 +00001485 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
Richard Smitha05b3b52012-09-20 21:52:32 +00001486 Cond, Inc, LoopVar, RParenLoc,
1487 Sema::BFRK_Rebuild);
Richard Smith02e85f32011-04-14 22:09:26 +00001488 }
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001489
1490 /// \brief Build a new C++0x range-based for statement.
1491 ///
1492 /// By default, performs semantic analysis to build the new statement.
1493 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00001494 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001495 bool IsIfExists,
1496 NestedNameSpecifierLoc QualifierLoc,
1497 DeclarationNameInfo NameInfo,
1498 Stmt *Nested) {
1499 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1500 QualifierLoc, NameInfo, Nested);
1501 }
1502
Richard Smith02e85f32011-04-14 22:09:26 +00001503 /// \brief Attach body to a C++0x range-based for statement.
1504 ///
1505 /// By default, performs semantic analysis to finish the new statement.
1506 /// Subclasses may override this routine to provide different behavior.
1507 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1508 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1509 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001510
David Majnemerfad8f482013-10-15 09:33:02 +00001511 StmtResult RebuildSEHTryStmt(bool IsCXXTry, SourceLocation TryLoc,
1512 Stmt *TryBlock, Stmt *Handler) {
1513 return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +00001514 }
1515
David Majnemerfad8f482013-10-15 09:33:02 +00001516 StmtResult RebuildSEHExceptStmt(SourceLocation Loc, Expr *FilterExpr,
John Wiegley1c0675e2011-04-28 01:08:34 +00001517 Stmt *Block) {
David Majnemerfad8f482013-10-15 09:33:02 +00001518 return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001519 }
1520
David Majnemerfad8f482013-10-15 09:33:02 +00001521 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, Stmt *Block) {
1522 return getSema().ActOnSEHFinallyBlock(Loc, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001523 }
1524
Douglas Gregora16548e2009-08-11 05:31:07 +00001525 /// \brief Build a new expression that references a declaration.
1526 ///
1527 /// By default, performs semantic analysis to build the new expression.
1528 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001529 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00001530 LookupResult &R,
1531 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00001532 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1533 }
1534
1535
1536 /// \brief Build a new expression that references a declaration.
1537 ///
1538 /// By default, performs semantic analysis to build the new expression.
1539 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorea972d32011-02-28 21:54:11 +00001540 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001541 ValueDecl *VD,
1542 const DeclarationNameInfo &NameInfo,
1543 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001544 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001545 SS.Adopt(QualifierLoc);
John McCallce546572009-12-08 09:08:17 +00001546
1547 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001548
1549 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001550 }
Mike Stump11289f42009-09-09 15:08:12 +00001551
Douglas Gregora16548e2009-08-11 05:31:07 +00001552 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001553 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001554 /// By default, performs semantic analysis to build the new expression.
1555 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001556 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00001557 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00001558 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001559 }
1560
Douglas Gregorad8a3362009-09-04 17:36:40 +00001561 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001562 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001563 /// By default, performs semantic analysis to build the new expression.
1564 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001565 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora6ce6082011-02-25 18:19:59 +00001566 SourceLocation OperatorLoc,
1567 bool isArrow,
1568 CXXScopeSpec &SS,
1569 TypeSourceInfo *ScopeType,
1570 SourceLocation CCLoc,
1571 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001572 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001573
Douglas Gregora16548e2009-08-11 05:31:07 +00001574 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001575 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001576 /// By default, performs semantic analysis to build the new expression.
1577 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001578 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001579 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001580 Expr *SubExpr) {
1581 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001582 }
Mike Stump11289f42009-09-09 15:08:12 +00001583
Douglas Gregor882211c2010-04-28 22:16:22 +00001584 /// \brief Build a new builtin offsetof expression.
1585 ///
1586 /// By default, performs semantic analysis to build the new expression.
1587 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001588 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor882211c2010-04-28 22:16:22 +00001589 TypeSourceInfo *Type,
John McCallfaf5fb42010-08-26 23:41:50 +00001590 Sema::OffsetOfComponent *Components,
Douglas Gregor882211c2010-04-28 22:16:22 +00001591 unsigned NumComponents,
1592 SourceLocation RParenLoc) {
1593 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1594 NumComponents, RParenLoc);
1595 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001596
1597 /// \brief Build a new sizeof, alignof or vec_step expression with a
Peter Collingbournee190dee2011-03-11 19:24:49 +00001598 /// type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001599 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001600 /// By default, performs semantic analysis to build the new expression.
1601 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001602 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1603 SourceLocation OpLoc,
1604 UnaryExprOrTypeTrait ExprKind,
1605 SourceRange R) {
1606 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001607 }
1608
Peter Collingbournee190dee2011-03-11 19:24:49 +00001609 /// \brief Build a new sizeof, alignof or vec step expression with an
1610 /// expression argument.
Mike Stump11289f42009-09-09 15:08:12 +00001611 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001612 /// By default, performs semantic analysis to build the new expression.
1613 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001614 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1615 UnaryExprOrTypeTrait ExprKind,
1616 SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00001617 ExprResult Result
Chandler Carrutha923fb22011-05-29 07:32:14 +00001618 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregora16548e2009-08-11 05:31:07 +00001619 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001620 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001621
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001622 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001623 }
Mike Stump11289f42009-09-09 15:08:12 +00001624
Douglas Gregora16548e2009-08-11 05:31:07 +00001625 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001626 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001627 /// By default, performs semantic analysis to build the new expression.
1628 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001629 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001630 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00001631 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001632 SourceLocation RBracketLoc) {
John McCallb268a282010-08-23 23:25:46 +00001633 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1634 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001635 RBracketLoc);
1636 }
1637
1638 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00001639 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001640 /// By default, performs semantic analysis to build the new expression.
1641 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001642 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001643 MultiExprArg Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00001644 SourceLocation RParenLoc,
1645 Expr *ExecConfig = 0) {
John McCallb268a282010-08-23 23:25:46 +00001646 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001647 Args, RParenLoc, ExecConfig);
Douglas Gregora16548e2009-08-11 05:31:07 +00001648 }
1649
1650 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001651 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001652 /// By default, performs semantic analysis to build the new expression.
1653 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001654 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001655 bool isArrow,
Douglas Gregorea972d32011-02-28 21:54:11 +00001656 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001657 SourceLocation TemplateKWLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001658 const DeclarationNameInfo &MemberNameInfo,
1659 ValueDecl *Member,
1660 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001661 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00001662 NamedDecl *FirstQualifierInScope) {
Richard Smithcab9a7d2011-10-26 19:06:56 +00001663 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
1664 isArrow);
Anders Carlsson5da84842009-09-01 04:26:58 +00001665 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00001666 // We have a reference to an unnamed field. This is always the
1667 // base of an anonymous struct/union member access, i.e. the
1668 // field is always of record type.
Douglas Gregorea972d32011-02-28 21:54:11 +00001669 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCall7decc9e2010-11-18 06:31:45 +00001670 assert(Member->getType()->isRecordType() &&
1671 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00001672
Richard Smithcab9a7d2011-10-26 19:06:56 +00001673 BaseResult =
1674 getSema().PerformObjectMemberConversion(BaseResult.take(),
John Wiegley01296292011-04-08 18:41:53 +00001675 QualifierLoc.getNestedNameSpecifier(),
1676 FoundDecl, Member);
1677 if (BaseResult.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001678 return ExprError();
John Wiegley01296292011-04-08 18:41:53 +00001679 Base = BaseResult.take();
John McCall7decc9e2010-11-18 06:31:45 +00001680 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump11289f42009-09-09 15:08:12 +00001681 MemberExpr *ME =
John McCallb268a282010-08-23 23:25:46 +00001682 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001683 Member, MemberNameInfo,
John McCall7decc9e2010-11-18 06:31:45 +00001684 cast<FieldDecl>(Member)->getType(),
1685 VK, OK_Ordinary);
Anders Carlsson5da84842009-09-01 04:26:58 +00001686 return getSema().Owned(ME);
1687 }
Mike Stump11289f42009-09-09 15:08:12 +00001688
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001689 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001690 SS.Adopt(QualifierLoc);
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001691
John Wiegley01296292011-04-08 18:41:53 +00001692 Base = BaseResult.take();
John McCallb268a282010-08-23 23:25:46 +00001693 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00001694
John McCall16df1e52010-03-30 21:47:33 +00001695 // FIXME: this involves duplicating earlier analysis in a lot of
1696 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001697 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001698 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001699 R.resolveKind();
1700
John McCallb268a282010-08-23 23:25:46 +00001701 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001702 SS, TemplateKWLoc,
1703 FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001704 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001705 }
Mike Stump11289f42009-09-09 15:08:12 +00001706
Douglas Gregora16548e2009-08-11 05:31:07 +00001707 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001708 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001709 /// By default, performs semantic analysis to build the new expression.
1710 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001711 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001712 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001713 Expr *LHS, Expr *RHS) {
1714 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001715 }
1716
1717 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001718 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001719 /// By default, performs semantic analysis to build the new expression.
1720 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001721 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCallc07a0c72011-02-17 10:25:35 +00001722 SourceLocation QuestionLoc,
1723 Expr *LHS,
1724 SourceLocation ColonLoc,
1725 Expr *RHS) {
John McCallb268a282010-08-23 23:25:46 +00001726 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1727 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001728 }
1729
Douglas Gregora16548e2009-08-11 05:31:07 +00001730 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001731 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001732 /// By default, performs semantic analysis to build the new expression.
1733 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001734 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00001735 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001736 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001737 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001738 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001739 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001740 }
Mike Stump11289f42009-09-09 15:08:12 +00001741
Douglas Gregora16548e2009-08-11 05:31:07 +00001742 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001743 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001744 /// By default, performs semantic analysis to build the new expression.
1745 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001746 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001747 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001748 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001749 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001750 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001751 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001752 }
Mike Stump11289f42009-09-09 15:08:12 +00001753
Douglas Gregora16548e2009-08-11 05:31:07 +00001754 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001755 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001756 /// By default, performs semantic analysis to build the new expression.
1757 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001758 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001759 SourceLocation OpLoc,
1760 SourceLocation AccessorLoc,
1761 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001762
John McCall10eae182009-11-30 22:42:35 +00001763 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001764 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00001765 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00001766 OpLoc, /*IsArrow*/ false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001767 SS, SourceLocation(),
1768 /*FirstQualifierInScope*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001769 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00001770 /* TemplateArgs */ 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00001771 }
Mike Stump11289f42009-09-09 15:08:12 +00001772
Douglas Gregora16548e2009-08-11 05:31:07 +00001773 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001774 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001775 /// By default, performs semantic analysis to build the new expression.
1776 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001777 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCall542e7c62011-07-06 07:30:07 +00001778 MultiExprArg Inits,
1779 SourceLocation RBraceLoc,
1780 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00001781 ExprResult Result
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001782 = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
Douglas Gregord3d93062009-11-09 17:16:50 +00001783 if (Result.isInvalid() || ResultTy->isDependentType())
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001784 return Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00001785
Douglas Gregord3d93062009-11-09 17:16:50 +00001786 // Patch in the result type we were given, which may have been computed
1787 // when the initial InitListExpr was built.
1788 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1789 ILE->setType(ResultTy);
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001790 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001791 }
Mike Stump11289f42009-09-09 15:08:12 +00001792
Douglas Gregora16548e2009-08-11 05:31:07 +00001793 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001794 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001795 /// By default, performs semantic analysis to build the new expression.
1796 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001797 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00001798 MultiExprArg ArrayExprs,
1799 SourceLocation EqualOrColonLoc,
1800 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001801 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00001802 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001803 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001804 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001805 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001806 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001807
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001808 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001809 }
Mike Stump11289f42009-09-09 15:08:12 +00001810
Douglas Gregora16548e2009-08-11 05:31:07 +00001811 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001812 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001813 /// By default, builds the implicit value initialization without performing
1814 /// any semantic analysis. Subclasses may override this routine to provide
1815 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001816 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001817 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1818 }
Mike Stump11289f42009-09-09 15:08:12 +00001819
Douglas Gregora16548e2009-08-11 05:31:07 +00001820 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001821 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001822 /// By default, performs semantic analysis to build the new expression.
1823 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001824 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001825 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001826 SourceLocation RParenLoc) {
1827 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001828 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001829 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001830 }
1831
1832 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001833 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001834 /// By default, performs semantic analysis to build the new expression.
1835 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001836 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redla9351792012-02-11 23:51:47 +00001837 MultiExprArg SubExprs,
1838 SourceLocation RParenLoc) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001839 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001840 }
Mike Stump11289f42009-09-09 15:08:12 +00001841
Douglas Gregora16548e2009-08-11 05:31:07 +00001842 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001843 ///
1844 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00001845 /// rather than attempting to map the label statement itself.
1846 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001847 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001848 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001849 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregora16548e2009-08-11 05:31:07 +00001850 }
Mike Stump11289f42009-09-09 15:08:12 +00001851
Douglas Gregora16548e2009-08-11 05:31:07 +00001852 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00001853 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001854 /// By default, performs semantic analysis to build the new expression.
1855 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001856 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001857 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00001858 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001859 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001860 }
Mike Stump11289f42009-09-09 15:08:12 +00001861
Douglas Gregora16548e2009-08-11 05:31:07 +00001862 /// \brief Build a new __builtin_choose_expr expression.
1863 ///
1864 /// By default, performs semantic analysis to build the new expression.
1865 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001866 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001867 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001868 SourceLocation RParenLoc) {
1869 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001870 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001871 RParenLoc);
1872 }
Mike Stump11289f42009-09-09 15:08:12 +00001873
Peter Collingbourne91147592011-04-15 00:35:48 +00001874 /// \brief Build a new generic selection expression.
1875 ///
1876 /// By default, performs semantic analysis to build the new expression.
1877 /// Subclasses may override this routine to provide different behavior.
1878 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
1879 SourceLocation DefaultLoc,
1880 SourceLocation RParenLoc,
1881 Expr *ControllingExpr,
Dmitri Gribenko82360372013-05-10 13:06:58 +00001882 ArrayRef<TypeSourceInfo *> Types,
1883 ArrayRef<Expr *> Exprs) {
Peter Collingbourne91147592011-04-15 00:35:48 +00001884 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
Dmitri Gribenko82360372013-05-10 13:06:58 +00001885 ControllingExpr, Types, Exprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00001886 }
1887
Douglas Gregora16548e2009-08-11 05:31:07 +00001888 /// \brief Build a new overloaded operator call expression.
1889 ///
1890 /// By default, performs semantic analysis to build the new expression.
1891 /// The semantic analysis provides the behavior of template instantiation,
1892 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00001893 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00001894 /// argument-dependent lookup, etc. Subclasses may override this routine to
1895 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001896 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00001897 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00001898 Expr *Callee,
1899 Expr *First,
1900 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00001901
1902 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00001903 /// reinterpret_cast.
1904 ///
1905 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00001906 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00001907 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001908 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001909 Stmt::StmtClass Class,
1910 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001911 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001912 SourceLocation RAngleLoc,
1913 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001914 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001915 SourceLocation RParenLoc) {
1916 switch (Class) {
1917 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001918 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001919 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001920 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001921
1922 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001923 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001924 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001925 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001926
Douglas Gregora16548e2009-08-11 05:31:07 +00001927 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001928 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001929 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001930 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001931 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001932
Douglas Gregora16548e2009-08-11 05:31:07 +00001933 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001934 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001935 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001936 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001937
Douglas Gregora16548e2009-08-11 05:31:07 +00001938 default:
David Blaikie83d382b2011-09-23 05:06:16 +00001939 llvm_unreachable("Invalid C++ named cast");
Douglas Gregora16548e2009-08-11 05:31:07 +00001940 }
Douglas Gregora16548e2009-08-11 05:31:07 +00001941 }
Mike Stump11289f42009-09-09 15:08:12 +00001942
Douglas Gregora16548e2009-08-11 05:31:07 +00001943 /// \brief Build a new C++ static_cast expression.
1944 ///
1945 /// By default, performs semantic analysis to build the new expression.
1946 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001947 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001948 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001949 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001950 SourceLocation RAngleLoc,
1951 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001952 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001953 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001954 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00001955 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001956 SourceRange(LAngleLoc, RAngleLoc),
1957 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001958 }
1959
1960 /// \brief Build a new C++ dynamic_cast expression.
1961 ///
1962 /// By default, performs semantic analysis to build the new expression.
1963 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001964 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001965 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001966 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001967 SourceLocation RAngleLoc,
1968 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001969 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001970 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001971 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00001972 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001973 SourceRange(LAngleLoc, RAngleLoc),
1974 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001975 }
1976
1977 /// \brief Build a new C++ reinterpret_cast expression.
1978 ///
1979 /// By default, performs semantic analysis to build the new expression.
1980 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001981 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001982 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001983 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001984 SourceLocation RAngleLoc,
1985 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001986 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001987 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001988 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00001989 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001990 SourceRange(LAngleLoc, RAngleLoc),
1991 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001992 }
1993
1994 /// \brief Build a new C++ const_cast expression.
1995 ///
1996 /// By default, performs semantic analysis to build the new expression.
1997 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001998 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001999 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002000 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002001 SourceLocation RAngleLoc,
2002 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002003 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002004 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002005 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00002006 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002007 SourceRange(LAngleLoc, RAngleLoc),
2008 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002009 }
Mike Stump11289f42009-09-09 15:08:12 +00002010
Douglas Gregora16548e2009-08-11 05:31:07 +00002011 /// \brief Build a new C++ functional-style cast expression.
2012 ///
2013 /// By default, performs semantic analysis to build the new expression.
2014 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002015 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
2016 SourceLocation LParenLoc,
2017 Expr *Sub,
2018 SourceLocation RParenLoc) {
2019 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00002020 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00002021 RParenLoc);
2022 }
Mike Stump11289f42009-09-09 15:08:12 +00002023
Douglas Gregora16548e2009-08-11 05:31:07 +00002024 /// \brief Build a new C++ typeid(type) expression.
2025 ///
2026 /// By default, performs semantic analysis to build the new expression.
2027 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002028 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002029 SourceLocation TypeidLoc,
2030 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002031 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002032 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002033 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002034 }
Mike Stump11289f42009-09-09 15:08:12 +00002035
Francois Pichet9f4f2072010-09-08 12:20:18 +00002036
Douglas Gregora16548e2009-08-11 05:31:07 +00002037 /// \brief Build a new C++ typeid(expr) expression.
2038 ///
2039 /// By default, performs semantic analysis to build the new expression.
2040 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002041 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002042 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00002043 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002044 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002045 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002046 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002047 }
2048
Francois Pichet9f4f2072010-09-08 12:20:18 +00002049 /// \brief Build a new C++ __uuidof(type) expression.
2050 ///
2051 /// By default, performs semantic analysis to build the new expression.
2052 /// Subclasses may override this routine to provide different behavior.
2053 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2054 SourceLocation TypeidLoc,
2055 TypeSourceInfo *Operand,
2056 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002057 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
Francois Pichet9f4f2072010-09-08 12:20:18 +00002058 RParenLoc);
2059 }
2060
2061 /// \brief Build a new C++ __uuidof(expr) expression.
2062 ///
2063 /// By default, performs semantic analysis to build the new expression.
2064 /// Subclasses may override this routine to provide different behavior.
2065 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2066 SourceLocation TypeidLoc,
2067 Expr *Operand,
2068 SourceLocation RParenLoc) {
2069 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
2070 RParenLoc);
2071 }
2072
Douglas Gregora16548e2009-08-11 05:31:07 +00002073 /// \brief Build a new C++ "this" expression.
2074 ///
2075 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00002076 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00002077 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002078 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00002079 QualType ThisType,
2080 bool isImplicit) {
Eli Friedman20139d32012-01-11 02:36:31 +00002081 getSema().CheckCXXThisCapture(ThisLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002082 return getSema().Owned(
Douglas Gregorb15af892010-01-07 23:12:05 +00002083 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
2084 isImplicit));
Douglas Gregora16548e2009-08-11 05:31:07 +00002085 }
2086
2087 /// \brief Build a new C++ throw expression.
2088 ///
2089 /// By default, performs semantic analysis to build the new expression.
2090 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor53e191ed2011-07-06 22:04:06 +00002091 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
2092 bool IsThrownVariableInScope) {
2093 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00002094 }
2095
2096 /// \brief Build a new C++ default-argument expression.
2097 ///
2098 /// By default, builds a new default-argument expression, which does not
2099 /// require any semantic analysis. Subclasses may override this routine to
2100 /// provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002101 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00002102 ParmVarDecl *Param) {
2103 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
2104 Param));
Douglas Gregora16548e2009-08-11 05:31:07 +00002105 }
2106
Richard Smith852c9db2013-04-20 22:23:05 +00002107 /// \brief Build a new C++11 default-initialization expression.
2108 ///
2109 /// By default, builds a new default field initialization expression, which
2110 /// does not require any semantic analysis. Subclasses may override this
2111 /// routine to provide different behavior.
2112 ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc,
2113 FieldDecl *Field) {
2114 return getSema().Owned(CXXDefaultInitExpr::Create(getSema().Context, Loc,
2115 Field));
2116 }
2117
Douglas Gregora16548e2009-08-11 05:31:07 +00002118 /// \brief Build a new C++ zero-initialization expression.
2119 ///
2120 /// By default, performs semantic analysis to build the new expression.
2121 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002122 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
2123 SourceLocation LParenLoc,
2124 SourceLocation RParenLoc) {
2125 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002126 None, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002127 }
Mike Stump11289f42009-09-09 15:08:12 +00002128
Douglas Gregora16548e2009-08-11 05:31:07 +00002129 /// \brief Build a new C++ "new" expression.
2130 ///
2131 /// By default, performs semantic analysis to build the new expression.
2132 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002133 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002134 bool UseGlobal,
2135 SourceLocation PlacementLParen,
2136 MultiExprArg PlacementArgs,
2137 SourceLocation PlacementRParen,
2138 SourceRange TypeIdParens,
2139 QualType AllocatedType,
2140 TypeSourceInfo *AllocatedTypeInfo,
2141 Expr *ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002142 SourceRange DirectInitRange,
2143 Expr *Initializer) {
Mike Stump11289f42009-09-09 15:08:12 +00002144 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00002145 PlacementLParen,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002146 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00002147 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00002148 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002149 AllocatedType,
2150 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00002151 ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002152 DirectInitRange,
2153 Initializer);
Douglas Gregora16548e2009-08-11 05:31:07 +00002154 }
Mike Stump11289f42009-09-09 15:08:12 +00002155
Douglas Gregora16548e2009-08-11 05:31:07 +00002156 /// \brief Build a new C++ "delete" expression.
2157 ///
2158 /// By default, performs semantic analysis to build the new expression.
2159 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002160 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002161 bool IsGlobalDelete,
2162 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002163 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002164 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002165 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00002166 }
Mike Stump11289f42009-09-09 15:08:12 +00002167
Douglas Gregor29c42f22012-02-24 07:38:34 +00002168 /// \brief Build a new type trait expression.
2169 ///
2170 /// By default, performs semantic analysis to build the new expression.
2171 /// Subclasses may override this routine to provide different behavior.
2172 ExprResult RebuildTypeTrait(TypeTrait Trait,
2173 SourceLocation StartLoc,
2174 ArrayRef<TypeSourceInfo *> Args,
2175 SourceLocation RParenLoc) {
2176 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2177 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002178
John Wiegley6242b6a2011-04-28 00:16:57 +00002179 /// \brief Build a new array type trait expression.
2180 ///
2181 /// By default, performs semantic analysis to build the new expression.
2182 /// Subclasses may override this routine to provide different behavior.
2183 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2184 SourceLocation StartLoc,
2185 TypeSourceInfo *TSInfo,
2186 Expr *DimExpr,
2187 SourceLocation RParenLoc) {
2188 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2189 }
2190
John Wiegleyf9f65842011-04-25 06:54:41 +00002191 /// \brief Build a new expression trait expression.
2192 ///
2193 /// By default, performs semantic analysis to build the new expression.
2194 /// Subclasses may override this routine to provide different behavior.
2195 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2196 SourceLocation StartLoc,
2197 Expr *Queried,
2198 SourceLocation RParenLoc) {
2199 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2200 }
2201
Mike Stump11289f42009-09-09 15:08:12 +00002202 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00002203 /// expression.
2204 ///
2205 /// By default, performs semantic analysis to build the new expression.
2206 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002207 ExprResult RebuildDependentScopeDeclRefExpr(
2208 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002209 SourceLocation TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002210 const DeclarationNameInfo &NameInfo,
Richard Smithdb2630f2012-10-21 03:28:35 +00002211 const TemplateArgumentListInfo *TemplateArgs,
2212 bool IsAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002213 CXXScopeSpec SS;
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002214 SS.Adopt(QualifierLoc);
John McCalle66edc12009-11-24 19:00:30 +00002215
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002216 if (TemplateArgs || TemplateKWLoc.isValid())
Abramo Bagnara7945c982012-01-27 09:46:47 +00002217 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002218 NameInfo, TemplateArgs);
John McCalle66edc12009-11-24 19:00:30 +00002219
Richard Smithdb2630f2012-10-21 03:28:35 +00002220 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo,
2221 IsAddressOfOperand);
Douglas Gregora16548e2009-08-11 05:31:07 +00002222 }
2223
2224 /// \brief Build a new template-id expression.
2225 ///
2226 /// By default, performs semantic analysis to build the new expression.
2227 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002228 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002229 SourceLocation TemplateKWLoc,
2230 LookupResult &R,
2231 bool RequiresADL,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002232 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnara7945c982012-01-27 09:46:47 +00002233 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2234 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002235 }
2236
2237 /// \brief Build a new object-construction expression.
2238 ///
2239 /// By default, performs semantic analysis to build the new expression.
2240 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002241 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002242 SourceLocation Loc,
2243 CXXConstructorDecl *Constructor,
2244 bool IsElidable,
2245 MultiExprArg Args,
2246 bool HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002247 bool ListInitialization,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002248 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00002249 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002250 SourceRange ParenRange) {
Benjamin Kramerf0623432012-08-23 22:51:59 +00002251 SmallVector<Expr*, 8> ConvertedArgs;
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002252 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00002253 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00002254 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002255
Douglas Gregordb121ba2009-12-14 16:27:04 +00002256 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002257 ConvertedArgs,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002258 HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002259 ListInitialization,
Chandler Carruth01718152010-10-25 08:47:36 +00002260 RequiresZeroInit, ConstructKind,
2261 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00002262 }
2263
2264 /// \brief Build a new object-construction expression.
2265 ///
2266 /// By default, performs semantic analysis to build the new expression.
2267 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002268 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2269 SourceLocation LParenLoc,
2270 MultiExprArg Args,
2271 SourceLocation RParenLoc) {
2272 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002273 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002274 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002275 RParenLoc);
2276 }
2277
2278 /// \brief Build a new object-construction expression.
2279 ///
2280 /// By default, performs semantic analysis to build the new expression.
2281 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002282 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2283 SourceLocation LParenLoc,
2284 MultiExprArg Args,
2285 SourceLocation RParenLoc) {
2286 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002287 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002288 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002289 RParenLoc);
2290 }
Mike Stump11289f42009-09-09 15:08:12 +00002291
Douglas Gregora16548e2009-08-11 05:31:07 +00002292 /// \brief Build a new member reference expression.
2293 ///
2294 /// By default, performs semantic analysis to build the new expression.
2295 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002296 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregore16af532011-02-28 18:50:33 +00002297 QualType BaseType,
2298 bool IsArrow,
2299 SourceLocation OperatorLoc,
2300 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002301 SourceLocation TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00002302 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002303 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00002304 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002305 CXXScopeSpec SS;
Douglas Gregore16af532011-02-28 18:50:33 +00002306 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002307
John McCallb268a282010-08-23 23:25:46 +00002308 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002309 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002310 SS, TemplateKWLoc,
2311 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002312 MemberNameInfo,
2313 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002314 }
2315
John McCall10eae182009-11-30 22:42:35 +00002316 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00002317 ///
2318 /// By default, performs semantic analysis to build the new expression.
2319 /// Subclasses may override this routine to provide different behavior.
Richard Smithcab9a7d2011-10-26 19:06:56 +00002320 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2321 SourceLocation OperatorLoc,
2322 bool IsArrow,
2323 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002324 SourceLocation TemplateKWLoc,
Richard Smithcab9a7d2011-10-26 19:06:56 +00002325 NamedDecl *FirstQualifierInScope,
2326 LookupResult &R,
John McCall10eae182009-11-30 22:42:35 +00002327 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00002328 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00002329 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002330
John McCallb268a282010-08-23 23:25:46 +00002331 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002332 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002333 SS, TemplateKWLoc,
2334 FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00002335 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00002336 }
Mike Stump11289f42009-09-09 15:08:12 +00002337
Sebastian Redl4202c0f2010-09-10 20:55:43 +00002338 /// \brief Build a new noexcept expression.
2339 ///
2340 /// By default, performs semantic analysis to build the new expression.
2341 /// Subclasses may override this routine to provide different behavior.
2342 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2343 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2344 }
2345
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002346 /// \brief Build a new expression to compute the length of a parameter pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00002347 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2348 SourceLocation PackLoc,
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002349 SourceLocation RParenLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002350 Optional<unsigned> Length) {
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002351 if (Length)
Chad Rosier1dcde962012-08-08 18:46:20 +00002352 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2353 OperatorLoc, Pack, PackLoc,
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002354 RParenLoc, *Length);
Chad Rosier1dcde962012-08-08 18:46:20 +00002355
2356 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2357 OperatorLoc, Pack, PackLoc,
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002358 RParenLoc);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002359 }
Ted Kremeneke65b0862012-03-06 20:05:56 +00002360
Patrick Beard0caa3942012-04-19 00:25:12 +00002361 /// \brief Build a new Objective-C boxed expression.
2362 ///
2363 /// By default, performs semantic analysis to build the new expression.
2364 /// Subclasses may override this routine to provide different behavior.
2365 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2366 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2367 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002368
Ted Kremeneke65b0862012-03-06 20:05:56 +00002369 /// \brief Build a new Objective-C array literal.
2370 ///
2371 /// By default, performs semantic analysis to build the new expression.
2372 /// Subclasses may override this routine to provide different behavior.
2373 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2374 Expr **Elements, unsigned NumElements) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002375 return getSema().BuildObjCArrayLiteral(Range,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002376 MultiExprArg(Elements, NumElements));
2377 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002378
2379 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002380 Expr *Base, Expr *Key,
2381 ObjCMethodDecl *getterMethod,
2382 ObjCMethodDecl *setterMethod) {
2383 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2384 getterMethod, setterMethod);
2385 }
2386
2387 /// \brief Build a new Objective-C dictionary literal.
2388 ///
2389 /// By default, performs semantic analysis to build the new expression.
2390 /// Subclasses may override this routine to provide different behavior.
2391 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
2392 ObjCDictionaryElement *Elements,
2393 unsigned NumElements) {
2394 return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements);
2395 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002396
James Dennett2a4d13c2012-06-15 07:13:21 +00002397 /// \brief Build a new Objective-C \@encode expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002398 ///
2399 /// By default, performs semantic analysis to build the new expression.
2400 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002401 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00002402 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002403 SourceLocation RParenLoc) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00002404 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002405 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00002406 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002407
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002408 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00002409 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002410 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002411 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002412 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002413 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002414 MultiExprArg Args,
2415 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002416 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2417 ReceiverTypeInfo->getType(),
2418 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002419 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002420 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002421 }
2422
2423 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00002424 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002425 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002426 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002427 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002428 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002429 MultiExprArg Args,
2430 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00002431 return SemaRef.BuildInstanceMessage(Receiver,
2432 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002433 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002434 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002435 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002436 }
2437
Douglas Gregord51d90d2010-04-26 20:11:03 +00002438 /// \brief Build a new Objective-C ivar reference expression.
2439 ///
2440 /// By default, performs semantic analysis to build the new expression.
2441 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002442 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002443 SourceLocation IvarLoc,
2444 bool IsArrow, bool IsFreeIvar) {
2445 // FIXME: We lose track of the IsFreeIvar bit.
2446 CXXScopeSpec SS;
John Wiegley01296292011-04-08 18:41:53 +00002447 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002448 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2449 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00002450 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002451 /*FIME:*/IvarLoc,
John McCall48871652010-08-21 09:40:31 +00002452 SS, 0,
John McCalle9cccd82010-06-16 08:42:20 +00002453 false);
John Wiegley01296292011-04-08 18:41:53 +00002454 if (Result.isInvalid() || Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002455 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002456
Douglas Gregord51d90d2010-04-26 20:11:03 +00002457 if (Result.get())
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002458 return Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00002459
John Wiegley01296292011-04-08 18:41:53 +00002460 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Abramo Bagnara7945c982012-01-27 09:46:47 +00002461 /*FIXME:*/IvarLoc, IsArrow,
2462 SS, SourceLocation(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00002463 /*FirstQualifierInScope=*/0,
Chad Rosier1dcde962012-08-08 18:46:20 +00002464 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002465 /*TemplateArgs=*/0);
2466 }
Douglas Gregor9faee212010-04-26 20:47:02 +00002467
2468 /// \brief Build a new Objective-C property reference expression.
2469 ///
2470 /// By default, performs semantic analysis to build the new expression.
2471 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002472 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall526ab472011-10-25 17:37:35 +00002473 ObjCPropertyDecl *Property,
2474 SourceLocation PropertyLoc) {
Douglas Gregor9faee212010-04-26 20:47:02 +00002475 CXXScopeSpec SS;
John Wiegley01296292011-04-08 18:41:53 +00002476 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregor9faee212010-04-26 20:47:02 +00002477 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2478 Sema::LookupMemberName);
2479 bool IsArrow = false;
John McCalldadc5752010-08-24 06:29:42 +00002480 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregor9faee212010-04-26 20:47:02 +00002481 /*FIME:*/PropertyLoc,
John McCall48871652010-08-21 09:40:31 +00002482 SS, 0, false);
John Wiegley01296292011-04-08 18:41:53 +00002483 if (Result.isInvalid() || Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002484 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002485
Douglas Gregor9faee212010-04-26 20:47:02 +00002486 if (Result.get())
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002487 return Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00002488
John Wiegley01296292011-04-08 18:41:53 +00002489 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Chad Rosier1dcde962012-08-08 18:46:20 +00002490 /*FIXME:*/PropertyLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002491 SS, SourceLocation(),
Douglas Gregor9faee212010-04-26 20:47:02 +00002492 /*FirstQualifierInScope=*/0,
Chad Rosier1dcde962012-08-08 18:46:20 +00002493 R,
Douglas Gregor9faee212010-04-26 20:47:02 +00002494 /*TemplateArgs=*/0);
2495 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002496
John McCallb7bd14f2010-12-02 01:19:52 +00002497 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002498 ///
2499 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00002500 /// Subclasses may override this routine to provide different behavior.
2501 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2502 ObjCMethodDecl *Getter,
2503 ObjCMethodDecl *Setter,
2504 SourceLocation PropertyLoc) {
2505 // Since these expressions can only be value-dependent, we do not
2506 // need to perform semantic analysis again.
2507 return Owned(
2508 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2509 VK_LValue, OK_ObjCProperty,
2510 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002511 }
2512
Douglas Gregord51d90d2010-04-26 20:11:03 +00002513 /// \brief Build a new Objective-C "isa" expression.
2514 ///
2515 /// By default, performs semantic analysis to build the new expression.
2516 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002517 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00002518 SourceLocation OpLoc,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002519 bool IsArrow) {
2520 CXXScopeSpec SS;
John Wiegley01296292011-04-08 18:41:53 +00002521 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002522 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2523 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00002524 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00002525 OpLoc,
John McCall48871652010-08-21 09:40:31 +00002526 SS, 0, false);
John Wiegley01296292011-04-08 18:41:53 +00002527 if (Result.isInvalid() || Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002528 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002529
Douglas Gregord51d90d2010-04-26 20:11:03 +00002530 if (Result.get())
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002531 return Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00002532
John Wiegley01296292011-04-08 18:41:53 +00002533 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00002534 OpLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002535 SS, SourceLocation(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00002536 /*FirstQualifierInScope=*/0,
Chad Rosier1dcde962012-08-08 18:46:20 +00002537 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002538 /*TemplateArgs=*/0);
2539 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002540
Douglas Gregora16548e2009-08-11 05:31:07 +00002541 /// \brief Build a new shuffle vector expression.
2542 ///
2543 /// By default, performs semantic analysis to build the new expression.
2544 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002545 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002546 MultiExprArg SubExprs,
2547 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002548 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00002549 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00002550 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2551 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2552 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
David Blaikieff7d47a2012-12-19 00:45:41 +00002553 assert(!Lookup.empty() && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00002554
Douglas Gregora16548e2009-08-11 05:31:07 +00002555 // Build a reference to the __builtin_shufflevector builtin
David Blaikieff7d47a2012-12-19 00:45:41 +00002556 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
Eli Friedman34866c72012-08-31 00:14:07 +00002557 Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false,
2558 SemaRef.Context.BuiltinFnTy,
2559 VK_RValue, BuiltinLoc);
2560 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
2561 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
2562 CK_BuiltinFnToFnPtr).take();
Mike Stump11289f42009-09-09 15:08:12 +00002563
2564 // Build the CallExpr
Alp Toker314cc812014-01-25 16:55:45 +00002565 ExprResult TheCall = SemaRef.Owned(new (SemaRef.Context) CallExpr(
2566 SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(),
2567 Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00002568
Douglas Gregora16548e2009-08-11 05:31:07 +00002569 // Type-check the __builtin_shufflevector expression.
John Wiegley01296292011-04-08 18:41:53 +00002570 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.take()));
Douglas Gregora16548e2009-08-11 05:31:07 +00002571 }
John McCall31f82722010-11-12 08:19:04 +00002572
Hal Finkelc4d7c822013-09-18 03:29:45 +00002573 /// \brief Build a new convert vector expression.
2574 ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc,
2575 Expr *SrcExpr, TypeSourceInfo *DstTInfo,
2576 SourceLocation RParenLoc) {
2577 return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo,
2578 BuiltinLoc, RParenLoc);
2579 }
2580
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002581 /// \brief Build a new template argument pack expansion.
2582 ///
2583 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00002584 /// for a template argument. Subclasses may override this routine to provide
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002585 /// different behavior.
2586 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002587 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002588 Optional<unsigned> NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002589 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00002590 case TemplateArgument::Expression: {
2591 ExprResult Result
Douglas Gregorb8840002011-01-14 21:20:45 +00002592 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2593 EllipsisLoc, NumExpansions);
Douglas Gregor98318c22011-01-03 21:37:45 +00002594 if (Result.isInvalid())
2595 return TemplateArgumentLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00002596
Douglas Gregor98318c22011-01-03 21:37:45 +00002597 return TemplateArgumentLoc(Result.get(), Result.get());
2598 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002599
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002600 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002601 return TemplateArgumentLoc(TemplateArgument(
2602 Pattern.getArgument().getAsTemplate(),
Douglas Gregore1d60df2011-01-14 23:41:42 +00002603 NumExpansions),
Douglas Gregor9d802122011-03-02 17:09:35 +00002604 Pattern.getTemplateQualifierLoc(),
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002605 Pattern.getTemplateNameLoc(),
2606 EllipsisLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00002607
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002608 case TemplateArgument::Null:
2609 case TemplateArgument::Integral:
2610 case TemplateArgument::Declaration:
2611 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002612 case TemplateArgument::TemplateExpansion:
Eli Friedmanb826a002012-09-26 02:36:12 +00002613 case TemplateArgument::NullPtr:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002614 llvm_unreachable("Pack expansion pattern has no parameter packs");
Chad Rosier1dcde962012-08-08 18:46:20 +00002615
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002616 case TemplateArgument::Type:
Chad Rosier1dcde962012-08-08 18:46:20 +00002617 if (TypeSourceInfo *Expansion
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002618 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002619 EllipsisLoc,
2620 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002621 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2622 Expansion);
2623 break;
2624 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002625
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002626 return TemplateArgumentLoc();
2627 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002628
Douglas Gregor968f23a2011-01-03 19:31:53 +00002629 /// \brief Build a new expression pack expansion.
2630 ///
2631 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00002632 /// for an expression. Subclasses may override this routine to provide
Douglas Gregor968f23a2011-01-03 19:31:53 +00002633 /// different behavior.
Douglas Gregorb8840002011-01-14 21:20:45 +00002634 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002635 Optional<unsigned> NumExpansions) {
Douglas Gregorb8840002011-01-14 21:20:45 +00002636 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002637 }
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002638
2639 /// \brief Build a new atomic operation expression.
2640 ///
2641 /// By default, performs semantic analysis to build the new expression.
2642 /// Subclasses may override this routine to provide different behavior.
2643 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2644 MultiExprArg SubExprs,
2645 QualType RetTy,
2646 AtomicExpr::AtomicOp Op,
2647 SourceLocation RParenLoc) {
2648 // Just create the expression; there is not any interesting semantic
2649 // analysis here because we can't actually build an AtomicExpr until
2650 // we are sure it is semantically sound.
Benjamin Kramerc215e762012-08-24 11:54:20 +00002651 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002652 RParenLoc);
2653 }
2654
John McCall31f82722010-11-12 08:19:04 +00002655private:
Douglas Gregor14454802011-02-25 02:25:35 +00002656 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2657 QualType ObjectType,
2658 NamedDecl *FirstQualifierInScope,
2659 CXXScopeSpec &SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00002660
2661 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2662 QualType ObjectType,
2663 NamedDecl *FirstQualifierInScope,
2664 CXXScopeSpec &SS);
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00002665
2666 TypeSourceInfo *TransformTSIInObjectScope(TypeLoc TL, QualType ObjectType,
2667 NamedDecl *FirstQualifierInScope,
2668 CXXScopeSpec &SS);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002669};
Douglas Gregora16548e2009-08-11 05:31:07 +00002670
Douglas Gregorebe10102009-08-20 07:17:43 +00002671template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002672StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002673 if (!S)
2674 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00002675
Douglas Gregorebe10102009-08-20 07:17:43 +00002676 switch (S->getStmtClass()) {
2677 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00002678
Douglas Gregorebe10102009-08-20 07:17:43 +00002679 // Transform individual statement nodes
2680#define STMT(Node, Parent) \
2681 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCallbd066782011-02-09 08:16:59 +00002682#define ABSTRACT_STMT(Node)
Douglas Gregorebe10102009-08-20 07:17:43 +00002683#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00002684#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002685
Douglas Gregorebe10102009-08-20 07:17:43 +00002686 // Transform expressions by calling TransformExpr.
2687#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00002688#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00002689#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00002690#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00002691 {
John McCalldadc5752010-08-24 06:29:42 +00002692 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00002693 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002694 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002695
Richard Smith945f8d32013-01-14 22:39:08 +00002696 return getSema().ActOnExprStmt(E);
Douglas Gregorebe10102009-08-20 07:17:43 +00002697 }
Mike Stump11289f42009-09-09 15:08:12 +00002698 }
2699
John McCallc3007a22010-10-26 07:05:15 +00002700 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00002701}
Mike Stump11289f42009-09-09 15:08:12 +00002702
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00002703template<typename Derived>
2704OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) {
2705 if (!S)
2706 return S;
2707
2708 switch (S->getClauseKind()) {
2709 default: break;
2710 // Transform individual clause nodes
2711#define OPENMP_CLAUSE(Name, Class) \
2712 case OMPC_ ## Name : \
2713 return getDerived().Transform ## Class(cast<Class>(S));
2714#include "clang/Basic/OpenMPKinds.def"
2715 }
2716
2717 return S;
2718}
2719
Mike Stump11289f42009-09-09 15:08:12 +00002720
Douglas Gregore922c772009-08-04 22:27:00 +00002721template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002722ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002723 if (!E)
2724 return SemaRef.Owned(E);
2725
2726 switch (E->getStmtClass()) {
2727 case Stmt::NoStmtClass: break;
2728#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00002729#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00002730#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00002731 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00002732#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002733 }
2734
John McCallc3007a22010-10-26 07:05:15 +00002735 return SemaRef.Owned(E);
Douglas Gregor766b0bb2009-08-06 22:17:10 +00002736}
2737
2738template<typename Derived>
Richard Smithd59b8322012-12-19 01:39:02 +00002739ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
2740 bool CXXDirectInit) {
2741 // Initializers are instantiated like expressions, except that various outer
2742 // layers are stripped.
2743 if (!Init)
2744 return SemaRef.Owned(Init);
2745
2746 if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init))
2747 Init = ExprTemp->getSubExpr();
2748
Richard Smithe6ca4752013-05-30 22:40:16 +00002749 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
2750 Init = MTE->GetTemporaryExpr();
2751
Richard Smithd59b8322012-12-19 01:39:02 +00002752 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
2753 Init = Binder->getSubExpr();
2754
2755 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
2756 Init = ICE->getSubExprAsWritten();
2757
Richard Smithcc1b96d2013-06-12 22:31:48 +00002758 if (CXXStdInitializerListExpr *ILE =
2759 dyn_cast<CXXStdInitializerListExpr>(Init))
2760 return TransformInitializer(ILE->getSubExpr(), CXXDirectInit);
2761
Richard Smith38a549b2012-12-21 08:13:35 +00002762 // If this is not a direct-initializer, we only need to reconstruct
2763 // InitListExprs. Other forms of copy-initialization will be a no-op if
2764 // the initializer is already the right type.
2765 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
2766 if (!CXXDirectInit && !(Construct && Construct->isListInitialization()))
2767 return getDerived().TransformExpr(Init);
2768
2769 // Revert value-initialization back to empty parens.
2770 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
2771 SourceRange Parens = VIE->getSourceRange();
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002772 return getDerived().RebuildParenListExpr(Parens.getBegin(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00002773 Parens.getEnd());
2774 }
2775
2776 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
2777 if (isa<ImplicitValueInitExpr>(Init))
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002778 return getDerived().RebuildParenListExpr(SourceLocation(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00002779 SourceLocation());
2780
2781 // Revert initialization by constructor back to a parenthesized or braced list
2782 // of expressions. Any other form of initializer can just be reused directly.
2783 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
Richard Smithd59b8322012-12-19 01:39:02 +00002784 return getDerived().TransformExpr(Init);
2785
2786 SmallVector<Expr*, 8> NewArgs;
2787 bool ArgChanged = false;
2788 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
2789 /*IsCall*/true, NewArgs, &ArgChanged))
2790 return ExprError();
2791
2792 // If this was list initialization, revert to list form.
2793 if (Construct->isListInitialization())
2794 return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs,
2795 Construct->getLocEnd(),
2796 Construct->getType());
2797
Richard Smithd59b8322012-12-19 01:39:02 +00002798 // Build a ParenListExpr to represent anything else.
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00002799 SourceRange Parens = Construct->getParenOrBraceRange();
Richard Smithd59b8322012-12-19 01:39:02 +00002800 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
2801 Parens.getEnd());
2802}
2803
2804template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00002805bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2806 unsigned NumInputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00002807 bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +00002808 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00002809 bool *ArgChanged) {
2810 for (unsigned I = 0; I != NumInputs; ++I) {
2811 // If requested, drop call arguments that need to be dropped.
2812 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2813 if (ArgChanged)
2814 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002815
Douglas Gregora3efea12011-01-03 19:04:46 +00002816 break;
2817 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002818
Douglas Gregor968f23a2011-01-03 19:31:53 +00002819 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2820 Expr *Pattern = Expansion->getPattern();
Chad Rosier1dcde962012-08-08 18:46:20 +00002821
Chris Lattner01cf8db2011-07-20 06:58:45 +00002822 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor968f23a2011-01-03 19:31:53 +00002823 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2824 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00002825
Douglas Gregor968f23a2011-01-03 19:31:53 +00002826 // Determine whether the set of unexpanded parameter packs can and should
2827 // be expanded.
2828 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002829 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00002830 Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
2831 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor968f23a2011-01-03 19:31:53 +00002832 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2833 Pattern->getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00002834 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002835 Expand, RetainExpansion,
2836 NumExpansions))
Douglas Gregor968f23a2011-01-03 19:31:53 +00002837 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002838
Douglas Gregor968f23a2011-01-03 19:31:53 +00002839 if (!Expand) {
2840 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00002841 // transformation on the pack expansion, producing another pack
Douglas Gregor968f23a2011-01-03 19:31:53 +00002842 // expansion.
2843 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2844 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2845 if (OutPattern.isInvalid())
2846 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002847
2848 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregorb8840002011-01-14 21:20:45 +00002849 Expansion->getEllipsisLoc(),
2850 NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002851 if (Out.isInvalid())
2852 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002853
Douglas Gregor968f23a2011-01-03 19:31:53 +00002854 if (ArgChanged)
2855 *ArgChanged = true;
2856 Outputs.push_back(Out.get());
2857 continue;
2858 }
John McCall542e7c62011-07-06 07:30:07 +00002859
2860 // Record right away that the argument was changed. This needs
2861 // to happen even if the array expands to nothing.
2862 if (ArgChanged) *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002863
Douglas Gregor968f23a2011-01-03 19:31:53 +00002864 // The transform has determined that we should perform an elementwise
2865 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002866 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor968f23a2011-01-03 19:31:53 +00002867 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2868 ExprResult Out = getDerived().TransformExpr(Pattern);
2869 if (Out.isInvalid())
2870 return true;
2871
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002872 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregorb8840002011-01-14 21:20:45 +00002873 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2874 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002875 if (Out.isInvalid())
2876 return true;
2877 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002878
Douglas Gregor968f23a2011-01-03 19:31:53 +00002879 Outputs.push_back(Out.get());
2880 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002881
Douglas Gregor968f23a2011-01-03 19:31:53 +00002882 continue;
2883 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002884
Richard Smithd59b8322012-12-19 01:39:02 +00002885 ExprResult Result =
2886 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
2887 : getDerived().TransformExpr(Inputs[I]);
Douglas Gregora3efea12011-01-03 19:04:46 +00002888 if (Result.isInvalid())
2889 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002890
Douglas Gregora3efea12011-01-03 19:04:46 +00002891 if (Result.get() != Inputs[I] && ArgChanged)
2892 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002893
2894 Outputs.push_back(Result.get());
Douglas Gregora3efea12011-01-03 19:04:46 +00002895 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002896
Douglas Gregora3efea12011-01-03 19:04:46 +00002897 return false;
2898}
2899
2900template<typename Derived>
Douglas Gregor14454802011-02-25 02:25:35 +00002901NestedNameSpecifierLoc
2902TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2903 NestedNameSpecifierLoc NNS,
2904 QualType ObjectType,
2905 NamedDecl *FirstQualifierInScope) {
Chris Lattner01cf8db2011-07-20 06:58:45 +00002906 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier1dcde962012-08-08 18:46:20 +00002907 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregor14454802011-02-25 02:25:35 +00002908 Qualifier = Qualifier.getPrefix())
2909 Qualifiers.push_back(Qualifier);
2910
2911 CXXScopeSpec SS;
2912 while (!Qualifiers.empty()) {
2913 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2914 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier1dcde962012-08-08 18:46:20 +00002915
Douglas Gregor14454802011-02-25 02:25:35 +00002916 switch (QNNS->getKind()) {
2917 case NestedNameSpecifier::Identifier:
Chad Rosier1dcde962012-08-08 18:46:20 +00002918 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
Douglas Gregor14454802011-02-25 02:25:35 +00002919 *QNNS->getAsIdentifier(),
Chad Rosier1dcde962012-08-08 18:46:20 +00002920 Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00002921 Q.getLocalEndLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00002922 ObjectType, false, SS,
Douglas Gregor14454802011-02-25 02:25:35 +00002923 FirstQualifierInScope, false))
2924 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00002925
Douglas Gregor14454802011-02-25 02:25:35 +00002926 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00002927
Douglas Gregor14454802011-02-25 02:25:35 +00002928 case NestedNameSpecifier::Namespace: {
2929 NamespaceDecl *NS
2930 = cast_or_null<NamespaceDecl>(
2931 getDerived().TransformDecl(
2932 Q.getLocalBeginLoc(),
2933 QNNS->getAsNamespace()));
2934 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2935 break;
2936 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002937
Douglas Gregor14454802011-02-25 02:25:35 +00002938 case NestedNameSpecifier::NamespaceAlias: {
2939 NamespaceAliasDecl *Alias
2940 = cast_or_null<NamespaceAliasDecl>(
2941 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2942 QNNS->getAsNamespaceAlias()));
Chad Rosier1dcde962012-08-08 18:46:20 +00002943 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00002944 Q.getLocalEndLoc());
2945 break;
2946 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002947
Douglas Gregor14454802011-02-25 02:25:35 +00002948 case NestedNameSpecifier::Global:
2949 // There is no meaningful transformation that one could perform on the
2950 // global scope.
2951 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2952 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00002953
Douglas Gregor14454802011-02-25 02:25:35 +00002954 case NestedNameSpecifier::TypeSpecWithTemplate:
2955 case NestedNameSpecifier::TypeSpec: {
2956 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2957 FirstQualifierInScope, SS);
Chad Rosier1dcde962012-08-08 18:46:20 +00002958
Douglas Gregor14454802011-02-25 02:25:35 +00002959 if (!TL)
2960 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00002961
Douglas Gregor14454802011-02-25 02:25:35 +00002962 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Richard Smith2bf7fdb2013-01-02 11:42:31 +00002963 (SemaRef.getLangOpts().CPlusPlus11 &&
Douglas Gregor14454802011-02-25 02:25:35 +00002964 TL.getType()->isEnumeralType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002965 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregor14454802011-02-25 02:25:35 +00002966 "Can't get cv-qualifiers here");
Richard Smith91c7bbd2011-10-20 03:28:47 +00002967 if (TL.getType()->isEnumeralType())
2968 SemaRef.Diag(TL.getBeginLoc(),
2969 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregor14454802011-02-25 02:25:35 +00002970 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2971 Q.getLocalEndLoc());
2972 break;
2973 }
Richard Trieude756fb2011-05-07 01:36:37 +00002974 // If the nested-name-specifier is an invalid type def, don't emit an
2975 // error because a previous error should have already been emitted.
David Blaikie6adc78e2013-02-18 22:06:02 +00002976 TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
2977 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002978 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieude756fb2011-05-07 01:36:37 +00002979 << TL.getType() << SS.getRange();
2980 }
Douglas Gregor14454802011-02-25 02:25:35 +00002981 return NestedNameSpecifierLoc();
2982 }
Douglas Gregore16af532011-02-28 18:50:33 +00002983 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002984
Douglas Gregore16af532011-02-28 18:50:33 +00002985 // The qualifier-in-scope and object type only apply to the leftmost entity.
Douglas Gregor14454802011-02-25 02:25:35 +00002986 FirstQualifierInScope = 0;
Douglas Gregore16af532011-02-28 18:50:33 +00002987 ObjectType = QualType();
Douglas Gregor14454802011-02-25 02:25:35 +00002988 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002989
Douglas Gregor14454802011-02-25 02:25:35 +00002990 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier1dcde962012-08-08 18:46:20 +00002991 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregor14454802011-02-25 02:25:35 +00002992 !getDerived().AlwaysRebuild())
2993 return NNS;
Chad Rosier1dcde962012-08-08 18:46:20 +00002994
2995 // If we can re-use the source-location data from the original
Douglas Gregor14454802011-02-25 02:25:35 +00002996 // nested-name-specifier, do so.
2997 if (SS.location_size() == NNS.getDataLength() &&
2998 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2999 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
3000
3001 // Allocate new nested-name-specifier location information.
3002 return SS.getWithLocInContext(SemaRef.Context);
3003}
3004
3005template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003006DeclarationNameInfo
3007TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00003008::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003009 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003010 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003011 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003012
3013 switch (Name.getNameKind()) {
3014 case DeclarationName::Identifier:
3015 case DeclarationName::ObjCZeroArgSelector:
3016 case DeclarationName::ObjCOneArgSelector:
3017 case DeclarationName::ObjCMultiArgSelector:
3018 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00003019 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00003020 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003021 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00003022
Douglas Gregorf816bd72009-09-03 22:13:48 +00003023 case DeclarationName::CXXConstructorName:
3024 case DeclarationName::CXXDestructorName:
3025 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003026 TypeSourceInfo *NewTInfo;
3027 CanQualType NewCanTy;
3028 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00003029 NewTInfo = getDerived().TransformType(OldTInfo);
3030 if (!NewTInfo)
3031 return DeclarationNameInfo();
3032 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003033 }
3034 else {
3035 NewTInfo = 0;
3036 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00003037 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003038 if (NewT.isNull())
3039 return DeclarationNameInfo();
3040 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
3041 }
Mike Stump11289f42009-09-09 15:08:12 +00003042
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003043 DeclarationName NewName
3044 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
3045 NewCanTy);
3046 DeclarationNameInfo NewNameInfo(NameInfo);
3047 NewNameInfo.setName(NewName);
3048 NewNameInfo.setNamedTypeInfo(NewTInfo);
3049 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00003050 }
Mike Stump11289f42009-09-09 15:08:12 +00003051 }
3052
David Blaikie83d382b2011-09-23 05:06:16 +00003053 llvm_unreachable("Unknown name kind.");
Douglas Gregorf816bd72009-09-03 22:13:48 +00003054}
3055
3056template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003057TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00003058TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
3059 TemplateName Name,
3060 SourceLocation NameLoc,
3061 QualType ObjectType,
3062 NamedDecl *FirstQualifierInScope) {
3063 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
3064 TemplateDecl *Template = QTN->getTemplateDecl();
3065 assert(Template && "qualified template name must refer to a template");
Chad Rosier1dcde962012-08-08 18:46:20 +00003066
Douglas Gregor9db53502011-03-02 18:07:45 +00003067 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003068 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003069 Template));
3070 if (!TransTemplate)
3071 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003072
Douglas Gregor9db53502011-03-02 18:07:45 +00003073 if (!getDerived().AlwaysRebuild() &&
3074 SS.getScopeRep() == QTN->getQualifier() &&
3075 TransTemplate == Template)
3076 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003077
Douglas Gregor9db53502011-03-02 18:07:45 +00003078 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
3079 TransTemplate);
3080 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003081
Douglas Gregor9db53502011-03-02 18:07:45 +00003082 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
3083 if (SS.getScopeRep()) {
3084 // These apply to the scope specifier, not the template.
3085 ObjectType = QualType();
3086 FirstQualifierInScope = 0;
Chad Rosier1dcde962012-08-08 18:46:20 +00003087 }
3088
Douglas Gregor9db53502011-03-02 18:07:45 +00003089 if (!getDerived().AlwaysRebuild() &&
3090 SS.getScopeRep() == DTN->getQualifier() &&
3091 ObjectType.isNull())
3092 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003093
Douglas Gregor9db53502011-03-02 18:07:45 +00003094 if (DTN->isIdentifier()) {
3095 return getDerived().RebuildTemplateName(SS,
Chad Rosier1dcde962012-08-08 18:46:20 +00003096 *DTN->getIdentifier(),
Douglas Gregor9db53502011-03-02 18:07:45 +00003097 NameLoc,
3098 ObjectType,
3099 FirstQualifierInScope);
3100 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003101
Douglas Gregor9db53502011-03-02 18:07:45 +00003102 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
3103 ObjectType);
3104 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003105
Douglas Gregor9db53502011-03-02 18:07:45 +00003106 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
3107 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003108 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003109 Template));
3110 if (!TransTemplate)
3111 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003112
Douglas Gregor9db53502011-03-02 18:07:45 +00003113 if (!getDerived().AlwaysRebuild() &&
3114 TransTemplate == Template)
3115 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003116
Douglas Gregor9db53502011-03-02 18:07:45 +00003117 return TemplateName(TransTemplate);
3118 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003119
Douglas Gregor9db53502011-03-02 18:07:45 +00003120 if (SubstTemplateTemplateParmPackStorage *SubstPack
3121 = Name.getAsSubstTemplateTemplateParmPack()) {
3122 TemplateTemplateParmDecl *TransParam
3123 = cast_or_null<TemplateTemplateParmDecl>(
3124 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
3125 if (!TransParam)
3126 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003127
Douglas Gregor9db53502011-03-02 18:07:45 +00003128 if (!getDerived().AlwaysRebuild() &&
3129 TransParam == SubstPack->getParameterPack())
3130 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003131
3132 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregor9db53502011-03-02 18:07:45 +00003133 SubstPack->getArgumentPack());
3134 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003135
Douglas Gregor9db53502011-03-02 18:07:45 +00003136 // These should be getting filtered out before they reach the AST.
3137 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregor9db53502011-03-02 18:07:45 +00003138}
3139
3140template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003141void TreeTransform<Derived>::InventTemplateArgumentLoc(
3142 const TemplateArgument &Arg,
3143 TemplateArgumentLoc &Output) {
3144 SourceLocation Loc = getDerived().getBaseLocation();
3145 switch (Arg.getKind()) {
3146 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003147 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00003148 break;
3149
3150 case TemplateArgument::Type:
3151 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00003152 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier1dcde962012-08-08 18:46:20 +00003153
John McCall0ad16662009-10-29 08:12:44 +00003154 break;
3155
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003156 case TemplateArgument::Template:
Douglas Gregor9d802122011-03-02 17:09:35 +00003157 case TemplateArgument::TemplateExpansion: {
3158 NestedNameSpecifierLocBuilder Builder;
3159 TemplateName Template = Arg.getAsTemplate();
3160 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3161 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3162 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3163 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003164
Douglas Gregor9d802122011-03-02 17:09:35 +00003165 if (Arg.getKind() == TemplateArgument::Template)
Chad Rosier1dcde962012-08-08 18:46:20 +00003166 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003167 Builder.getWithLocInContext(SemaRef.Context),
3168 Loc);
3169 else
Chad Rosier1dcde962012-08-08 18:46:20 +00003170 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003171 Builder.getWithLocInContext(SemaRef.Context),
3172 Loc, Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003173
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003174 break;
Douglas Gregor9d802122011-03-02 17:09:35 +00003175 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003176
John McCall0ad16662009-10-29 08:12:44 +00003177 case TemplateArgument::Expression:
3178 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3179 break;
3180
3181 case TemplateArgument::Declaration:
3182 case TemplateArgument::Integral:
3183 case TemplateArgument::Pack:
Eli Friedmanb826a002012-09-26 02:36:12 +00003184 case TemplateArgument::NullPtr:
John McCall0d07eb32009-10-29 18:45:58 +00003185 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00003186 break;
3187 }
3188}
3189
3190template<typename Derived>
3191bool TreeTransform<Derived>::TransformTemplateArgument(
3192 const TemplateArgumentLoc &Input,
3193 TemplateArgumentLoc &Output) {
3194 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00003195 switch (Arg.getKind()) {
3196 case TemplateArgument::Null:
3197 case TemplateArgument::Integral:
Eli Friedmancda3db82012-09-25 01:02:42 +00003198 case TemplateArgument::Pack:
3199 case TemplateArgument::Declaration:
Eli Friedmanb826a002012-09-26 02:36:12 +00003200 case TemplateArgument::NullPtr:
3201 llvm_unreachable("Unexpected TemplateArgument");
Mike Stump11289f42009-09-09 15:08:12 +00003202
Douglas Gregore922c772009-08-04 22:27:00 +00003203 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00003204 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall0ad16662009-10-29 08:12:44 +00003205 if (DI == NULL)
John McCallbcd03502009-12-07 02:54:59 +00003206 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00003207
3208 DI = getDerived().TransformType(DI);
3209 if (!DI) return true;
3210
3211 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3212 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003213 }
Mike Stump11289f42009-09-09 15:08:12 +00003214
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003215 case TemplateArgument::Template: {
Douglas Gregor9d802122011-03-02 17:09:35 +00003216 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3217 if (QualifierLoc) {
3218 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3219 if (!QualifierLoc)
3220 return true;
3221 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003222
Douglas Gregordf846d12011-03-02 18:46:51 +00003223 CXXScopeSpec SS;
3224 SS.Adopt(QualifierLoc);
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003225 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00003226 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3227 Input.getTemplateNameLoc());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003228 if (Template.isNull())
3229 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003230
Douglas Gregor9d802122011-03-02 17:09:35 +00003231 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003232 Input.getTemplateNameLoc());
3233 return false;
3234 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003235
3236 case TemplateArgument::TemplateExpansion:
3237 llvm_unreachable("Caller should expand pack expansions");
3238
Douglas Gregore922c772009-08-04 22:27:00 +00003239 case TemplateArgument::Expression: {
Richard Smith764d2fe2011-12-20 02:08:33 +00003240 // Template argument expressions are constant expressions.
Mike Stump11289f42009-09-09 15:08:12 +00003241 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smith764d2fe2011-12-20 02:08:33 +00003242 Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003243
John McCall0ad16662009-10-29 08:12:44 +00003244 Expr *InputExpr = Input.getSourceExpression();
3245 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3246
Chris Lattnercdb591a2011-04-25 20:37:58 +00003247 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanc6237c62012-02-29 03:16:56 +00003248 E = SemaRef.ActOnConstantExpression(E);
John McCall0ad16662009-10-29 08:12:44 +00003249 if (E.isInvalid()) return true;
John McCallb268a282010-08-23 23:25:46 +00003250 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall0ad16662009-10-29 08:12:44 +00003251 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003252 }
Douglas Gregore922c772009-08-04 22:27:00 +00003253 }
Mike Stump11289f42009-09-09 15:08:12 +00003254
Douglas Gregore922c772009-08-04 22:27:00 +00003255 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00003256 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00003257}
3258
Douglas Gregorfe921a72010-12-20 23:36:19 +00003259/// \brief Iterator adaptor that invents template argument location information
3260/// for each of the template arguments in its underlying iterator.
3261template<typename Derived, typename InputIterator>
3262class TemplateArgumentLocInventIterator {
3263 TreeTransform<Derived> &Self;
3264 InputIterator Iter;
Chad Rosier1dcde962012-08-08 18:46:20 +00003265
Douglas Gregorfe921a72010-12-20 23:36:19 +00003266public:
3267 typedef TemplateArgumentLoc value_type;
3268 typedef TemplateArgumentLoc reference;
3269 typedef typename std::iterator_traits<InputIterator>::difference_type
3270 difference_type;
3271 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00003272
Douglas Gregorfe921a72010-12-20 23:36:19 +00003273 class pointer {
3274 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00003275
Douglas Gregorfe921a72010-12-20 23:36:19 +00003276 public:
3277 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003278
Douglas Gregorfe921a72010-12-20 23:36:19 +00003279 const TemplateArgumentLoc *operator->() const { return &Arg; }
3280 };
Chad Rosier1dcde962012-08-08 18:46:20 +00003281
Douglas Gregorfe921a72010-12-20 23:36:19 +00003282 TemplateArgumentLocInventIterator() { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003283
Douglas Gregorfe921a72010-12-20 23:36:19 +00003284 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3285 InputIterator Iter)
3286 : Self(Self), Iter(Iter) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003287
Douglas Gregorfe921a72010-12-20 23:36:19 +00003288 TemplateArgumentLocInventIterator &operator++() {
3289 ++Iter;
3290 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00003291 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003292
Douglas Gregorfe921a72010-12-20 23:36:19 +00003293 TemplateArgumentLocInventIterator operator++(int) {
3294 TemplateArgumentLocInventIterator Old(*this);
3295 ++(*this);
3296 return Old;
3297 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003298
Douglas Gregorfe921a72010-12-20 23:36:19 +00003299 reference operator*() const {
3300 TemplateArgumentLoc Result;
3301 Self.InventTemplateArgumentLoc(*Iter, Result);
3302 return Result;
3303 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003304
Douglas Gregorfe921a72010-12-20 23:36:19 +00003305 pointer operator->() const { return pointer(**this); }
Chad Rosier1dcde962012-08-08 18:46:20 +00003306
Douglas Gregorfe921a72010-12-20 23:36:19 +00003307 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3308 const TemplateArgumentLocInventIterator &Y) {
3309 return X.Iter == Y.Iter;
3310 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00003311
Douglas Gregorfe921a72010-12-20 23:36:19 +00003312 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3313 const TemplateArgumentLocInventIterator &Y) {
3314 return X.Iter != Y.Iter;
3315 }
3316};
Chad Rosier1dcde962012-08-08 18:46:20 +00003317
Douglas Gregor42cafa82010-12-20 17:42:22 +00003318template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00003319template<typename InputIterator>
3320bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3321 InputIterator Last,
Douglas Gregor42cafa82010-12-20 17:42:22 +00003322 TemplateArgumentListInfo &Outputs) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00003323 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00003324 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00003325 TemplateArgumentLoc In = *First;
Chad Rosier1dcde962012-08-08 18:46:20 +00003326
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003327 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3328 // Unpack argument packs, which we translate them into separate
3329 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00003330 // FIXME: We could do much better if we could guarantee that the
3331 // TemplateArgumentLocInfo for the pack expansion would be usable for
3332 // all of the template arguments in the argument pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00003333 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003334 TemplateArgument::pack_iterator>
3335 PackLocIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00003336 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003337 In.getArgument().pack_begin()),
3338 PackLocIterator(*this,
3339 In.getArgument().pack_end()),
3340 Outputs))
3341 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003342
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003343 continue;
3344 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003345
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003346 if (In.getArgument().isPackExpansion()) {
3347 // We have a pack expansion, for which we will be substituting into
3348 // the pattern.
3349 SourceLocation Ellipsis;
David Blaikie05785d12013-02-20 22:23:23 +00003350 Optional<unsigned> OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003351 TemplateArgumentLoc Pattern
Eli Friedman94e9eaa2013-06-20 04:11:21 +00003352 = getSema().getTemplateArgumentPackExpansionPattern(
3353 In, Ellipsis, OrigNumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00003354
Chris Lattner01cf8db2011-07-20 06:58:45 +00003355 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003356 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3357 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00003358
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003359 // Determine whether the set of unexpanded parameter packs can and should
3360 // be expanded.
3361 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003362 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00003363 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003364 if (getDerived().TryExpandParameterPacks(Ellipsis,
3365 Pattern.getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003366 Unexpanded,
Chad Rosier1dcde962012-08-08 18:46:20 +00003367 Expand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003368 RetainExpansion,
3369 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003370 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003371
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003372 if (!Expand) {
3373 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00003374 // transformation on the pack expansion, producing another pack
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003375 // expansion.
3376 TemplateArgumentLoc OutPattern;
3377 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3378 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3379 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003380
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003381 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3382 NumExpansions);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003383 if (Out.getArgument().isNull())
3384 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003385
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003386 Outputs.addArgument(Out);
3387 continue;
3388 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003389
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003390 // The transform has determined that we should perform an elementwise
3391 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003392 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003393 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3394
3395 if (getDerived().TransformTemplateArgument(Pattern, Out))
3396 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003397
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003398 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003399 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3400 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003401 if (Out.getArgument().isNull())
3402 return true;
3403 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003404
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003405 Outputs.addArgument(Out);
3406 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003407
Douglas Gregor48d24112011-01-10 20:53:55 +00003408 // If we're supposed to retain a pack expansion, do so by temporarily
3409 // forgetting the partially-substituted parameter pack.
3410 if (RetainExpansion) {
3411 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00003412
Douglas Gregor48d24112011-01-10 20:53:55 +00003413 if (getDerived().TransformTemplateArgument(Pattern, Out))
3414 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003415
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003416 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3417 OrigNumExpansions);
Douglas Gregor48d24112011-01-10 20:53:55 +00003418 if (Out.getArgument().isNull())
3419 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003420
Douglas Gregor48d24112011-01-10 20:53:55 +00003421 Outputs.addArgument(Out);
3422 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003423
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003424 continue;
3425 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003426
3427 // The simple case:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003428 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor42cafa82010-12-20 17:42:22 +00003429 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003430
Douglas Gregor42cafa82010-12-20 17:42:22 +00003431 Outputs.addArgument(Out);
3432 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003433
Douglas Gregor42cafa82010-12-20 17:42:22 +00003434 return false;
3435
3436}
3437
Douglas Gregord6ff3322009-08-04 16:50:30 +00003438//===----------------------------------------------------------------------===//
3439// Type transformation
3440//===----------------------------------------------------------------------===//
3441
3442template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003443QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00003444 if (getDerived().AlreadyTransformed(T))
3445 return T;
Mike Stump11289f42009-09-09 15:08:12 +00003446
John McCall550e0c22009-10-21 00:40:46 +00003447 // Temporary workaround. All of these transformations should
3448 // eventually turn into transformations on TypeLocs.
Douglas Gregor2d525f02011-01-25 19:13:18 +00003449 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3450 getDerived().getBaseLocation());
Chad Rosier1dcde962012-08-08 18:46:20 +00003451
John McCall31f82722010-11-12 08:19:04 +00003452 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00003453
John McCall550e0c22009-10-21 00:40:46 +00003454 if (!NewDI)
3455 return QualType();
3456
3457 return NewDI->getType();
3458}
3459
3460template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003461TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smith764d2fe2011-12-20 02:08:33 +00003462 // Refine the base location to the type's location.
3463 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3464 getDerived().getBaseEntity());
John McCall550e0c22009-10-21 00:40:46 +00003465 if (getDerived().AlreadyTransformed(DI->getType()))
3466 return DI;
3467
3468 TypeLocBuilder TLB;
3469
3470 TypeLoc TL = DI->getTypeLoc();
3471 TLB.reserve(TL.getFullDataSize());
3472
John McCall31f82722010-11-12 08:19:04 +00003473 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00003474 if (Result.isNull())
3475 return 0;
3476
John McCallbcd03502009-12-07 02:54:59 +00003477 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00003478}
3479
3480template<typename Derived>
3481QualType
John McCall31f82722010-11-12 08:19:04 +00003482TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003483 switch (T.getTypeLocClass()) {
3484#define ABSTRACT_TYPELOC(CLASS, PARENT)
David Blaikie6adc78e2013-02-18 22:06:02 +00003485#define TYPELOC(CLASS, PARENT) \
3486 case TypeLoc::CLASS: \
3487 return getDerived().Transform##CLASS##Type(TLB, \
3488 T.castAs<CLASS##TypeLoc>());
John McCall550e0c22009-10-21 00:40:46 +00003489#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00003490 }
Mike Stump11289f42009-09-09 15:08:12 +00003491
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003492 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00003493}
3494
3495/// FIXME: By default, this routine adds type qualifiers only to types
3496/// that can have qualifiers, and silently suppresses those qualifiers
3497/// that are not permitted (e.g., qualifiers on reference or function
3498/// types). This is the right thing for template instantiation, but
3499/// probably not for other clients.
3500template<typename Derived>
3501QualType
3502TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003503 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00003504 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00003505
John McCall31f82722010-11-12 08:19:04 +00003506 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00003507 if (Result.isNull())
3508 return QualType();
3509
3510 // Silently suppress qualifiers if the result type can't be qualified.
3511 // FIXME: this is the right thing for template instantiation, but
3512 // probably not for other clients.
3513 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00003514 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00003515
John McCall31168b02011-06-15 23:02:42 +00003516 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore46db902011-06-17 22:11:49 +00003517 // resulting type.
3518 if (Quals.hasObjCLifetime()) {
3519 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3520 Quals.removeObjCLifetime();
Douglas Gregord7357a92011-06-17 23:16:24 +00003521 else if (Result.getObjCLifetime()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003522 // Objective-C ARC:
Douglas Gregore46db902011-06-17 22:11:49 +00003523 // A lifetime qualifier applied to a substituted template parameter
3524 // overrides the lifetime qualifier from the template argument.
Douglas Gregorf4e43312013-01-17 23:59:28 +00003525 const AutoType *AutoTy;
Chad Rosier1dcde962012-08-08 18:46:20 +00003526 if (const SubstTemplateTypeParmType *SubstTypeParam
Douglas Gregore46db902011-06-17 22:11:49 +00003527 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3528 QualType Replacement = SubstTypeParam->getReplacementType();
3529 Qualifiers Qs = Replacement.getQualifiers();
3530 Qs.removeObjCLifetime();
Chad Rosier1dcde962012-08-08 18:46:20 +00003531 Replacement
Douglas Gregore46db902011-06-17 22:11:49 +00003532 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3533 Qs);
3534 Result = SemaRef.Context.getSubstTemplateTypeParmType(
Chad Rosier1dcde962012-08-08 18:46:20 +00003535 SubstTypeParam->getReplacedParameter(),
Douglas Gregore46db902011-06-17 22:11:49 +00003536 Replacement);
3537 TLB.TypeWasModifiedSafely(Result);
Douglas Gregorf4e43312013-01-17 23:59:28 +00003538 } else if ((AutoTy = dyn_cast<AutoType>(Result)) && AutoTy->isDeduced()) {
3539 // 'auto' types behave the same way as template parameters.
3540 QualType Deduced = AutoTy->getDeducedType();
3541 Qualifiers Qs = Deduced.getQualifiers();
3542 Qs.removeObjCLifetime();
3543 Deduced = SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(),
3544 Qs);
Faisal Vali2b391ab2013-09-26 19:54:12 +00003545 Result = SemaRef.Context.getAutoType(Deduced, AutoTy->isDecltypeAuto(),
3546 AutoTy->isDependentType());
Douglas Gregorf4e43312013-01-17 23:59:28 +00003547 TLB.TypeWasModifiedSafely(Result);
Douglas Gregore46db902011-06-17 22:11:49 +00003548 } else {
Douglas Gregord7357a92011-06-17 23:16:24 +00003549 // Otherwise, complain about the addition of a qualifier to an
3550 // already-qualified type.
Eli Friedman7152fbe2013-06-07 20:31:48 +00003551 SourceRange R = T.getUnqualifiedLoc().getSourceRange();
Argyrios Kyrtzidiscff00d92011-06-24 00:08:59 +00003552 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregord7357a92011-06-17 23:16:24 +00003553 << Result << R;
Chad Rosier1dcde962012-08-08 18:46:20 +00003554
Douglas Gregore46db902011-06-17 22:11:49 +00003555 Quals.removeObjCLifetime();
3556 }
3557 }
3558 }
John McCallcb0f89a2010-06-05 06:41:15 +00003559 if (!Quals.empty()) {
3560 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
Richard Smithdeec0742013-03-27 23:36:39 +00003561 // BuildQualifiedType might not add qualifiers if they are invalid.
3562 if (Result.hasLocalQualifiers())
3563 TLB.push<QualifiedTypeLoc>(Result);
John McCallcb0f89a2010-06-05 06:41:15 +00003564 // No location information to preserve.
3565 }
John McCall550e0c22009-10-21 00:40:46 +00003566
3567 return Result;
3568}
3569
Douglas Gregor14454802011-02-25 02:25:35 +00003570template<typename Derived>
3571TypeLoc
3572TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3573 QualType ObjectType,
3574 NamedDecl *UnqualLookup,
3575 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003576 if (getDerived().AlreadyTransformed(TL.getType()))
Douglas Gregor14454802011-02-25 02:25:35 +00003577 return TL;
Chad Rosier1dcde962012-08-08 18:46:20 +00003578
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003579 TypeSourceInfo *TSI =
3580 TransformTSIInObjectScope(TL, ObjectType, UnqualLookup, SS);
3581 if (TSI)
3582 return TSI->getTypeLoc();
3583 return TypeLoc();
Douglas Gregor14454802011-02-25 02:25:35 +00003584}
3585
Douglas Gregor579c15f2011-03-02 18:32:08 +00003586template<typename Derived>
3587TypeSourceInfo *
3588TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3589 QualType ObjectType,
3590 NamedDecl *UnqualLookup,
3591 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003592 if (getDerived().AlreadyTransformed(TSInfo->getType()))
Douglas Gregor579c15f2011-03-02 18:32:08 +00003593 return TSInfo;
Chad Rosier1dcde962012-08-08 18:46:20 +00003594
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003595 return TransformTSIInObjectScope(TSInfo->getTypeLoc(), ObjectType,
3596 UnqualLookup, SS);
3597}
3598
3599template <typename Derived>
3600TypeSourceInfo *TreeTransform<Derived>::TransformTSIInObjectScope(
3601 TypeLoc TL, QualType ObjectType, NamedDecl *UnqualLookup,
3602 CXXScopeSpec &SS) {
3603 QualType T = TL.getType();
3604 assert(!getDerived().AlreadyTransformed(T));
3605
Douglas Gregor579c15f2011-03-02 18:32:08 +00003606 TypeLocBuilder TLB;
3607 QualType Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00003608
Douglas Gregor579c15f2011-03-02 18:32:08 +00003609 if (isa<TemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00003610 TemplateSpecializationTypeLoc SpecTL =
3611 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00003612
Douglas Gregor579c15f2011-03-02 18:32:08 +00003613 TemplateName Template
3614 = getDerived().TransformTemplateName(SS,
3615 SpecTL.getTypePtr()->getTemplateName(),
3616 SpecTL.getTemplateNameLoc(),
3617 ObjectType, UnqualLookup);
Chad Rosier1dcde962012-08-08 18:46:20 +00003618 if (Template.isNull())
Douglas Gregor579c15f2011-03-02 18:32:08 +00003619 return 0;
Chad Rosier1dcde962012-08-08 18:46:20 +00003620
3621 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregor579c15f2011-03-02 18:32:08 +00003622 Template);
3623 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00003624 DependentTemplateSpecializationTypeLoc SpecTL =
3625 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00003626
Douglas Gregor579c15f2011-03-02 18:32:08 +00003627 TemplateName Template
Chad Rosier1dcde962012-08-08 18:46:20 +00003628 = getDerived().RebuildTemplateName(SS,
3629 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00003630 SpecTL.getTemplateNameLoc(),
Douglas Gregor579c15f2011-03-02 18:32:08 +00003631 ObjectType, UnqualLookup);
3632 if (Template.isNull())
3633 return 0;
Chad Rosier1dcde962012-08-08 18:46:20 +00003634
3635 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregor579c15f2011-03-02 18:32:08 +00003636 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00003637 Template,
3638 SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00003639 } else {
3640 // Nothing special needs to be done for these.
3641 Result = getDerived().TransformType(TLB, TL);
3642 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003643
3644 if (Result.isNull())
Douglas Gregor579c15f2011-03-02 18:32:08 +00003645 return 0;
Chad Rosier1dcde962012-08-08 18:46:20 +00003646
Douglas Gregor579c15f2011-03-02 18:32:08 +00003647 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3648}
3649
John McCall550e0c22009-10-21 00:40:46 +00003650template <class TyLoc> static inline
3651QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3652 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3653 NewT.setNameLoc(T.getNameLoc());
3654 return T.getType();
3655}
3656
John McCall550e0c22009-10-21 00:40:46 +00003657template<typename Derived>
3658QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003659 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00003660 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3661 NewT.setBuiltinLoc(T.getBuiltinLoc());
3662 if (T.needsExtraLocalData())
3663 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3664 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003665}
Mike Stump11289f42009-09-09 15:08:12 +00003666
Douglas Gregord6ff3322009-08-04 16:50:30 +00003667template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003668QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003669 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003670 // FIXME: recurse?
3671 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003672}
Mike Stump11289f42009-09-09 15:08:12 +00003673
Reid Kleckner0503a872013-12-05 01:23:43 +00003674template <typename Derived>
3675QualType TreeTransform<Derived>::TransformAdjustedType(TypeLocBuilder &TLB,
3676 AdjustedTypeLoc TL) {
3677 // Adjustments applied during transformation are handled elsewhere.
3678 return getDerived().TransformType(TLB, TL.getOriginalLoc());
3679}
3680
Douglas Gregord6ff3322009-08-04 16:50:30 +00003681template<typename Derived>
Reid Kleckner8a365022013-06-24 17:51:48 +00003682QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
3683 DecayedTypeLoc TL) {
3684 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
3685 if (OriginalType.isNull())
3686 return QualType();
3687
3688 QualType Result = TL.getType();
3689 if (getDerived().AlwaysRebuild() ||
3690 OriginalType != TL.getOriginalLoc().getType())
3691 Result = SemaRef.Context.getDecayedType(OriginalType);
3692 TLB.push<DecayedTypeLoc>(Result);
3693 // Nothing to set for DecayedTypeLoc.
3694 return Result;
3695}
3696
3697template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003698QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003699 PointerTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003700 QualType PointeeType
3701 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003702 if (PointeeType.isNull())
3703 return QualType();
3704
3705 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00003706 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003707 // A dependent pointer type 'T *' has is being transformed such
3708 // that an Objective-C class type is being replaced for 'T'. The
3709 // resulting pointer type is an ObjCObjectPointerType, not a
3710 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00003711 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier1dcde962012-08-08 18:46:20 +00003712
John McCall8b07ec22010-05-15 11:32:37 +00003713 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3714 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003715 return Result;
3716 }
John McCall31f82722010-11-12 08:19:04 +00003717
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003718 if (getDerived().AlwaysRebuild() ||
3719 PointeeType != TL.getPointeeLoc().getType()) {
3720 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3721 if (Result.isNull())
3722 return QualType();
3723 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003724
John McCall31168b02011-06-15 23:02:42 +00003725 // Objective-C ARC can add lifetime qualifiers to the type that we're
3726 // pointing to.
3727 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier1dcde962012-08-08 18:46:20 +00003728
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003729 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3730 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00003731 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003732}
Mike Stump11289f42009-09-09 15:08:12 +00003733
3734template<typename Derived>
3735QualType
John McCall550e0c22009-10-21 00:40:46 +00003736TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003737 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00003738 QualType PointeeType
Chad Rosier1dcde962012-08-08 18:46:20 +00003739 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3740 if (PointeeType.isNull())
3741 return QualType();
3742
3743 QualType Result = TL.getType();
3744 if (getDerived().AlwaysRebuild() ||
3745 PointeeType != TL.getPointeeLoc().getType()) {
3746 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00003747 TL.getSigilLoc());
3748 if (Result.isNull())
3749 return QualType();
3750 }
3751
Douglas Gregor049211a2010-04-22 16:50:51 +00003752 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00003753 NewT.setSigilLoc(TL.getSigilLoc());
3754 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003755}
3756
John McCall70dd5f62009-10-30 00:06:24 +00003757/// Transforms a reference type. Note that somewhat paradoxically we
3758/// don't care whether the type itself is an l-value type or an r-value
3759/// type; we only care if the type was *written* as an l-value type
3760/// or an r-value type.
3761template<typename Derived>
3762QualType
3763TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003764 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00003765 const ReferenceType *T = TL.getTypePtr();
3766
3767 // Note that this works with the pointee-as-written.
3768 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3769 if (PointeeType.isNull())
3770 return QualType();
3771
3772 QualType Result = TL.getType();
3773 if (getDerived().AlwaysRebuild() ||
3774 PointeeType != T->getPointeeTypeAsWritten()) {
3775 Result = getDerived().RebuildReferenceType(PointeeType,
3776 T->isSpelledAsLValue(),
3777 TL.getSigilLoc());
3778 if (Result.isNull())
3779 return QualType();
3780 }
3781
John McCall31168b02011-06-15 23:02:42 +00003782 // Objective-C ARC can add lifetime qualifiers to the type that we're
3783 // referring to.
3784 TLB.TypeWasModifiedSafely(
3785 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3786
John McCall70dd5f62009-10-30 00:06:24 +00003787 // r-value references can be rebuilt as l-value references.
3788 ReferenceTypeLoc NewTL;
3789 if (isa<LValueReferenceType>(Result))
3790 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3791 else
3792 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3793 NewTL.setSigilLoc(TL.getSigilLoc());
3794
3795 return Result;
3796}
3797
Mike Stump11289f42009-09-09 15:08:12 +00003798template<typename Derived>
3799QualType
John McCall550e0c22009-10-21 00:40:46 +00003800TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003801 LValueReferenceTypeLoc TL) {
3802 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003803}
3804
Mike Stump11289f42009-09-09 15:08:12 +00003805template<typename Derived>
3806QualType
John McCall550e0c22009-10-21 00:40:46 +00003807TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003808 RValueReferenceTypeLoc TL) {
3809 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003810}
Mike Stump11289f42009-09-09 15:08:12 +00003811
Douglas Gregord6ff3322009-08-04 16:50:30 +00003812template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003813QualType
John McCall550e0c22009-10-21 00:40:46 +00003814TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003815 MemberPointerTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003816 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003817 if (PointeeType.isNull())
3818 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003819
Abramo Bagnara509357842011-03-05 14:42:21 +00003820 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
3821 TypeSourceInfo* NewClsTInfo = 0;
3822 if (OldClsTInfo) {
3823 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3824 if (!NewClsTInfo)
3825 return QualType();
3826 }
3827
3828 const MemberPointerType *T = TL.getTypePtr();
3829 QualType OldClsType = QualType(T->getClass(), 0);
3830 QualType NewClsType;
3831 if (NewClsTInfo)
3832 NewClsType = NewClsTInfo->getType();
3833 else {
3834 NewClsType = getDerived().TransformType(OldClsType);
3835 if (NewClsType.isNull())
3836 return QualType();
3837 }
Mike Stump11289f42009-09-09 15:08:12 +00003838
John McCall550e0c22009-10-21 00:40:46 +00003839 QualType Result = TL.getType();
3840 if (getDerived().AlwaysRebuild() ||
3841 PointeeType != T->getPointeeType() ||
Abramo Bagnara509357842011-03-05 14:42:21 +00003842 NewClsType != OldClsType) {
3843 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall70dd5f62009-10-30 00:06:24 +00003844 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00003845 if (Result.isNull())
3846 return QualType();
3847 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00003848
Reid Kleckner0503a872013-12-05 01:23:43 +00003849 // If we had to adjust the pointee type when building a member pointer, make
3850 // sure to push TypeLoc info for it.
3851 const MemberPointerType *MPT = Result->getAs<MemberPointerType>();
3852 if (MPT && PointeeType != MPT->getPointeeType()) {
3853 assert(isa<AdjustedType>(MPT->getPointeeType()));
3854 TLB.push<AdjustedTypeLoc>(MPT->getPointeeType());
3855 }
3856
John McCall550e0c22009-10-21 00:40:46 +00003857 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3858 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnara509357842011-03-05 14:42:21 +00003859 NewTL.setClassTInfo(NewClsTInfo);
John McCall550e0c22009-10-21 00:40:46 +00003860
3861 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003862}
3863
Mike Stump11289f42009-09-09 15:08:12 +00003864template<typename Derived>
3865QualType
John McCall550e0c22009-10-21 00:40:46 +00003866TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003867 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003868 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003869 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003870 if (ElementType.isNull())
3871 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003872
John McCall550e0c22009-10-21 00:40:46 +00003873 QualType Result = TL.getType();
3874 if (getDerived().AlwaysRebuild() ||
3875 ElementType != T->getElementType()) {
3876 Result = getDerived().RebuildConstantArrayType(ElementType,
3877 T->getSizeModifier(),
3878 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00003879 T->getIndexTypeCVRQualifiers(),
3880 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003881 if (Result.isNull())
3882 return QualType();
3883 }
Eli Friedmanf7f102f2012-01-25 22:19:07 +00003884
3885 // We might have either a ConstantArrayType or a VariableArrayType now:
3886 // a ConstantArrayType is allowed to have an element type which is a
3887 // VariableArrayType if the type is dependent. Fortunately, all array
3888 // types have the same location layout.
3889 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00003890 NewTL.setLBracketLoc(TL.getLBracketLoc());
3891 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00003892
John McCall550e0c22009-10-21 00:40:46 +00003893 Expr *Size = TL.getSizeExpr();
3894 if (Size) {
Richard Smith764d2fe2011-12-20 02:08:33 +00003895 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3896 Sema::ConstantEvaluated);
John McCall550e0c22009-10-21 00:40:46 +00003897 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
Eli Friedmanc6237c62012-02-29 03:16:56 +00003898 Size = SemaRef.ActOnConstantExpression(Size).take();
John McCall550e0c22009-10-21 00:40:46 +00003899 }
3900 NewTL.setSizeExpr(Size);
3901
3902 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003903}
Mike Stump11289f42009-09-09 15:08:12 +00003904
Douglas Gregord6ff3322009-08-04 16:50:30 +00003905template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003906QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00003907 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003908 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003909 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003910 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003911 if (ElementType.isNull())
3912 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003913
John McCall550e0c22009-10-21 00:40:46 +00003914 QualType Result = TL.getType();
3915 if (getDerived().AlwaysRebuild() ||
3916 ElementType != T->getElementType()) {
3917 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00003918 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00003919 T->getIndexTypeCVRQualifiers(),
3920 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003921 if (Result.isNull())
3922 return QualType();
3923 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003924
John McCall550e0c22009-10-21 00:40:46 +00003925 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3926 NewTL.setLBracketLoc(TL.getLBracketLoc());
3927 NewTL.setRBracketLoc(TL.getRBracketLoc());
3928 NewTL.setSizeExpr(0);
3929
3930 return Result;
3931}
3932
3933template<typename Derived>
3934QualType
3935TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003936 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003937 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003938 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3939 if (ElementType.isNull())
3940 return QualType();
3941
John McCalldadc5752010-08-24 06:29:42 +00003942 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00003943 = getDerived().TransformExpr(T->getSizeExpr());
3944 if (SizeResult.isInvalid())
3945 return QualType();
3946
John McCallb268a282010-08-23 23:25:46 +00003947 Expr *Size = SizeResult.take();
John McCall550e0c22009-10-21 00:40:46 +00003948
3949 QualType Result = TL.getType();
3950 if (getDerived().AlwaysRebuild() ||
3951 ElementType != T->getElementType() ||
3952 Size != T->getSizeExpr()) {
3953 Result = getDerived().RebuildVariableArrayType(ElementType,
3954 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00003955 Size,
John McCall550e0c22009-10-21 00:40:46 +00003956 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00003957 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003958 if (Result.isNull())
3959 return QualType();
3960 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003961
Serge Pavlov774c6d02014-02-06 03:49:11 +00003962 // We might have constant size array now, but fortunately it has the same
3963 // location layout.
3964 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00003965 NewTL.setLBracketLoc(TL.getLBracketLoc());
3966 NewTL.setRBracketLoc(TL.getRBracketLoc());
3967 NewTL.setSizeExpr(Size);
3968
3969 return Result;
3970}
3971
3972template<typename Derived>
3973QualType
3974TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003975 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003976 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003977 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3978 if (ElementType.isNull())
3979 return QualType();
3980
Richard Smith764d2fe2011-12-20 02:08:33 +00003981 // Array bounds are constant expressions.
3982 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3983 Sema::ConstantEvaluated);
John McCall550e0c22009-10-21 00:40:46 +00003984
John McCall33ddac02011-01-19 10:06:00 +00003985 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3986 Expr *origSize = TL.getSizeExpr();
3987 if (!origSize) origSize = T->getSizeExpr();
3988
3989 ExprResult sizeResult
3990 = getDerived().TransformExpr(origSize);
Eli Friedmanc6237c62012-02-29 03:16:56 +00003991 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall33ddac02011-01-19 10:06:00 +00003992 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00003993 return QualType();
3994
John McCall33ddac02011-01-19 10:06:00 +00003995 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00003996
3997 QualType Result = TL.getType();
3998 if (getDerived().AlwaysRebuild() ||
3999 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00004000 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00004001 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
4002 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00004003 size,
John McCall550e0c22009-10-21 00:40:46 +00004004 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004005 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004006 if (Result.isNull())
4007 return QualType();
4008 }
John McCall550e0c22009-10-21 00:40:46 +00004009
4010 // We might have any sort of array type now, but fortunately they
4011 // all have the same location layout.
4012 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4013 NewTL.setLBracketLoc(TL.getLBracketLoc());
4014 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00004015 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00004016
4017 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004018}
Mike Stump11289f42009-09-09 15:08:12 +00004019
4020template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004021QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00004022 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004023 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004024 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004025
4026 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00004027 QualType ElementType = getDerived().TransformType(T->getElementType());
4028 if (ElementType.isNull())
4029 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004030
Richard Smith764d2fe2011-12-20 02:08:33 +00004031 // Vector sizes are constant expressions.
4032 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4033 Sema::ConstantEvaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00004034
John McCalldadc5752010-08-24 06:29:42 +00004035 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanc6237c62012-02-29 03:16:56 +00004036 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004037 if (Size.isInvalid())
4038 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004039
John McCall550e0c22009-10-21 00:40:46 +00004040 QualType Result = TL.getType();
4041 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00004042 ElementType != T->getElementType() ||
4043 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00004044 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCallb268a282010-08-23 23:25:46 +00004045 Size.take(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00004046 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00004047 if (Result.isNull())
4048 return QualType();
4049 }
John McCall550e0c22009-10-21 00:40:46 +00004050
4051 // Result might be dependent or not.
4052 if (isa<DependentSizedExtVectorType>(Result)) {
4053 DependentSizedExtVectorTypeLoc NewTL
4054 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
4055 NewTL.setNameLoc(TL.getNameLoc());
4056 } else {
4057 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4058 NewTL.setNameLoc(TL.getNameLoc());
4059 }
4060
4061 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004062}
Mike Stump11289f42009-09-09 15:08:12 +00004063
4064template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004065QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004066 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004067 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004068 QualType ElementType = getDerived().TransformType(T->getElementType());
4069 if (ElementType.isNull())
4070 return QualType();
4071
John McCall550e0c22009-10-21 00:40:46 +00004072 QualType Result = TL.getType();
4073 if (getDerived().AlwaysRebuild() ||
4074 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00004075 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00004076 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00004077 if (Result.isNull())
4078 return QualType();
4079 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004080
John McCall550e0c22009-10-21 00:40:46 +00004081 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
4082 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004083
John McCall550e0c22009-10-21 00:40:46 +00004084 return Result;
4085}
4086
4087template<typename Derived>
4088QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004089 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004090 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004091 QualType ElementType = getDerived().TransformType(T->getElementType());
4092 if (ElementType.isNull())
4093 return QualType();
4094
4095 QualType Result = TL.getType();
4096 if (getDerived().AlwaysRebuild() ||
4097 ElementType != T->getElementType()) {
4098 Result = getDerived().RebuildExtVectorType(ElementType,
4099 T->getNumElements(),
4100 /*FIXME*/ SourceLocation());
4101 if (Result.isNull())
4102 return QualType();
4103 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004104
John McCall550e0c22009-10-21 00:40:46 +00004105 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4106 NewTL.setNameLoc(TL.getNameLoc());
4107
4108 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004109}
Mike Stump11289f42009-09-09 15:08:12 +00004110
David Blaikie05785d12013-02-20 22:23:23 +00004111template <typename Derived>
4112ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
4113 ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
4114 bool ExpectParameterPack) {
John McCall58f10c32010-03-11 09:03:00 +00004115 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor715e4612011-01-14 22:40:04 +00004116 TypeSourceInfo *NewDI = 0;
Chad Rosier1dcde962012-08-08 18:46:20 +00004117
Douglas Gregor715e4612011-01-14 22:40:04 +00004118 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004119 // If we're substituting into a pack expansion type and we know the
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004120 // length we want to expand to, just substitute for the pattern.
Douglas Gregor715e4612011-01-14 22:40:04 +00004121 TypeLoc OldTL = OldDI->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004122 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004123
Douglas Gregor715e4612011-01-14 22:40:04 +00004124 TypeLocBuilder TLB;
4125 TypeLoc NewTL = OldDI->getTypeLoc();
4126 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00004127
4128 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor715e4612011-01-14 22:40:04 +00004129 OldExpansionTL.getPatternLoc());
4130 if (Result.isNull())
4131 return 0;
Chad Rosier1dcde962012-08-08 18:46:20 +00004132
4133 Result = RebuildPackExpansionType(Result,
4134 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor715e4612011-01-14 22:40:04 +00004135 OldExpansionTL.getEllipsisLoc(),
4136 NumExpansions);
4137 if (Result.isNull())
4138 return 0;
Chad Rosier1dcde962012-08-08 18:46:20 +00004139
Douglas Gregor715e4612011-01-14 22:40:04 +00004140 PackExpansionTypeLoc NewExpansionTL
4141 = TLB.push<PackExpansionTypeLoc>(Result);
4142 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
4143 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
4144 } else
4145 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00004146 if (!NewDI)
4147 return 0;
4148
John McCall8fb0d9d2011-05-01 22:35:37 +00004149 if (NewDI == OldDI && indexAdjustment == 0)
John McCall58f10c32010-03-11 09:03:00 +00004150 return OldParm;
John McCall8fb0d9d2011-05-01 22:35:37 +00004151
4152 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
4153 OldParm->getDeclContext(),
4154 OldParm->getInnerLocStart(),
4155 OldParm->getLocation(),
4156 OldParm->getIdentifier(),
4157 NewDI->getType(),
4158 NewDI,
4159 OldParm->getStorageClass(),
John McCall8fb0d9d2011-05-01 22:35:37 +00004160 /* DefArg */ NULL);
4161 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
4162 OldParm->getFunctionScopeIndex() + indexAdjustment);
4163 return newParm;
John McCall58f10c32010-03-11 09:03:00 +00004164}
4165
4166template<typename Derived>
4167bool TreeTransform<Derived>::
Douglas Gregordd472162011-01-07 00:20:55 +00004168 TransformFunctionTypeParams(SourceLocation Loc,
4169 ParmVarDecl **Params, unsigned NumParams,
4170 const QualType *ParamTypes,
Chris Lattner01cf8db2011-07-20 06:58:45 +00004171 SmallVectorImpl<QualType> &OutParamTypes,
4172 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004173 int indexAdjustment = 0;
4174
Douglas Gregordd472162011-01-07 00:20:55 +00004175 for (unsigned i = 0; i != NumParams; ++i) {
4176 if (ParmVarDecl *OldParm = Params[i]) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004177 assert(OldParm->getFunctionScopeIndex() == i);
4178
David Blaikie05785d12013-02-20 22:23:23 +00004179 Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004180 ParmVarDecl *NewParm = 0;
Douglas Gregor5499af42011-01-05 23:12:31 +00004181 if (OldParm->isParameterPack()) {
4182 // We have a function parameter pack that may need to be expanded.
Chris Lattner01cf8db2011-07-20 06:58:45 +00004183 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00004184
Douglas Gregor5499af42011-01-05 23:12:31 +00004185 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004186 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004187 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004188 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4189 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004190 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4191
Douglas Gregor5499af42011-01-05 23:12:31 +00004192 // Determine whether we should expand the parameter packs.
4193 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004194 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004195 Optional<unsigned> OrigNumExpansions =
4196 ExpansionTL.getTypePtr()->getNumExpansions();
Douglas Gregor715e4612011-01-14 22:40:04 +00004197 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004198 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4199 Pattern.getSourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004200 Unexpanded,
4201 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004202 RetainExpansion,
4203 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004204 return true;
4205 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004206
Douglas Gregor5499af42011-01-05 23:12:31 +00004207 if (ShouldExpand) {
4208 // Expand the function parameter pack into multiple, separate
4209 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00004210 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004211 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004212 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier1dcde962012-08-08 18:46:20 +00004213 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004214 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004215 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004216 OrigNumExpansions,
4217 /*ExpectParameterPack=*/false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004218 if (!NewParm)
4219 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004220
Douglas Gregordd472162011-01-07 00:20:55 +00004221 OutParamTypes.push_back(NewParm->getType());
4222 if (PVars)
4223 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004224 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004225
4226 // If we're supposed to retain a pack expansion, do so by temporarily
4227 // forgetting the partially-substituted parameter pack.
4228 if (RetainExpansion) {
4229 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00004230 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004231 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004232 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004233 OrigNumExpansions,
4234 /*ExpectParameterPack=*/false);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004235 if (!NewParm)
4236 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004237
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004238 OutParamTypes.push_back(NewParm->getType());
4239 if (PVars)
4240 PVars->push_back(NewParm);
4241 }
4242
John McCall8fb0d9d2011-05-01 22:35:37 +00004243 // The next parameter should have the same adjustment as the
4244 // last thing we pushed, but we post-incremented indexAdjustment
4245 // on every push. Also, if we push nothing, the adjustment should
4246 // go down by one.
4247 indexAdjustment--;
4248
Douglas Gregor5499af42011-01-05 23:12:31 +00004249 // We're done with the pack expansion.
4250 continue;
4251 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004252
4253 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004254 // expansion.
Douglas Gregorc52264e2011-03-02 02:04:06 +00004255 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4256 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004257 indexAdjustment,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004258 NumExpansions,
4259 /*ExpectParameterPack=*/true);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004260 } else {
David Blaikie05785d12013-02-20 22:23:23 +00004261 NewParm = getDerived().TransformFunctionTypeParam(
David Blaikie7a30dc52013-02-21 01:47:18 +00004262 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004263 }
Douglas Gregorc52264e2011-03-02 02:04:06 +00004264
John McCall58f10c32010-03-11 09:03:00 +00004265 if (!NewParm)
4266 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004267
Douglas Gregordd472162011-01-07 00:20:55 +00004268 OutParamTypes.push_back(NewParm->getType());
4269 if (PVars)
4270 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004271 continue;
4272 }
John McCall58f10c32010-03-11 09:03:00 +00004273
4274 // Deal with the possibility that we don't have a parameter
4275 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00004276 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00004277 bool IsPackExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004278 Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004279 QualType NewType;
Chad Rosier1dcde962012-08-08 18:46:20 +00004280 if (const PackExpansionType *Expansion
Douglas Gregor5499af42011-01-05 23:12:31 +00004281 = dyn_cast<PackExpansionType>(OldType)) {
4282 // We have a function parameter pack that may need to be expanded.
4283 QualType Pattern = Expansion->getPattern();
Chris Lattner01cf8db2011-07-20 06:58:45 +00004284 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor5499af42011-01-05 23:12:31 +00004285 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00004286
Douglas Gregor5499af42011-01-05 23:12:31 +00004287 // Determine whether we should expand the parameter packs.
4288 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004289 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00004290 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004291 Unexpanded,
4292 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004293 RetainExpansion,
4294 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00004295 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00004296 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004297
Douglas Gregor5499af42011-01-05 23:12:31 +00004298 if (ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004299 // Expand the function parameter pack into multiple, separate
Douglas Gregor5499af42011-01-05 23:12:31 +00004300 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004301 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004302 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4303 QualType NewType = getDerived().TransformType(Pattern);
4304 if (NewType.isNull())
4305 return true;
John McCall58f10c32010-03-11 09:03:00 +00004306
Douglas Gregordd472162011-01-07 00:20:55 +00004307 OutParamTypes.push_back(NewType);
4308 if (PVars)
4309 PVars->push_back(0);
Douglas Gregor5499af42011-01-05 23:12:31 +00004310 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004311
Douglas Gregor5499af42011-01-05 23:12:31 +00004312 // We're done with the pack expansion.
4313 continue;
4314 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004315
Douglas Gregor48d24112011-01-10 20:53:55 +00004316 // If we're supposed to retain a pack expansion, do so by temporarily
4317 // forgetting the partially-substituted parameter pack.
4318 if (RetainExpansion) {
4319 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4320 QualType NewType = getDerived().TransformType(Pattern);
4321 if (NewType.isNull())
4322 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004323
Douglas Gregor48d24112011-01-10 20:53:55 +00004324 OutParamTypes.push_back(NewType);
4325 if (PVars)
4326 PVars->push_back(0);
4327 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004328
Chad Rosier1dcde962012-08-08 18:46:20 +00004329 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004330 // expansion.
4331 OldType = Expansion->getPattern();
4332 IsPackExpansion = true;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004333 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4334 NewType = getDerived().TransformType(OldType);
4335 } else {
4336 NewType = getDerived().TransformType(OldType);
Douglas Gregor5499af42011-01-05 23:12:31 +00004337 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004338
Douglas Gregor5499af42011-01-05 23:12:31 +00004339 if (NewType.isNull())
4340 return true;
4341
4342 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004343 NewType = getSema().Context.getPackExpansionType(NewType,
4344 NumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00004345
Douglas Gregordd472162011-01-07 00:20:55 +00004346 OutParamTypes.push_back(NewType);
4347 if (PVars)
4348 PVars->push_back(0);
John McCall58f10c32010-03-11 09:03:00 +00004349 }
4350
John McCall8fb0d9d2011-05-01 22:35:37 +00004351#ifndef NDEBUG
4352 if (PVars) {
4353 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4354 if (ParmVarDecl *parm = (*PVars)[i])
4355 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor5499af42011-01-05 23:12:31 +00004356 }
John McCall8fb0d9d2011-05-01 22:35:37 +00004357#endif
4358
4359 return false;
4360}
John McCall58f10c32010-03-11 09:03:00 +00004361
4362template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004363QualType
John McCall550e0c22009-10-21 00:40:46 +00004364TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004365 FunctionProtoTypeLoc TL) {
Douglas Gregor3024f072012-04-16 07:05:22 +00004366 return getDerived().TransformFunctionProtoType(TLB, TL, 0, 0);
4367}
4368
4369template<typename Derived>
4370QualType
4371TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
4372 FunctionProtoTypeLoc TL,
4373 CXXRecordDecl *ThisContext,
4374 unsigned ThisTypeQuals) {
Douglas Gregor4afc2362010-08-31 00:26:14 +00004375 // Transform the parameters and return type.
4376 //
Richard Smithf623c962012-04-17 00:58:00 +00004377 // We are required to instantiate the params and return type in source order.
Douglas Gregor7fb25412010-10-01 18:44:50 +00004378 // When the function has a trailing return type, we instantiate the
4379 // parameters before the return type, since the return type can then refer
4380 // to the parameters themselves (via decltype, sizeof, etc.).
4381 //
Chris Lattner01cf8db2011-07-20 06:58:45 +00004382 SmallVector<QualType, 4> ParamTypes;
4383 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall424cec92011-01-19 06:33:43 +00004384 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00004385
Douglas Gregor7fb25412010-10-01 18:44:50 +00004386 QualType ResultType;
4387
Richard Smith1226c602012-08-14 22:51:13 +00004388 if (T->hasTrailingReturn()) {
Alp Toker9cacbab2014-01-20 20:26:09 +00004389 if (getDerived().TransformFunctionTypeParams(
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004390 TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(),
Alp Toker9cacbab2014-01-20 20:26:09 +00004391 TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004392 return QualType();
4393
Douglas Gregor3024f072012-04-16 07:05:22 +00004394 {
4395 // C++11 [expr.prim.general]p3:
Chad Rosier1dcde962012-08-08 18:46:20 +00004396 // If a declaration declares a member function or member function
4397 // template of a class X, the expression this is a prvalue of type
Douglas Gregor3024f072012-04-16 07:05:22 +00004398 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier1dcde962012-08-08 18:46:20 +00004399 // and the end of the function-definition, member-declarator, or
Douglas Gregor3024f072012-04-16 07:05:22 +00004400 // declarator.
4401 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier1dcde962012-08-08 18:46:20 +00004402
Alp Toker42a16a62014-01-25 23:51:36 +00004403 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor3024f072012-04-16 07:05:22 +00004404 if (ResultType.isNull())
4405 return QualType();
4406 }
Douglas Gregor7fb25412010-10-01 18:44:50 +00004407 }
4408 else {
Alp Toker42a16a62014-01-25 23:51:36 +00004409 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00004410 if (ResultType.isNull())
4411 return QualType();
4412
Alp Toker9cacbab2014-01-20 20:26:09 +00004413 if (getDerived().TransformFunctionTypeParams(
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004414 TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(),
Alp Toker9cacbab2014-01-20 20:26:09 +00004415 TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004416 return QualType();
4417 }
4418
Richard Smithf623c962012-04-17 00:58:00 +00004419 // FIXME: Need to transform the exception-specification too.
4420
John McCall550e0c22009-10-21 00:40:46 +00004421 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00004422 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() ||
Alp Toker9cacbab2014-01-20 20:26:09 +00004423 T->getNumParams() != ParamTypes.size() ||
4424 !std::equal(T->param_type_begin(), T->param_type_end(),
4425 ParamTypes.begin())) {
Jordan Rose5c382722013-03-08 21:51:21 +00004426 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +00004427 T->getExtProtoInfo());
John McCall550e0c22009-10-21 00:40:46 +00004428 if (Result.isNull())
4429 return QualType();
4430 }
Mike Stump11289f42009-09-09 15:08:12 +00004431
John McCall550e0c22009-10-21 00:40:46 +00004432 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004433 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00004434 NewTL.setLParenLoc(TL.getLParenLoc());
4435 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004436 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004437 for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i)
4438 NewTL.setParam(i, ParamDecls[i]);
John McCall550e0c22009-10-21 00:40:46 +00004439
4440 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004441}
Mike Stump11289f42009-09-09 15:08:12 +00004442
Douglas Gregord6ff3322009-08-04 16:50:30 +00004443template<typename Derived>
4444QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00004445 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004446 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004447 const FunctionNoProtoType *T = TL.getTypePtr();
Alp Toker42a16a62014-01-25 23:51:36 +00004448 QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
John McCall550e0c22009-10-21 00:40:46 +00004449 if (ResultType.isNull())
4450 return QualType();
4451
4452 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00004453 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType())
John McCall550e0c22009-10-21 00:40:46 +00004454 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4455
4456 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004457 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00004458 NewTL.setLParenLoc(TL.getLParenLoc());
4459 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004460 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCall550e0c22009-10-21 00:40:46 +00004461
4462 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004463}
Mike Stump11289f42009-09-09 15:08:12 +00004464
John McCallb96ec562009-12-04 22:46:56 +00004465template<typename Derived> QualType
4466TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004467 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004468 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004469 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00004470 if (!D)
4471 return QualType();
4472
4473 QualType Result = TL.getType();
4474 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4475 Result = getDerived().RebuildUnresolvedUsingType(D);
4476 if (Result.isNull())
4477 return QualType();
4478 }
4479
4480 // We might get an arbitrary type spec type back. We should at
4481 // least always get a type spec type, though.
4482 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4483 NewTL.setNameLoc(TL.getNameLoc());
4484
4485 return Result;
4486}
4487
Douglas Gregord6ff3322009-08-04 16:50:30 +00004488template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004489QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004490 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004491 const TypedefType *T = TL.getTypePtr();
Richard Smithdda56e42011-04-15 14:24:37 +00004492 TypedefNameDecl *Typedef
4493 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4494 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004495 if (!Typedef)
4496 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004497
John McCall550e0c22009-10-21 00:40:46 +00004498 QualType Result = TL.getType();
4499 if (getDerived().AlwaysRebuild() ||
4500 Typedef != T->getDecl()) {
4501 Result = getDerived().RebuildTypedefType(Typedef);
4502 if (Result.isNull())
4503 return QualType();
4504 }
Mike Stump11289f42009-09-09 15:08:12 +00004505
John McCall550e0c22009-10-21 00:40:46 +00004506 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4507 NewTL.setNameLoc(TL.getNameLoc());
4508
4509 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004510}
Mike Stump11289f42009-09-09 15:08:12 +00004511
Douglas Gregord6ff3322009-08-04 16:50:30 +00004512template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004513QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004514 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00004515 // typeof expressions are not potentially evaluated contexts
Eli Friedman15681d62012-09-26 04:34:21 +00004516 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4517 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00004518
John McCalldadc5752010-08-24 06:29:42 +00004519 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004520 if (E.isInvalid())
4521 return QualType();
4522
Eli Friedmane4f22df2012-02-29 04:03:55 +00004523 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
4524 if (E.isInvalid())
4525 return QualType();
4526
John McCall550e0c22009-10-21 00:40:46 +00004527 QualType Result = TL.getType();
4528 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00004529 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004530 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00004531 if (Result.isNull())
4532 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004533 }
John McCall550e0c22009-10-21 00:40:46 +00004534 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00004535
John McCall550e0c22009-10-21 00:40:46 +00004536 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004537 NewTL.setTypeofLoc(TL.getTypeofLoc());
4538 NewTL.setLParenLoc(TL.getLParenLoc());
4539 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00004540
4541 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004542}
Mike Stump11289f42009-09-09 15:08:12 +00004543
4544template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004545QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004546 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00004547 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4548 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4549 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00004550 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004551
John McCall550e0c22009-10-21 00:40:46 +00004552 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00004553 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4554 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00004555 if (Result.isNull())
4556 return QualType();
4557 }
Mike Stump11289f42009-09-09 15:08:12 +00004558
John McCall550e0c22009-10-21 00:40:46 +00004559 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004560 NewTL.setTypeofLoc(TL.getTypeofLoc());
4561 NewTL.setLParenLoc(TL.getLParenLoc());
4562 NewTL.setRParenLoc(TL.getRParenLoc());
4563 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00004564
4565 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004566}
Mike Stump11289f42009-09-09 15:08:12 +00004567
4568template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004569QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004570 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004571 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004572
Douglas Gregore922c772009-08-04 22:27:00 +00004573 // decltype expressions are not potentially evaluated contexts
Richard Smithfd555f62012-02-22 02:04:18 +00004574 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, 0,
4575 /*IsDecltype=*/ true);
Mike Stump11289f42009-09-09 15:08:12 +00004576
John McCalldadc5752010-08-24 06:29:42 +00004577 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004578 if (E.isInvalid())
4579 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004580
Richard Smithfd555f62012-02-22 02:04:18 +00004581 E = getSema().ActOnDecltypeExpression(E.take());
4582 if (E.isInvalid())
4583 return QualType();
4584
John McCall550e0c22009-10-21 00:40:46 +00004585 QualType Result = TL.getType();
4586 if (getDerived().AlwaysRebuild() ||
4587 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004588 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004589 if (Result.isNull())
4590 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004591 }
John McCall550e0c22009-10-21 00:40:46 +00004592 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00004593
John McCall550e0c22009-10-21 00:40:46 +00004594 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4595 NewTL.setNameLoc(TL.getNameLoc());
4596
4597 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004598}
4599
4600template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00004601QualType TreeTransform<Derived>::TransformUnaryTransformType(
4602 TypeLocBuilder &TLB,
4603 UnaryTransformTypeLoc TL) {
4604 QualType Result = TL.getType();
4605 if (Result->isDependentType()) {
4606 const UnaryTransformType *T = TL.getTypePtr();
4607 QualType NewBase =
4608 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4609 Result = getDerived().RebuildUnaryTransformType(NewBase,
4610 T->getUTTKind(),
4611 TL.getKWLoc());
4612 if (Result.isNull())
4613 return QualType();
4614 }
4615
4616 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4617 NewTL.setKWLoc(TL.getKWLoc());
4618 NewTL.setParensRange(TL.getParensRange());
4619 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4620 return Result;
4621}
4622
4623template<typename Derived>
Richard Smith30482bc2011-02-20 03:19:35 +00004624QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4625 AutoTypeLoc TL) {
4626 const AutoType *T = TL.getTypePtr();
4627 QualType OldDeduced = T->getDeducedType();
4628 QualType NewDeduced;
4629 if (!OldDeduced.isNull()) {
4630 NewDeduced = getDerived().TransformType(OldDeduced);
4631 if (NewDeduced.isNull())
4632 return QualType();
4633 }
4634
4635 QualType Result = TL.getType();
Richard Smith27d807c2013-04-30 13:56:41 +00004636 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
4637 T->isDependentType()) {
Richard Smith74aeef52013-04-26 16:15:35 +00004638 Result = getDerived().RebuildAutoType(NewDeduced, T->isDecltypeAuto());
Richard Smith30482bc2011-02-20 03:19:35 +00004639 if (Result.isNull())
4640 return QualType();
4641 }
4642
4643 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4644 NewTL.setNameLoc(TL.getNameLoc());
4645
4646 return Result;
4647}
4648
4649template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004650QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004651 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004652 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004653 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004654 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4655 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004656 if (!Record)
4657 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004658
John McCall550e0c22009-10-21 00:40:46 +00004659 QualType Result = TL.getType();
4660 if (getDerived().AlwaysRebuild() ||
4661 Record != T->getDecl()) {
4662 Result = getDerived().RebuildRecordType(Record);
4663 if (Result.isNull())
4664 return QualType();
4665 }
Mike Stump11289f42009-09-09 15:08:12 +00004666
John McCall550e0c22009-10-21 00:40:46 +00004667 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4668 NewTL.setNameLoc(TL.getNameLoc());
4669
4670 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004671}
Mike Stump11289f42009-09-09 15:08:12 +00004672
4673template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004674QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004675 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004676 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004677 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004678 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4679 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004680 if (!Enum)
4681 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004682
John McCall550e0c22009-10-21 00:40:46 +00004683 QualType Result = TL.getType();
4684 if (getDerived().AlwaysRebuild() ||
4685 Enum != T->getDecl()) {
4686 Result = getDerived().RebuildEnumType(Enum);
4687 if (Result.isNull())
4688 return QualType();
4689 }
Mike Stump11289f42009-09-09 15:08:12 +00004690
John McCall550e0c22009-10-21 00:40:46 +00004691 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4692 NewTL.setNameLoc(TL.getNameLoc());
4693
4694 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004695}
John McCallfcc33b02009-09-05 00:15:47 +00004696
John McCalle78aac42010-03-10 03:28:59 +00004697template<typename Derived>
4698QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4699 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004700 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00004701 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4702 TL.getTypePtr()->getDecl());
4703 if (!D) return QualType();
4704
4705 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4706 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4707 return T;
4708}
4709
Douglas Gregord6ff3322009-08-04 16:50:30 +00004710template<typename Derived>
4711QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004712 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004713 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004714 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004715}
4716
Mike Stump11289f42009-09-09 15:08:12 +00004717template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00004718QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004719 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004720 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004721 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00004722
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004723 // Substitute into the replacement type, which itself might involve something
4724 // that needs to be transformed. This only tends to occur with default
4725 // template arguments of template template parameters.
4726 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4727 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4728 if (Replacement.isNull())
4729 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00004730
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004731 // Always canonicalize the replacement type.
4732 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4733 QualType Result
Chad Rosier1dcde962012-08-08 18:46:20 +00004734 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004735 Replacement);
Chad Rosier1dcde962012-08-08 18:46:20 +00004736
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004737 // Propagate type-source information.
4738 SubstTemplateTypeParmTypeLoc NewTL
4739 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4740 NewTL.setNameLoc(TL.getNameLoc());
4741 return Result;
4742
John McCallcebee162009-10-18 09:09:24 +00004743}
4744
4745template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00004746QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4747 TypeLocBuilder &TLB,
4748 SubstTemplateTypeParmPackTypeLoc TL) {
4749 return TransformTypeSpecType(TLB, TL);
4750}
4751
4752template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00004753QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00004754 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004755 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00004756 const TemplateSpecializationType *T = TL.getTypePtr();
4757
Douglas Gregordf846d12011-03-02 18:46:51 +00004758 // The nested-name-specifier never matters in a TemplateSpecializationType,
4759 // because we can't have a dependent nested-name-specifier anyway.
4760 CXXScopeSpec SS;
Mike Stump11289f42009-09-09 15:08:12 +00004761 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00004762 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4763 TL.getTemplateNameLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004764 if (Template.isNull())
4765 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004766
John McCall31f82722010-11-12 08:19:04 +00004767 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4768}
4769
Eli Friedman0dfb8892011-10-06 23:00:33 +00004770template<typename Derived>
4771QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
4772 AtomicTypeLoc TL) {
4773 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
4774 if (ValueType.isNull())
4775 return QualType();
4776
4777 QualType Result = TL.getType();
4778 if (getDerived().AlwaysRebuild() ||
4779 ValueType != TL.getValueLoc().getType()) {
4780 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
4781 if (Result.isNull())
4782 return QualType();
4783 }
4784
4785 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
4786 NewTL.setKWLoc(TL.getKWLoc());
4787 NewTL.setLParenLoc(TL.getLParenLoc());
4788 NewTL.setRParenLoc(TL.getRParenLoc());
4789
4790 return Result;
4791}
4792
Chad Rosier1dcde962012-08-08 18:46:20 +00004793 /// \brief Simple iterator that traverses the template arguments in a
Douglas Gregorfe921a72010-12-20 23:36:19 +00004794 /// container that provides a \c getArgLoc() member function.
4795 ///
4796 /// This iterator is intended to be used with the iterator form of
4797 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4798 template<typename ArgLocContainer>
4799 class TemplateArgumentLocContainerIterator {
4800 ArgLocContainer *Container;
4801 unsigned Index;
Chad Rosier1dcde962012-08-08 18:46:20 +00004802
Douglas Gregorfe921a72010-12-20 23:36:19 +00004803 public:
4804 typedef TemplateArgumentLoc value_type;
4805 typedef TemplateArgumentLoc reference;
4806 typedef int difference_type;
4807 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00004808
Douglas Gregorfe921a72010-12-20 23:36:19 +00004809 class pointer {
4810 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00004811
Douglas Gregorfe921a72010-12-20 23:36:19 +00004812 public:
4813 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00004814
Douglas Gregorfe921a72010-12-20 23:36:19 +00004815 const TemplateArgumentLoc *operator->() const {
4816 return &Arg;
4817 }
4818 };
Chad Rosier1dcde962012-08-08 18:46:20 +00004819
4820
Douglas Gregorfe921a72010-12-20 23:36:19 +00004821 TemplateArgumentLocContainerIterator() {}
Chad Rosier1dcde962012-08-08 18:46:20 +00004822
Douglas Gregorfe921a72010-12-20 23:36:19 +00004823 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4824 unsigned Index)
4825 : Container(&Container), Index(Index) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00004826
Douglas Gregorfe921a72010-12-20 23:36:19 +00004827 TemplateArgumentLocContainerIterator &operator++() {
4828 ++Index;
4829 return *this;
4830 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004831
Douglas Gregorfe921a72010-12-20 23:36:19 +00004832 TemplateArgumentLocContainerIterator operator++(int) {
4833 TemplateArgumentLocContainerIterator Old(*this);
4834 ++(*this);
4835 return Old;
4836 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004837
Douglas Gregorfe921a72010-12-20 23:36:19 +00004838 TemplateArgumentLoc operator*() const {
4839 return Container->getArgLoc(Index);
4840 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004841
Douglas Gregorfe921a72010-12-20 23:36:19 +00004842 pointer operator->() const {
4843 return pointer(Container->getArgLoc(Index));
4844 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004845
Douglas Gregorfe921a72010-12-20 23:36:19 +00004846 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004847 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004848 return X.Container == Y.Container && X.Index == Y.Index;
4849 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004850
Douglas Gregorfe921a72010-12-20 23:36:19 +00004851 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004852 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004853 return !(X == Y);
4854 }
4855 };
Chad Rosier1dcde962012-08-08 18:46:20 +00004856
4857
John McCall31f82722010-11-12 08:19:04 +00004858template <typename Derived>
4859QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4860 TypeLocBuilder &TLB,
4861 TemplateSpecializationTypeLoc TL,
4862 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00004863 TemplateArgumentListInfo NewTemplateArgs;
4864 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4865 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00004866 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4867 ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00004868 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregorfe921a72010-12-20 23:36:19 +00004869 ArgIterator(TL, TL.getNumArgs()),
4870 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00004871 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004872
John McCall0ad16662009-10-29 08:12:44 +00004873 // FIXME: maybe don't rebuild if all the template arguments are the same.
4874
4875 QualType Result =
4876 getDerived().RebuildTemplateSpecializationType(Template,
4877 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00004878 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00004879
4880 if (!Result.isNull()) {
Richard Smith3f1b5d02011-05-05 21:57:07 +00004881 // Specializations of template template parameters are represented as
4882 // TemplateSpecializationTypes, and substitution of type alias templates
4883 // within a dependent context can transform them into
4884 // DependentTemplateSpecializationTypes.
4885 if (isa<DependentTemplateSpecializationType>(Result)) {
4886 DependentTemplateSpecializationTypeLoc NewTL
4887 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004888 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3f1b5d02011-05-05 21:57:07 +00004889 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00004890 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004891 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3f1b5d02011-05-05 21:57:07 +00004892 NewTL.setLAngleLoc(TL.getLAngleLoc());
4893 NewTL.setRAngleLoc(TL.getRAngleLoc());
4894 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4895 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4896 return Result;
4897 }
4898
John McCall0ad16662009-10-29 08:12:44 +00004899 TemplateSpecializationTypeLoc NewTL
4900 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004901 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall0ad16662009-10-29 08:12:44 +00004902 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4903 NewTL.setLAngleLoc(TL.getLAngleLoc());
4904 NewTL.setRAngleLoc(TL.getRAngleLoc());
4905 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4906 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004907 }
Mike Stump11289f42009-09-09 15:08:12 +00004908
John McCall0ad16662009-10-29 08:12:44 +00004909 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004910}
Mike Stump11289f42009-09-09 15:08:12 +00004911
Douglas Gregor5a064722011-02-28 17:23:35 +00004912template <typename Derived>
4913QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4914 TypeLocBuilder &TLB,
4915 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +00004916 TemplateName Template,
4917 CXXScopeSpec &SS) {
Douglas Gregor5a064722011-02-28 17:23:35 +00004918 TemplateArgumentListInfo NewTemplateArgs;
4919 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4920 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4921 typedef TemplateArgumentLocContainerIterator<
4922 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00004923 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor5a064722011-02-28 17:23:35 +00004924 ArgIterator(TL, TL.getNumArgs()),
4925 NewTemplateArgs))
4926 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00004927
Douglas Gregor5a064722011-02-28 17:23:35 +00004928 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier1dcde962012-08-08 18:46:20 +00004929
Douglas Gregor5a064722011-02-28 17:23:35 +00004930 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4931 QualType Result
4932 = getSema().Context.getDependentTemplateSpecializationType(
4933 TL.getTypePtr()->getKeyword(),
4934 DTN->getQualifier(),
4935 DTN->getIdentifier(),
4936 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00004937
Douglas Gregor5a064722011-02-28 17:23:35 +00004938 DependentTemplateSpecializationTypeLoc NewTL
4939 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004940 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004941 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00004942 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004943 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00004944 NewTL.setLAngleLoc(TL.getLAngleLoc());
4945 NewTL.setRAngleLoc(TL.getRAngleLoc());
4946 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4947 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4948 return Result;
4949 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004950
4951 QualType Result
Douglas Gregor5a064722011-02-28 17:23:35 +00004952 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004953 TL.getTemplateNameLoc(),
Douglas Gregor5a064722011-02-28 17:23:35 +00004954 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00004955
Douglas Gregor5a064722011-02-28 17:23:35 +00004956 if (!Result.isNull()) {
4957 /// FIXME: Wrap this in an elaborated-type-specifier?
4958 TemplateSpecializationTypeLoc NewTL
4959 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00004960 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004961 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00004962 NewTL.setLAngleLoc(TL.getLAngleLoc());
4963 NewTL.setRAngleLoc(TL.getRAngleLoc());
4964 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4965 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4966 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004967
Douglas Gregor5a064722011-02-28 17:23:35 +00004968 return Result;
4969}
4970
Mike Stump11289f42009-09-09 15:08:12 +00004971template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004972QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00004973TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004974 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004975 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00004976
Douglas Gregor844cb502011-03-01 18:12:44 +00004977 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara6150c882010-05-11 21:36:43 +00004978 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor844cb502011-03-01 18:12:44 +00004979 if (TL.getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004980 QualifierLoc
Douglas Gregor844cb502011-03-01 18:12:44 +00004981 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4982 if (!QualifierLoc)
Abramo Bagnara6150c882010-05-11 21:36:43 +00004983 return QualType();
4984 }
Mike Stump11289f42009-09-09 15:08:12 +00004985
John McCall31f82722010-11-12 08:19:04 +00004986 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4987 if (NamedT.isNull())
4988 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00004989
Richard Smith3f1b5d02011-05-05 21:57:07 +00004990 // C++0x [dcl.type.elab]p2:
4991 // If the identifier resolves to a typedef-name or the simple-template-id
4992 // resolves to an alias template specialization, the
4993 // elaborated-type-specifier is ill-formed.
Richard Smith0c4a34b2011-05-14 15:04:18 +00004994 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
4995 if (const TemplateSpecializationType *TST =
4996 NamedT->getAs<TemplateSpecializationType>()) {
4997 TemplateName Template = TST->getTemplateName();
4998 if (TypeAliasTemplateDecl *TAT =
4999 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
5000 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
5001 diag::err_tag_reference_non_tag) << 4;
5002 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
5003 }
Richard Smith3f1b5d02011-05-05 21:57:07 +00005004 }
5005 }
5006
John McCall550e0c22009-10-21 00:40:46 +00005007 QualType Result = TL.getType();
5008 if (getDerived().AlwaysRebuild() ||
Douglas Gregor844cb502011-03-01 18:12:44 +00005009 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00005010 NamedT != T->getNamedType()) {
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005011 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00005012 T->getKeyword(),
Douglas Gregor844cb502011-03-01 18:12:44 +00005013 QualifierLoc, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00005014 if (Result.isNull())
5015 return QualType();
5016 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00005017
Abramo Bagnara6150c882010-05-11 21:36:43 +00005018 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005019 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005020 NewTL.setQualifierLoc(QualifierLoc);
John McCall550e0c22009-10-21 00:40:46 +00005021 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005022}
Mike Stump11289f42009-09-09 15:08:12 +00005023
5024template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00005025QualType TreeTransform<Derived>::TransformAttributedType(
5026 TypeLocBuilder &TLB,
5027 AttributedTypeLoc TL) {
5028 const AttributedType *oldType = TL.getTypePtr();
5029 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
5030 if (modifiedType.isNull())
5031 return QualType();
5032
5033 QualType result = TL.getType();
5034
5035 // FIXME: dependent operand expressions?
5036 if (getDerived().AlwaysRebuild() ||
5037 modifiedType != oldType->getModifiedType()) {
5038 // TODO: this is really lame; we should really be rebuilding the
5039 // equivalent type from first principles.
5040 QualType equivalentType
5041 = getDerived().TransformType(oldType->getEquivalentType());
5042 if (equivalentType.isNull())
5043 return QualType();
5044 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
5045 modifiedType,
5046 equivalentType);
5047 }
5048
5049 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
5050 newTL.setAttrNameLoc(TL.getAttrNameLoc());
5051 if (TL.hasAttrOperand())
5052 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5053 if (TL.hasAttrExprOperand())
5054 newTL.setAttrExprOperand(TL.getAttrExprOperand());
5055 else if (TL.hasAttrEnumOperand())
5056 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
5057
5058 return result;
5059}
5060
5061template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00005062QualType
5063TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
5064 ParenTypeLoc TL) {
5065 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
5066 if (Inner.isNull())
5067 return QualType();
5068
5069 QualType Result = TL.getType();
5070 if (getDerived().AlwaysRebuild() ||
5071 Inner != TL.getInnerLoc().getType()) {
5072 Result = getDerived().RebuildParenType(Inner);
5073 if (Result.isNull())
5074 return QualType();
5075 }
5076
5077 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
5078 NewTL.setLParenLoc(TL.getLParenLoc());
5079 NewTL.setRParenLoc(TL.getRParenLoc());
5080 return Result;
5081}
5082
5083template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00005084QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005085 DependentNameTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005086 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00005087
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005088 NestedNameSpecifierLoc QualifierLoc
5089 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5090 if (!QualifierLoc)
Douglas Gregord6ff3322009-08-04 16:50:30 +00005091 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005092
John McCallc392f372010-06-11 00:33:02 +00005093 QualType Result
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005094 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005095 TL.getElaboratedKeywordLoc(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005096 QualifierLoc,
5097 T->getIdentifier(),
John McCallc392f372010-06-11 00:33:02 +00005098 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00005099 if (Result.isNull())
5100 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005101
Abramo Bagnarad7548482010-05-19 21:37:53 +00005102 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
5103 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00005104 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
5105
Abramo Bagnarad7548482010-05-19 21:37:53 +00005106 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005107 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005108 NewTL.setQualifierLoc(QualifierLoc);
John McCallc392f372010-06-11 00:33:02 +00005109 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00005110 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005111 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005112 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00005113 NewTL.setNameLoc(TL.getNameLoc());
5114 }
John McCall550e0c22009-10-21 00:40:46 +00005115 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005116}
Mike Stump11289f42009-09-09 15:08:12 +00005117
Douglas Gregord6ff3322009-08-04 16:50:30 +00005118template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00005119QualType TreeTransform<Derived>::
5120 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005121 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregora7a795b2011-03-01 20:11:18 +00005122 NestedNameSpecifierLoc QualifierLoc;
5123 if (TL.getQualifierLoc()) {
5124 QualifierLoc
5125 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5126 if (!QualifierLoc)
Douglas Gregor5a064722011-02-28 17:23:35 +00005127 return QualType();
5128 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005129
John McCall31f82722010-11-12 08:19:04 +00005130 return getDerived()
Douglas Gregora7a795b2011-03-01 20:11:18 +00005131 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall31f82722010-11-12 08:19:04 +00005132}
5133
5134template<typename Derived>
5135QualType TreeTransform<Derived>::
Douglas Gregora7a795b2011-03-01 20:11:18 +00005136TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
5137 DependentTemplateSpecializationTypeLoc TL,
5138 NestedNameSpecifierLoc QualifierLoc) {
5139 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00005140
Douglas Gregora7a795b2011-03-01 20:11:18 +00005141 TemplateArgumentListInfo NewTemplateArgs;
5142 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5143 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00005144
Douglas Gregora7a795b2011-03-01 20:11:18 +00005145 typedef TemplateArgumentLocContainerIterator<
5146 DependentTemplateSpecializationTypeLoc> ArgIterator;
5147 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5148 ArgIterator(TL, TL.getNumArgs()),
5149 NewTemplateArgs))
5150 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005151
Douglas Gregora7a795b2011-03-01 20:11:18 +00005152 QualType Result
5153 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
5154 QualifierLoc,
5155 T->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005156 TL.getTemplateNameLoc(),
Douglas Gregora7a795b2011-03-01 20:11:18 +00005157 NewTemplateArgs);
5158 if (Result.isNull())
5159 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005160
Douglas Gregora7a795b2011-03-01 20:11:18 +00005161 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
5162 QualType NamedT = ElabT->getNamedType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005163
Douglas Gregora7a795b2011-03-01 20:11:18 +00005164 // Copy information relevant to the template specialization.
5165 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor43f788f2011-03-07 02:33:33 +00005166 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005167 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005168 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005169 NamedTL.setLAngleLoc(TL.getLAngleLoc());
5170 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005171 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005172 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier1dcde962012-08-08 18:46:20 +00005173
Douglas Gregora7a795b2011-03-01 20:11:18 +00005174 // Copy information relevant to the elaborated type.
5175 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005176 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005177 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor43f788f2011-03-07 02:33:33 +00005178 } else if (isa<DependentTemplateSpecializationType>(Result)) {
5179 DependentTemplateSpecializationTypeLoc SpecTL
5180 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005181 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005182 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005183 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005184 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005185 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5186 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005187 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005188 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005189 } else {
Douglas Gregor43f788f2011-03-07 02:33:33 +00005190 TemplateSpecializationTypeLoc SpecTL
5191 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005192 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005193 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005194 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5195 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005196 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005197 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005198 }
5199 return Result;
5200}
5201
5202template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00005203QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5204 PackExpansionTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005205 QualType Pattern
5206 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor822d0302011-01-12 17:07:58 +00005207 if (Pattern.isNull())
5208 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005209
5210 QualType Result = TL.getType();
Douglas Gregor822d0302011-01-12 17:07:58 +00005211 if (getDerived().AlwaysRebuild() ||
5212 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005213 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00005214 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00005215 TL.getEllipsisLoc(),
5216 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00005217 if (Result.isNull())
5218 return QualType();
5219 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005220
Douglas Gregor822d0302011-01-12 17:07:58 +00005221 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5222 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5223 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00005224}
5225
5226template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005227QualType
5228TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005229 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005230 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00005231 TLB.pushFullCopy(TL);
5232 return TL.getType();
5233}
5234
5235template<typename Derived>
5236QualType
5237TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005238 ObjCObjectTypeLoc TL) {
John McCall8b07ec22010-05-15 11:32:37 +00005239 // ObjCObjectType is never dependent.
5240 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00005241 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005242}
Mike Stump11289f42009-09-09 15:08:12 +00005243
5244template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005245QualType
5246TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005247 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005248 // ObjCObjectPointerType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00005249 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00005250 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00005251}
5252
Douglas Gregord6ff3322009-08-04 16:50:30 +00005253//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00005254// Statement transformation
5255//===----------------------------------------------------------------------===//
5256template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005257StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005258TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00005259 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005260}
5261
5262template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005263StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005264TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
5265 return getDerived().TransformCompoundStmt(S, false);
5266}
5267
5268template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005269StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005270TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00005271 bool IsStmtExpr) {
Dmitri Gribenko800ddf32012-02-14 22:14:32 +00005272 Sema::CompoundScopeRAII CompoundScope(getSema());
5273
John McCall1ababa62010-08-27 19:56:05 +00005274 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00005275 bool SubStmtChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005276 SmallVector<Stmt*, 8> Statements;
Douglas Gregorebe10102009-08-20 07:17:43 +00005277 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
5278 B != BEnd; ++B) {
John McCalldadc5752010-08-24 06:29:42 +00005279 StmtResult Result = getDerived().TransformStmt(*B);
John McCall1ababa62010-08-27 19:56:05 +00005280 if (Result.isInvalid()) {
5281 // Immediately fail if this was a DeclStmt, since it's very
5282 // likely that this will cause problems for future statements.
5283 if (isa<DeclStmt>(*B))
5284 return StmtError();
5285
5286 // Otherwise, just keep processing substatements and fail later.
5287 SubStmtInvalid = true;
5288 continue;
5289 }
Mike Stump11289f42009-09-09 15:08:12 +00005290
Douglas Gregorebe10102009-08-20 07:17:43 +00005291 SubStmtChanged = SubStmtChanged || Result.get() != *B;
5292 Statements.push_back(Result.takeAs<Stmt>());
5293 }
Mike Stump11289f42009-09-09 15:08:12 +00005294
John McCall1ababa62010-08-27 19:56:05 +00005295 if (SubStmtInvalid)
5296 return StmtError();
5297
Douglas Gregorebe10102009-08-20 07:17:43 +00005298 if (!getDerived().AlwaysRebuild() &&
5299 !SubStmtChanged)
John McCallc3007a22010-10-26 07:05:15 +00005300 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005301
5302 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00005303 Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00005304 S->getRBracLoc(),
5305 IsStmtExpr);
5306}
Mike Stump11289f42009-09-09 15:08:12 +00005307
Douglas Gregorebe10102009-08-20 07:17:43 +00005308template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005309StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005310TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005311 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00005312 {
Eli Friedman1f4f9dd2012-01-18 02:54:10 +00005313 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5314 Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005315
Eli Friedman06577382009-11-19 03:14:00 +00005316 // Transform the left-hand case value.
5317 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00005318 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman06577382009-11-19 03:14:00 +00005319 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005320 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005321
Eli Friedman06577382009-11-19 03:14:00 +00005322 // Transform the right-hand case value (for the GNU case-range extension).
5323 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00005324 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman06577382009-11-19 03:14:00 +00005325 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005326 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00005327 }
Mike Stump11289f42009-09-09 15:08:12 +00005328
Douglas Gregorebe10102009-08-20 07:17:43 +00005329 // Build the case statement.
5330 // Case statements are always rebuilt so that they will attached to their
5331 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005332 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00005333 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005334 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00005335 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005336 S->getColonLoc());
5337 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005338 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005339
Douglas Gregorebe10102009-08-20 07:17:43 +00005340 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00005341 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005342 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005343 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005344
Douglas Gregorebe10102009-08-20 07:17:43 +00005345 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00005346 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005347}
5348
5349template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005350StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005351TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005352 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00005353 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005354 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005355 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005356
Douglas Gregorebe10102009-08-20 07:17:43 +00005357 // Default statements are always rebuilt
5358 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00005359 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005360}
Mike Stump11289f42009-09-09 15:08:12 +00005361
Douglas Gregorebe10102009-08-20 07:17:43 +00005362template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005363StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005364TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005365 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005366 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005367 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005368
Chris Lattnercab02a62011-02-17 20:34:02 +00005369 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5370 S->getDecl());
5371 if (!LD)
5372 return StmtError();
Richard Smithc202b282012-04-14 00:33:13 +00005373
5374
Douglas Gregorebe10102009-08-20 07:17:43 +00005375 // FIXME: Pass the real colon location in.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00005376 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005377 cast<LabelDecl>(LD), SourceLocation(),
5378 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005379}
Mike Stump11289f42009-09-09 15:08:12 +00005380
Douglas Gregorebe10102009-08-20 07:17:43 +00005381template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005382StmtResult
Richard Smithc202b282012-04-14 00:33:13 +00005383TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
5384 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5385 if (SubStmt.isInvalid())
5386 return StmtError();
5387
5388 // TODO: transform attributes
5389 if (SubStmt.get() == S->getSubStmt() /* && attrs are the same */)
5390 return S;
5391
5392 return getDerived().RebuildAttributedStmt(S->getAttrLoc(),
5393 S->getAttrs(),
5394 SubStmt.get());
5395}
5396
5397template<typename Derived>
5398StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005399TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005400 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005401 ExprResult Cond;
Douglas Gregor633caca2009-11-23 23:44:04 +00005402 VarDecl *ConditionVar = 0;
5403 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005404 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00005405 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005406 getDerived().TransformDefinition(
5407 S->getConditionVariable()->getLocation(),
5408 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00005409 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005410 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005411 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00005412 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005413
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005414 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005415 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005416
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005417 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00005418 if (S->getCond()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005419 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005420 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005421 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005422 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005423
John McCallb268a282010-08-23 23:25:46 +00005424 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005425 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005426 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005427
John McCallb268a282010-08-23 23:25:46 +00005428 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5429 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005430 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005431
Douglas Gregorebe10102009-08-20 07:17:43 +00005432 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00005433 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00005434 if (Then.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005435 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005436
Douglas Gregorebe10102009-08-20 07:17:43 +00005437 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00005438 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00005439 if (Else.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005440 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005441
Douglas Gregorebe10102009-08-20 07:17:43 +00005442 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00005443 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005444 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005445 Then.get() == S->getThen() &&
5446 Else.get() == S->getElse())
John McCallc3007a22010-10-26 07:05:15 +00005447 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005448
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005449 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00005450 Then.get(),
John McCallb268a282010-08-23 23:25:46 +00005451 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005452}
5453
5454template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005455StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005456TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005457 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00005458 ExprResult Cond;
Douglas Gregordcf19622009-11-24 17:07:59 +00005459 VarDecl *ConditionVar = 0;
5460 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005461 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00005462 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005463 getDerived().TransformDefinition(
5464 S->getConditionVariable()->getLocation(),
5465 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00005466 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005467 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005468 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00005469 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005470
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005471 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005472 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005473 }
Mike Stump11289f42009-09-09 15:08:12 +00005474
Douglas Gregorebe10102009-08-20 07:17:43 +00005475 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005476 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00005477 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00005478 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00005479 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005480 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005481
Douglas Gregorebe10102009-08-20 07:17:43 +00005482 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005483 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005484 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005485 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005486
Douglas Gregorebe10102009-08-20 07:17:43 +00005487 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00005488 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5489 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005490}
Mike Stump11289f42009-09-09 15:08:12 +00005491
Douglas Gregorebe10102009-08-20 07:17:43 +00005492template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005493StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005494TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005495 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005496 ExprResult Cond;
Douglas Gregor680f8612009-11-24 21:15:44 +00005497 VarDecl *ConditionVar = 0;
5498 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005499 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00005500 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005501 getDerived().TransformDefinition(
5502 S->getConditionVariable()->getLocation(),
5503 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00005504 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005505 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005506 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00005507 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005508
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005509 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005510 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005511
5512 if (S->getCond()) {
5513 // Convert the condition to a boolean value.
Chad Rosier1dcde962012-08-08 18:46:20 +00005514 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005515 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005516 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005517 return StmtError();
John McCallb268a282010-08-23 23:25:46 +00005518 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00005519 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005520 }
Mike Stump11289f42009-09-09 15:08:12 +00005521
John McCallb268a282010-08-23 23:25:46 +00005522 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5523 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005524 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005525
Douglas Gregorebe10102009-08-20 07:17:43 +00005526 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005527 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005528 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005529 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005530
Douglas Gregorebe10102009-08-20 07:17:43 +00005531 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00005532 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005533 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005534 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00005535 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005536
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005537 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00005538 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005539}
Mike Stump11289f42009-09-09 15:08:12 +00005540
Douglas Gregorebe10102009-08-20 07:17:43 +00005541template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005542StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005543TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005544 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005545 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005546 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005547 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005548
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005549 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005550 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005551 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005552 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005553
Douglas Gregorebe10102009-08-20 07:17:43 +00005554 if (!getDerived().AlwaysRebuild() &&
5555 Cond.get() == S->getCond() &&
5556 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005557 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005558
John McCallb268a282010-08-23 23:25:46 +00005559 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5560 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005561 S->getRParenLoc());
5562}
Mike Stump11289f42009-09-09 15:08:12 +00005563
Douglas Gregorebe10102009-08-20 07:17:43 +00005564template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005565StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005566TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005567 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00005568 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00005569 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005570 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005571
Douglas Gregorebe10102009-08-20 07:17:43 +00005572 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005573 ExprResult Cond;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005574 VarDecl *ConditionVar = 0;
5575 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005576 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005577 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005578 getDerived().TransformDefinition(
5579 S->getConditionVariable()->getLocation(),
5580 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005581 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005582 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005583 } else {
5584 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005585
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005586 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005587 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005588
5589 if (S->getCond()) {
5590 // Convert the condition to a boolean value.
Chad Rosier1dcde962012-08-08 18:46:20 +00005591 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005592 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005593 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005594 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005595
John McCallb268a282010-08-23 23:25:46 +00005596 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005597 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005598 }
Mike Stump11289f42009-09-09 15:08:12 +00005599
Chad Rosier1dcde962012-08-08 18:46:20 +00005600 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
John McCallb268a282010-08-23 23:25:46 +00005601 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005602 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005603
Douglas Gregorebe10102009-08-20 07:17:43 +00005604 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00005605 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005606 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005607 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005608
Richard Smith945f8d32013-01-14 22:39:08 +00005609 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
John McCallb268a282010-08-23 23:25:46 +00005610 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005611 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005612
Douglas Gregorebe10102009-08-20 07:17:43 +00005613 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005614 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005615 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005616 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005617
Douglas Gregorebe10102009-08-20 07:17:43 +00005618 if (!getDerived().AlwaysRebuild() &&
5619 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00005620 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005621 Inc.get() == S->getInc() &&
5622 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005623 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005624
Douglas Gregorebe10102009-08-20 07:17:43 +00005625 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005626 Init.get(), FullCond, ConditionVar,
5627 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005628}
5629
5630template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005631StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005632TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattnercab02a62011-02-17 20:34:02 +00005633 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5634 S->getLabel());
5635 if (!LD)
5636 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005637
Douglas Gregorebe10102009-08-20 07:17:43 +00005638 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00005639 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005640 cast<LabelDecl>(LD));
Douglas Gregorebe10102009-08-20 07:17:43 +00005641}
5642
5643template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005644StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005645TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005646 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00005647 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005648 return StmtError();
Eli Friedman9ccdb1d2012-01-31 22:47:07 +00005649 Target = SemaRef.MaybeCreateExprWithCleanups(Target.take());
Mike Stump11289f42009-09-09 15:08:12 +00005650
Douglas Gregorebe10102009-08-20 07:17:43 +00005651 if (!getDerived().AlwaysRebuild() &&
5652 Target.get() == S->getTarget())
John McCallc3007a22010-10-26 07:05:15 +00005653 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005654
5655 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00005656 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005657}
5658
5659template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005660StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005661TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00005662 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005663}
Mike Stump11289f42009-09-09 15:08:12 +00005664
Douglas Gregorebe10102009-08-20 07:17:43 +00005665template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005666StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005667TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00005668 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005669}
Mike Stump11289f42009-09-09 15:08:12 +00005670
Douglas Gregorebe10102009-08-20 07:17:43 +00005671template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005672StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005673TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005674 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregorebe10102009-08-20 07:17:43 +00005675 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005676 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00005677
Mike Stump11289f42009-09-09 15:08:12 +00005678 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00005679 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00005680 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005681}
Mike Stump11289f42009-09-09 15:08:12 +00005682
Douglas Gregorebe10102009-08-20 07:17:43 +00005683template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005684StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005685TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005686 bool DeclChanged = false;
Chris Lattner01cf8db2011-07-20 06:58:45 +00005687 SmallVector<Decl *, 4> Decls;
Douglas Gregorebe10102009-08-20 07:17:43 +00005688 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5689 D != DEnd; ++D) {
Douglas Gregor25289362010-03-01 17:25:41 +00005690 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5691 *D);
Douglas Gregorebe10102009-08-20 07:17:43 +00005692 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00005693 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005694
Douglas Gregorebe10102009-08-20 07:17:43 +00005695 if (Transformed != *D)
5696 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00005697
Douglas Gregorebe10102009-08-20 07:17:43 +00005698 Decls.push_back(Transformed);
5699 }
Mike Stump11289f42009-09-09 15:08:12 +00005700
Douglas Gregorebe10102009-08-20 07:17:43 +00005701 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCallc3007a22010-10-26 07:05:15 +00005702 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005703
Rafael Espindolaab417692013-07-09 12:05:01 +00005704 return getDerived().RebuildDeclStmt(Decls, S->getStartLoc(), S->getEndLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005705}
Mike Stump11289f42009-09-09 15:08:12 +00005706
Douglas Gregorebe10102009-08-20 07:17:43 +00005707template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005708StmtResult
Chad Rosierde70e0e2012-08-25 00:11:56 +00005709TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005710
Benjamin Kramerf0623432012-08-23 22:51:59 +00005711 SmallVector<Expr*, 8> Constraints;
5712 SmallVector<Expr*, 8> Exprs;
Chris Lattner01cf8db2011-07-20 06:58:45 +00005713 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00005714
John McCalldadc5752010-08-24 06:29:42 +00005715 ExprResult AsmString;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005716 SmallVector<Expr*, 8> Clobbers;
Anders Carlssonaaeef072010-01-24 05:50:09 +00005717
5718 bool ExprsChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00005719
Anders Carlssonaaeef072010-01-24 05:50:09 +00005720 // Go through the outputs.
5721 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005722 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005723
Anders Carlssonaaeef072010-01-24 05:50:09 +00005724 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005725 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005726
Anders Carlssonaaeef072010-01-24 05:50:09 +00005727 // Transform the output expr.
5728 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005729 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005730 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005731 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005732
Anders Carlssonaaeef072010-01-24 05:50:09 +00005733 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00005734
John McCallb268a282010-08-23 23:25:46 +00005735 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005736 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005737
Anders Carlssonaaeef072010-01-24 05:50:09 +00005738 // Go through the inputs.
5739 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005740 Names.push_back(S->getInputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005741
Anders Carlssonaaeef072010-01-24 05:50:09 +00005742 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005743 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005744
Anders Carlssonaaeef072010-01-24 05:50:09 +00005745 // Transform the input expr.
5746 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005747 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005748 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005749 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005750
Anders Carlssonaaeef072010-01-24 05:50:09 +00005751 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00005752
John McCallb268a282010-08-23 23:25:46 +00005753 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005754 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005755
Anders Carlssonaaeef072010-01-24 05:50:09 +00005756 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCallc3007a22010-10-26 07:05:15 +00005757 return SemaRef.Owned(S);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005758
5759 // Go through the clobbers.
5760 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosierd9fb09a2012-08-27 23:28:41 +00005761 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00005762
5763 // No need to transform the asm string literal.
5764 AsmString = SemaRef.Owned(S->getAsmString());
Chad Rosierde70e0e2012-08-25 00:11:56 +00005765 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
5766 S->isVolatile(), S->getNumOutputs(),
5767 S->getNumInputs(), Names.data(),
5768 Constraints, Exprs, AsmString.get(),
5769 Clobbers, S->getRParenLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005770}
5771
Chad Rosier32503022012-06-11 20:47:18 +00005772template<typename Derived>
5773StmtResult
5774TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier99fc3812012-08-07 00:29:06 +00005775 ArrayRef<Token> AsmToks =
5776 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier3ed0bd92012-08-08 19:48:07 +00005777
John McCallf413f5e2013-05-03 00:10:13 +00005778 bool HadError = false, HadChange = false;
5779
5780 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
5781 SmallVector<Expr*, 8> TransformedExprs;
5782 TransformedExprs.reserve(SrcExprs.size());
5783 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
5784 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
5785 if (!Result.isUsable()) {
5786 HadError = true;
5787 } else {
5788 HadChange |= (Result.get() != SrcExprs[i]);
5789 TransformedExprs.push_back(Result.take());
5790 }
5791 }
5792
5793 if (HadError) return StmtError();
5794 if (!HadChange && !getDerived().AlwaysRebuild())
5795 return Owned(S);
5796
Chad Rosierb6f46c12012-08-15 16:53:30 +00005797 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
John McCallf413f5e2013-05-03 00:10:13 +00005798 AsmToks, S->getAsmString(),
5799 S->getNumOutputs(), S->getNumInputs(),
5800 S->getAllConstraints(), S->getClobbers(),
5801 TransformedExprs, S->getEndLoc());
Chad Rosier32503022012-06-11 20:47:18 +00005802}
Douglas Gregorebe10102009-08-20 07:17:43 +00005803
5804template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005805StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005806TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005807 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00005808 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005809 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005810 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005811
Douglas Gregor96c79492010-04-23 22:50:49 +00005812 // Transform the @catch statements (if present).
5813 bool AnyCatchChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005814 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor96c79492010-04-23 22:50:49 +00005815 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00005816 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00005817 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005818 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00005819 if (Catch.get() != S->getCatchStmt(I))
5820 AnyCatchChanged = true;
5821 CatchStmts.push_back(Catch.release());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005822 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005823
Douglas Gregor306de2f2010-04-22 23:59:56 +00005824 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00005825 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00005826 if (S->getFinallyStmt()) {
5827 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5828 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005829 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00005830 }
5831
5832 // If nothing changed, just retain this statement.
5833 if (!getDerived().AlwaysRebuild() &&
5834 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00005835 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00005836 Finally.get() == S->getFinallyStmt())
John McCallc3007a22010-10-26 07:05:15 +00005837 return SemaRef.Owned(S);
Chad Rosier1dcde962012-08-08 18:46:20 +00005838
Douglas Gregor306de2f2010-04-22 23:59:56 +00005839 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00005840 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00005841 CatchStmts, Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005842}
Mike Stump11289f42009-09-09 15:08:12 +00005843
Douglas Gregorebe10102009-08-20 07:17:43 +00005844template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005845StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005846TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005847 // Transform the @catch parameter, if there is one.
5848 VarDecl *Var = 0;
5849 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5850 TypeSourceInfo *TSInfo = 0;
5851 if (FromVar->getTypeSourceInfo()) {
5852 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5853 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005854 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005855 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005856
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005857 QualType T;
5858 if (TSInfo)
5859 T = TSInfo->getType();
5860 else {
5861 T = getDerived().TransformType(FromVar->getType());
5862 if (T.isNull())
Chad Rosier1dcde962012-08-08 18:46:20 +00005863 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005864 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005865
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005866 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5867 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00005868 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005869 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005870
John McCalldadc5752010-08-24 06:29:42 +00005871 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005872 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005873 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005874
5875 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005876 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005877 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005878}
Mike Stump11289f42009-09-09 15:08:12 +00005879
Douglas Gregorebe10102009-08-20 07:17:43 +00005880template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005881StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005882TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005883 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005884 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005885 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005886 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005887
Douglas Gregor306de2f2010-04-22 23:59:56 +00005888 // If nothing changed, just retain this statement.
5889 if (!getDerived().AlwaysRebuild() &&
5890 Body.get() == S->getFinallyBody())
John McCallc3007a22010-10-26 07:05:15 +00005891 return SemaRef.Owned(S);
Douglas Gregor306de2f2010-04-22 23:59:56 +00005892
5893 // Build a new statement.
5894 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00005895 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005896}
Mike Stump11289f42009-09-09 15:08:12 +00005897
Douglas Gregorebe10102009-08-20 07:17:43 +00005898template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005899StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005900TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005901 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00005902 if (S->getThrowExpr()) {
5903 Operand = getDerived().TransformExpr(S->getThrowExpr());
5904 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005905 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00005906 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005907
Douglas Gregor2900c162010-04-22 21:44:01 +00005908 if (!getDerived().AlwaysRebuild() &&
5909 Operand.get() == S->getThrowExpr())
John McCallc3007a22010-10-26 07:05:15 +00005910 return getSema().Owned(S);
Chad Rosier1dcde962012-08-08 18:46:20 +00005911
John McCallb268a282010-08-23 23:25:46 +00005912 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005913}
Mike Stump11289f42009-09-09 15:08:12 +00005914
Douglas Gregorebe10102009-08-20 07:17:43 +00005915template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005916StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005917TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00005918 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00005919 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00005920 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00005921 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005922 return StmtError();
John McCalld9bb7432011-07-27 21:50:02 +00005923 Object =
5924 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
5925 Object.get());
5926 if (Object.isInvalid())
5927 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005928
Douglas Gregor6148de72010-04-22 22:01:21 +00005929 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005930 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00005931 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005932 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005933
Douglas Gregor6148de72010-04-22 22:01:21 +00005934 // If nothing change, just retain the current statement.
5935 if (!getDerived().AlwaysRebuild() &&
5936 Object.get() == S->getSynchExpr() &&
5937 Body.get() == S->getSynchBody())
John McCallc3007a22010-10-26 07:05:15 +00005938 return SemaRef.Owned(S);
Douglas Gregor6148de72010-04-22 22:01:21 +00005939
5940 // Build a new statement.
5941 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00005942 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005943}
5944
5945template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005946StmtResult
John McCall31168b02011-06-15 23:02:42 +00005947TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
5948 ObjCAutoreleasePoolStmt *S) {
5949 // Transform the body.
5950 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
5951 if (Body.isInvalid())
5952 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005953
John McCall31168b02011-06-15 23:02:42 +00005954 // If nothing changed, just retain this statement.
5955 if (!getDerived().AlwaysRebuild() &&
5956 Body.get() == S->getSubStmt())
5957 return SemaRef.Owned(S);
5958
5959 // Build a new statement.
5960 return getDerived().RebuildObjCAutoreleasePoolStmt(
5961 S->getAtLoc(), Body.get());
5962}
5963
5964template<typename Derived>
5965StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005966TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00005967 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00005968 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00005969 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005970 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005971 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005972
Douglas Gregorf68a5082010-04-22 23:10:45 +00005973 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00005974 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005975 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005976 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005977
Douglas Gregorf68a5082010-04-22 23:10:45 +00005978 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005979 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005980 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005981 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005982
Douglas Gregorf68a5082010-04-22 23:10:45 +00005983 // If nothing changed, just retain this statement.
5984 if (!getDerived().AlwaysRebuild() &&
5985 Element.get() == S->getElement() &&
5986 Collection.get() == S->getCollection() &&
5987 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005988 return SemaRef.Owned(S);
Chad Rosier1dcde962012-08-08 18:46:20 +00005989
Douglas Gregorf68a5082010-04-22 23:10:45 +00005990 // Build a new statement.
5991 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00005992 Element.get(),
5993 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00005994 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005995 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005996}
5997
David Majnemer5f7efef2013-10-15 09:50:08 +00005998template <typename Derived>
5999StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006000 // Transform the exception declaration, if any.
6001 VarDecl *Var = 0;
David Majnemer5f7efef2013-10-15 09:50:08 +00006002 if (VarDecl *ExceptionDecl = S->getExceptionDecl()) {
6003 TypeSourceInfo *T =
6004 getDerived().TransformType(ExceptionDecl->getTypeSourceInfo());
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00006005 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006006 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006007
David Majnemer5f7efef2013-10-15 09:50:08 +00006008 Var = getDerived().RebuildExceptionDecl(
6009 ExceptionDecl, T, ExceptionDecl->getInnerLocStart(),
6010 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
Douglas Gregorb412e172010-07-25 18:17:45 +00006011 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00006012 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00006013 }
Mike Stump11289f42009-09-09 15:08:12 +00006014
Douglas Gregorebe10102009-08-20 07:17:43 +00006015 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00006016 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00006017 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006018 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006019
David Majnemer5f7efef2013-10-15 09:50:08 +00006020 if (!getDerived().AlwaysRebuild() && !Var &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006021 Handler.get() == S->getHandlerBlock())
John McCallc3007a22010-10-26 07:05:15 +00006022 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00006023
David Majnemer5f7efef2013-10-15 09:50:08 +00006024 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006025}
Mike Stump11289f42009-09-09 15:08:12 +00006026
David Majnemer5f7efef2013-10-15 09:50:08 +00006027template <typename Derived>
6028StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006029 // Transform the try block itself.
David Majnemer5f7efef2013-10-15 09:50:08 +00006030 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
Douglas Gregorebe10102009-08-20 07:17:43 +00006031 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006032 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006033
Douglas Gregorebe10102009-08-20 07:17:43 +00006034 // Transform the handlers.
6035 bool HandlerChanged = false;
David Majnemer5f7efef2013-10-15 09:50:08 +00006036 SmallVector<Stmt *, 8> Handlers;
Douglas Gregorebe10102009-08-20 07:17:43 +00006037 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
David Majnemer5f7efef2013-10-15 09:50:08 +00006038 StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I));
Douglas Gregorebe10102009-08-20 07:17:43 +00006039 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006040 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006041
Douglas Gregorebe10102009-08-20 07:17:43 +00006042 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
6043 Handlers.push_back(Handler.takeAs<Stmt>());
6044 }
Mike Stump11289f42009-09-09 15:08:12 +00006045
David Majnemer5f7efef2013-10-15 09:50:08 +00006046 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006047 !HandlerChanged)
John McCallc3007a22010-10-26 07:05:15 +00006048 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00006049
John McCallb268a282010-08-23 23:25:46 +00006050 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006051 Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00006052}
Mike Stump11289f42009-09-09 15:08:12 +00006053
Richard Smith02e85f32011-04-14 22:09:26 +00006054template<typename Derived>
6055StmtResult
6056TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
6057 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
6058 if (Range.isInvalid())
6059 return StmtError();
6060
6061 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
6062 if (BeginEnd.isInvalid())
6063 return StmtError();
6064
6065 ExprResult Cond = getDerived().TransformExpr(S->getCond());
6066 if (Cond.isInvalid())
6067 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006068 if (Cond.get())
6069 Cond = SemaRef.CheckBooleanCondition(Cond.take(), S->getColonLoc());
6070 if (Cond.isInvalid())
6071 return StmtError();
6072 if (Cond.get())
6073 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.take());
Richard Smith02e85f32011-04-14 22:09:26 +00006074
6075 ExprResult Inc = getDerived().TransformExpr(S->getInc());
6076 if (Inc.isInvalid())
6077 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006078 if (Inc.get())
6079 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.take());
Richard Smith02e85f32011-04-14 22:09:26 +00006080
6081 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
6082 if (LoopVar.isInvalid())
6083 return StmtError();
6084
6085 StmtResult NewStmt = S;
6086 if (getDerived().AlwaysRebuild() ||
6087 Range.get() != S->getRangeStmt() ||
6088 BeginEnd.get() != S->getBeginEndStmt() ||
6089 Cond.get() != S->getCond() ||
6090 Inc.get() != S->getInc() ||
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006091 LoopVar.get() != S->getLoopVarStmt()) {
Richard Smith02e85f32011-04-14 22:09:26 +00006092 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6093 S->getColonLoc(), Range.get(),
6094 BeginEnd.get(), Cond.get(),
6095 Inc.get(), LoopVar.get(),
6096 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006097 if (NewStmt.isInvalid())
6098 return StmtError();
6099 }
Richard Smith02e85f32011-04-14 22:09:26 +00006100
6101 StmtResult Body = getDerived().TransformStmt(S->getBody());
6102 if (Body.isInvalid())
6103 return StmtError();
6104
6105 // Body has changed but we didn't rebuild the for-range statement. Rebuild
6106 // it now so we have a new statement to attach the body to.
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006107 if (Body.get() != S->getBody() && NewStmt.get() == S) {
Richard Smith02e85f32011-04-14 22:09:26 +00006108 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6109 S->getColonLoc(), Range.get(),
6110 BeginEnd.get(), Cond.get(),
6111 Inc.get(), LoopVar.get(),
6112 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006113 if (NewStmt.isInvalid())
6114 return StmtError();
6115 }
Richard Smith02e85f32011-04-14 22:09:26 +00006116
6117 if (NewStmt.get() == S)
6118 return SemaRef.Owned(S);
6119
6120 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
6121}
6122
John Wiegley1c0675e2011-04-28 01:08:34 +00006123template<typename Derived>
6124StmtResult
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006125TreeTransform<Derived>::TransformMSDependentExistsStmt(
6126 MSDependentExistsStmt *S) {
6127 // Transform the nested-name-specifier, if any.
6128 NestedNameSpecifierLoc QualifierLoc;
6129 if (S->getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006130 QualifierLoc
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006131 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
6132 if (!QualifierLoc)
6133 return StmtError();
6134 }
6135
6136 // Transform the declaration name.
6137 DeclarationNameInfo NameInfo = S->getNameInfo();
6138 if (NameInfo.getName()) {
6139 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6140 if (!NameInfo.getName())
6141 return StmtError();
6142 }
6143
6144 // Check whether anything changed.
6145 if (!getDerived().AlwaysRebuild() &&
6146 QualifierLoc == S->getQualifierLoc() &&
6147 NameInfo.getName() == S->getNameInfo().getName())
6148 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006149
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006150 // Determine whether this name exists, if we can.
6151 CXXScopeSpec SS;
6152 SS.Adopt(QualifierLoc);
6153 bool Dependent = false;
6154 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/0, SS, NameInfo)) {
6155 case Sema::IER_Exists:
6156 if (S->isIfExists())
6157 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006158
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006159 return new (getSema().Context) NullStmt(S->getKeywordLoc());
6160
6161 case Sema::IER_DoesNotExist:
6162 if (S->isIfNotExists())
6163 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006164
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006165 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00006166
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006167 case Sema::IER_Dependent:
6168 Dependent = true;
6169 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006170
Douglas Gregor4a2a8f72011-10-25 03:44:56 +00006171 case Sema::IER_Error:
6172 return StmtError();
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006173 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006174
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006175 // We need to continue with the instantiation, so do so now.
6176 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
6177 if (SubStmt.isInvalid())
6178 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006179
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006180 // If we have resolved the name, just transform to the substatement.
6181 if (!Dependent)
6182 return SubStmt;
Chad Rosier1dcde962012-08-08 18:46:20 +00006183
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006184 // The name is still dependent, so build a dependent expression again.
6185 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
6186 S->isIfExists(),
6187 QualifierLoc,
6188 NameInfo,
6189 SubStmt.get());
6190}
6191
6192template<typename Derived>
John McCall5e77d762013-04-16 07:28:30 +00006193ExprResult
6194TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
6195 NestedNameSpecifierLoc QualifierLoc;
6196 if (E->getQualifierLoc()) {
6197 QualifierLoc
6198 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6199 if (!QualifierLoc)
6200 return ExprError();
6201 }
6202
6203 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
6204 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
6205 if (!PD)
6206 return ExprError();
6207
6208 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
6209 if (Base.isInvalid())
6210 return ExprError();
6211
6212 return new (SemaRef.getASTContext())
6213 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
6214 SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
6215 QualifierLoc, E->getMemberLoc());
6216}
6217
David Majnemerfad8f482013-10-15 09:33:02 +00006218template <typename Derived>
6219StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00006220 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006221 if (TryBlock.isInvalid())
6222 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006223
6224 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
David Majnemer7e755502013-10-15 09:30:14 +00006225 if (Handler.isInvalid())
6226 return StmtError();
6227
David Majnemerfad8f482013-10-15 09:33:02 +00006228 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
6229 Handler.get() == S->getHandler())
John Wiegley1c0675e2011-04-28 01:08:34 +00006230 return SemaRef.Owned(S);
6231
David Majnemerfad8f482013-10-15 09:33:02 +00006232 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(),
6233 TryBlock.take(), Handler.take());
John Wiegley1c0675e2011-04-28 01:08:34 +00006234}
6235
David Majnemerfad8f482013-10-15 09:33:02 +00006236template <typename Derived>
6237StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00006238 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006239 if (Block.isInvalid())
6240 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006241
David Majnemerfad8f482013-10-15 09:33:02 +00006242 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.take());
John Wiegley1c0675e2011-04-28 01:08:34 +00006243}
6244
David Majnemerfad8f482013-10-15 09:33:02 +00006245template <typename Derived>
6246StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
John Wiegley1c0675e2011-04-28 01:08:34 +00006247 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
David Majnemerfad8f482013-10-15 09:33:02 +00006248 if (FilterExpr.isInvalid())
6249 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006250
David Majnemer7e755502013-10-15 09:30:14 +00006251 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006252 if (Block.isInvalid())
6253 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006254
David Majnemerfad8f482013-10-15 09:33:02 +00006255 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.take(),
John Wiegley1c0675e2011-04-28 01:08:34 +00006256 Block.take());
6257}
6258
David Majnemerfad8f482013-10-15 09:33:02 +00006259template <typename Derived>
6260StmtResult TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
6261 if (isa<SEHFinallyStmt>(Handler))
John Wiegley1c0675e2011-04-28 01:08:34 +00006262 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
6263 else
6264 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
6265}
6266
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006267template<typename Derived>
6268StmtResult
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006269TreeTransform<Derived>::TransformOMPExecutableDirective(
6270 OMPExecutableDirective *D) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00006271
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006272 // Transform the clauses
Alexey Bataev758e55e2013-09-06 18:03:48 +00006273 llvm::SmallVector<OMPClause *, 16> TClauses;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006274 ArrayRef<OMPClause *> Clauses = D->clauses();
6275 TClauses.reserve(Clauses.size());
6276 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
6277 I != E; ++I) {
6278 if (*I) {
6279 OMPClause *Clause = getDerived().TransformOMPClause(*I);
Alexey Bataev758e55e2013-09-06 18:03:48 +00006280 if (!Clause) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006281 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00006282 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006283 TClauses.push_back(Clause);
6284 }
6285 else {
6286 TClauses.push_back(0);
6287 }
6288 }
Alexey Bataev758e55e2013-09-06 18:03:48 +00006289 if (!D->getAssociatedStmt()) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006290 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00006291 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006292 StmtResult AssociatedStmt =
6293 getDerived().TransformStmt(D->getAssociatedStmt());
Alexey Bataev758e55e2013-09-06 18:03:48 +00006294 if (AssociatedStmt.isInvalid()) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006295 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00006296 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006297
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006298 return getDerived().RebuildOMPExecutableDirective(D->getDirectiveKind(),
6299 TClauses,
6300 AssociatedStmt.take(),
6301 D->getLocStart(),
6302 D->getLocEnd());
6303}
6304
6305template<typename Derived>
6306StmtResult
6307TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
6308 DeclarationNameInfo DirName;
Alexey Bataev3d76e772014-03-07 04:01:56 +00006309 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, 0);
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006310 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6311 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6312 return Res;
6313}
6314
6315template<typename Derived>
6316StmtResult
6317TreeTransform<Derived>::TransformOMPSimdDirective(OMPSimdDirective *D) {
6318 DeclarationNameInfo DirName;
6319 getSema().StartOpenMPDSABlock(OMPD_simd, DirName, 0);
6320 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6321 getDerived().getSema().EndOpenMPDSABlock(Res.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00006322 return Res;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006323}
6324
6325template<typename Derived>
6326OMPClause *
Alexey Bataevaadd52e2014-02-13 05:29:23 +00006327TreeTransform<Derived>::TransformOMPIfClause(OMPIfClause *C) {
Alexey Bataevaf7849e2014-03-05 06:45:14 +00006328 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
6329 if (Cond.isInvalid())
6330 return 0;
6331 return getDerived().RebuildOMPIfClause(Cond.take(), C->getLocStart(),
Alexey Bataevaadd52e2014-02-13 05:29:23 +00006332 C->getLParenLoc(), C->getLocEnd());
6333}
6334
6335template<typename Derived>
6336OMPClause *
Alexey Bataev568a8332014-03-06 06:15:19 +00006337TreeTransform<Derived>::TransformOMPNumThreadsClause(OMPNumThreadsClause *C) {
6338 ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads());
6339 if (NumThreads.isInvalid())
6340 return 0;
6341 return getDerived().RebuildOMPNumThreadsClause(NumThreads.take(),
6342 C->getLocStart(),
6343 C->getLParenLoc(),
6344 C->getLocEnd());
6345}
6346
6347template<typename Derived>
6348OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006349TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
6350 return getDerived().RebuildOMPDefaultClause(C->getDefaultKind(),
6351 C->getDefaultKindKwLoc(),
6352 C->getLocStart(),
6353 C->getLParenLoc(),
6354 C->getLocEnd());
6355}
6356
6357template<typename Derived>
6358OMPClause *
6359TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00006360 llvm::SmallVector<Expr *, 16> Vars;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006361 Vars.reserve(C->varlist_size());
Alexey Bataev756c1962013-09-24 03:17:45 +00006362 for (OMPPrivateClause::varlist_iterator I = C->varlist_begin(),
6363 E = C->varlist_end();
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006364 I != E; ++I) {
6365 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(*I));
6366 if (EVar.isInvalid())
6367 return 0;
6368 Vars.push_back(EVar.take());
6369 }
6370 return getDerived().RebuildOMPPrivateClause(Vars,
6371 C->getLocStart(),
6372 C->getLParenLoc(),
6373 C->getLocEnd());
6374}
6375
Alexey Bataev758e55e2013-09-06 18:03:48 +00006376template<typename Derived>
6377OMPClause *
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006378TreeTransform<Derived>::TransformOMPFirstprivateClause(
6379 OMPFirstprivateClause *C) {
6380 llvm::SmallVector<Expr *, 16> Vars;
6381 Vars.reserve(C->varlist_size());
6382 for (OMPFirstprivateClause::varlist_iterator I = C->varlist_begin(),
6383 E = C->varlist_end();
6384 I != E; ++I) {
6385 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(*I));
6386 if (EVar.isInvalid())
6387 return 0;
6388 Vars.push_back(EVar.take());
6389 }
6390 return getDerived().RebuildOMPFirstprivateClause(Vars,
6391 C->getLocStart(),
6392 C->getLParenLoc(),
6393 C->getLocEnd());
6394}
6395
6396template<typename Derived>
6397OMPClause *
Alexey Bataev758e55e2013-09-06 18:03:48 +00006398TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
6399 llvm::SmallVector<Expr *, 16> Vars;
6400 Vars.reserve(C->varlist_size());
Alexey Bataev756c1962013-09-24 03:17:45 +00006401 for (OMPSharedClause::varlist_iterator I = C->varlist_begin(),
6402 E = C->varlist_end();
Alexey Bataev758e55e2013-09-06 18:03:48 +00006403 I != E; ++I) {
6404 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(*I));
6405 if (EVar.isInvalid())
6406 return 0;
6407 Vars.push_back(EVar.take());
6408 }
6409 return getDerived().RebuildOMPSharedClause(Vars,
6410 C->getLocStart(),
6411 C->getLParenLoc(),
6412 C->getLocEnd());
6413}
6414
Douglas Gregorebe10102009-08-20 07:17:43 +00006415//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00006416// Expression transformation
6417//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00006418template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006419ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006420TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006421 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006422}
Mike Stump11289f42009-09-09 15:08:12 +00006423
6424template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006425ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006426TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregorea972d32011-02-28 21:54:11 +00006427 NestedNameSpecifierLoc QualifierLoc;
6428 if (E->getQualifierLoc()) {
6429 QualifierLoc
6430 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6431 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00006432 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00006433 }
John McCallce546572009-12-08 09:08:17 +00006434
6435 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006436 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6437 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006438 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00006439 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006440
John McCall815039a2010-08-17 21:27:17 +00006441 DeclarationNameInfo NameInfo = E->getNameInfo();
6442 if (NameInfo.getName()) {
6443 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6444 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00006445 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00006446 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006447
6448 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00006449 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00006450 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006451 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00006452 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00006453
6454 // Mark it referenced in the new context regardless.
6455 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00006456 SemaRef.MarkDeclRefReferenced(E);
John McCallce546572009-12-08 09:08:17 +00006457
John McCallc3007a22010-10-26 07:05:15 +00006458 return SemaRef.Owned(E);
Douglas Gregor4bd90e52009-10-23 18:54:35 +00006459 }
John McCallce546572009-12-08 09:08:17 +00006460
6461 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCallb3774b52010-08-19 23:49:38 +00006462 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00006463 TemplateArgs = &TransArgs;
6464 TransArgs.setLAngleLoc(E->getLAngleLoc());
6465 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006466 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6467 E->getNumTemplateArgs(),
6468 TransArgs))
6469 return ExprError();
John McCallce546572009-12-08 09:08:17 +00006470 }
6471
Chad Rosier1dcde962012-08-08 18:46:20 +00006472 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregorea972d32011-02-28 21:54:11 +00006473 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00006474}
Mike Stump11289f42009-09-09 15:08:12 +00006475
Douglas Gregora16548e2009-08-11 05:31:07 +00006476template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006477ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006478TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00006479 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006480}
Mike Stump11289f42009-09-09 15:08:12 +00006481
Douglas Gregora16548e2009-08-11 05:31:07 +00006482template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006483ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006484TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00006485 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006486}
Mike Stump11289f42009-09-09 15:08:12 +00006487
Douglas Gregora16548e2009-08-11 05:31:07 +00006488template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006489ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006490TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00006491 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006492}
Mike Stump11289f42009-09-09 15:08:12 +00006493
Douglas Gregora16548e2009-08-11 05:31:07 +00006494template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006495ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006496TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00006497 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006498}
Mike Stump11289f42009-09-09 15:08:12 +00006499
Douglas Gregora16548e2009-08-11 05:31:07 +00006500template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006501ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006502TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00006503 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006504}
6505
6506template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006507ExprResult
Richard Smithc67fdd42012-03-07 08:35:16 +00006508TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
Argyrios Kyrtzidis25049092013-04-09 01:17:02 +00006509 if (FunctionDecl *FD = E->getDirectCallee())
6510 SemaRef.MarkFunctionReferenced(E->getLocStart(), FD);
Richard Smithc67fdd42012-03-07 08:35:16 +00006511 return SemaRef.MaybeBindToTemporary(E);
6512}
6513
6514template<typename Derived>
6515ExprResult
Peter Collingbourne91147592011-04-15 00:35:48 +00006516TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
6517 ExprResult ControllingExpr =
6518 getDerived().TransformExpr(E->getControllingExpr());
6519 if (ControllingExpr.isInvalid())
6520 return ExprError();
6521
Chris Lattner01cf8db2011-07-20 06:58:45 +00006522 SmallVector<Expr *, 4> AssocExprs;
6523 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbourne91147592011-04-15 00:35:48 +00006524 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
6525 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
6526 if (TS) {
6527 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
6528 if (!AssocType)
6529 return ExprError();
6530 AssocTypes.push_back(AssocType);
6531 } else {
6532 AssocTypes.push_back(0);
6533 }
6534
6535 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
6536 if (AssocExpr.isInvalid())
6537 return ExprError();
6538 AssocExprs.push_back(AssocExpr.release());
6539 }
6540
6541 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
6542 E->getDefaultLoc(),
6543 E->getRParenLoc(),
6544 ControllingExpr.release(),
Dmitri Gribenko82360372013-05-10 13:06:58 +00006545 AssocTypes,
6546 AssocExprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00006547}
6548
6549template<typename Derived>
6550ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006551TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006552 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006553 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006554 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006555
Douglas Gregora16548e2009-08-11 05:31:07 +00006556 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006557 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006558
John McCallb268a282010-08-23 23:25:46 +00006559 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006560 E->getRParen());
6561}
6562
Richard Smithdb2630f2012-10-21 03:28:35 +00006563/// \brief The operand of a unary address-of operator has special rules: it's
6564/// allowed to refer to a non-static member of a class even if there's no 'this'
6565/// object available.
6566template<typename Derived>
6567ExprResult
6568TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
6569 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
6570 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true);
6571 else
6572 return getDerived().TransformExpr(E);
6573}
6574
Mike Stump11289f42009-09-09 15:08:12 +00006575template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006576ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006577TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smitheebe125f2013-05-21 23:29:46 +00006578 ExprResult SubExpr;
6579 if (E->getOpcode() == UO_AddrOf)
6580 SubExpr = TransformAddressOfOperand(E->getSubExpr());
6581 else
6582 SubExpr = TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006583 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006584 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006585
Douglas Gregora16548e2009-08-11 05:31:07 +00006586 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006587 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006588
Douglas Gregora16548e2009-08-11 05:31:07 +00006589 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
6590 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00006591 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006592}
Mike Stump11289f42009-09-09 15:08:12 +00006593
Douglas Gregora16548e2009-08-11 05:31:07 +00006594template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006595ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00006596TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
6597 // Transform the type.
6598 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
6599 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00006600 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006601
Douglas Gregor882211c2010-04-28 22:16:22 +00006602 // Transform all of the components into components similar to what the
6603 // parser uses.
Chad Rosier1dcde962012-08-08 18:46:20 +00006604 // FIXME: It would be slightly more efficient in the non-dependent case to
6605 // just map FieldDecls, rather than requiring the rebuilder to look for
6606 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00006607 // template code that we don't care.
6608 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00006609 typedef Sema::OffsetOfComponent Component;
Douglas Gregor882211c2010-04-28 22:16:22 +00006610 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner01cf8db2011-07-20 06:58:45 +00006611 SmallVector<Component, 4> Components;
Douglas Gregor882211c2010-04-28 22:16:22 +00006612 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
6613 const Node &ON = E->getComponent(I);
6614 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00006615 Comp.isBrackets = true;
Abramo Bagnara6b6f0512011-03-12 09:45:03 +00006616 Comp.LocStart = ON.getSourceRange().getBegin();
6617 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor882211c2010-04-28 22:16:22 +00006618 switch (ON.getKind()) {
6619 case Node::Array: {
6620 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00006621 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00006622 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006623 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006624
Douglas Gregor882211c2010-04-28 22:16:22 +00006625 ExprChanged = ExprChanged || Index.get() != FromIndex;
6626 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00006627 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00006628 break;
6629 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006630
Douglas Gregor882211c2010-04-28 22:16:22 +00006631 case Node::Field:
6632 case Node::Identifier:
6633 Comp.isBrackets = false;
6634 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00006635 if (!Comp.U.IdentInfo)
6636 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00006637
Douglas Gregor882211c2010-04-28 22:16:22 +00006638 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006639
Douglas Gregord1702062010-04-29 00:18:15 +00006640 case Node::Base:
6641 // Will be recomputed during the rebuild.
6642 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00006643 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006644
Douglas Gregor882211c2010-04-28 22:16:22 +00006645 Components.push_back(Comp);
6646 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006647
Douglas Gregor882211c2010-04-28 22:16:22 +00006648 // If nothing changed, retain the existing expression.
6649 if (!getDerived().AlwaysRebuild() &&
6650 Type == E->getTypeSourceInfo() &&
6651 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00006652 return SemaRef.Owned(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00006653
Douglas Gregor882211c2010-04-28 22:16:22 +00006654 // Build a new offsetof expression.
6655 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
6656 Components.data(), Components.size(),
6657 E->getRParenLoc());
6658}
6659
6660template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006661ExprResult
John McCall8d69a212010-11-15 23:31:06 +00006662TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
6663 assert(getDerived().AlreadyTransformed(E->getType()) &&
6664 "opaque value expression requires transformation");
6665 return SemaRef.Owned(E);
6666}
6667
6668template<typename Derived>
6669ExprResult
John McCallfe96e0b2011-11-06 09:01:30 +00006670TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCalle9290822011-11-30 04:42:31 +00006671 // Rebuild the syntactic form. The original syntactic form has
6672 // opaque-value expressions in it, so strip those away and rebuild
6673 // the result. This is a really awful way of doing this, but the
6674 // better solution (rebuilding the semantic expressions and
6675 // rebinding OVEs as necessary) doesn't work; we'd need
6676 // TreeTransform to not strip away implicit conversions.
6677 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
6678 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCallfe96e0b2011-11-06 09:01:30 +00006679 if (result.isInvalid()) return ExprError();
6680
6681 // If that gives us a pseudo-object result back, the pseudo-object
6682 // expression must have been an lvalue-to-rvalue conversion which we
6683 // should reapply.
6684 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
6685 result = SemaRef.checkPseudoObjectRValue(result.take());
6686
6687 return result;
6688}
6689
6690template<typename Derived>
6691ExprResult
Peter Collingbournee190dee2011-03-11 19:24:49 +00006692TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
6693 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006694 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00006695 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00006696
John McCallbcd03502009-12-07 02:54:59 +00006697 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00006698 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00006699 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006700
John McCall4c98fd82009-11-04 07:28:41 +00006701 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCallc3007a22010-10-26 07:05:15 +00006702 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006703
Peter Collingbournee190dee2011-03-11 19:24:49 +00006704 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
6705 E->getKind(),
6706 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00006707 }
Mike Stump11289f42009-09-09 15:08:12 +00006708
Eli Friedmane4f22df2012-02-29 04:03:55 +00006709 // C++0x [expr.sizeof]p1:
6710 // The operand is either an expression, which is an unevaluated operand
6711 // [...]
Eli Friedman15681d62012-09-26 04:34:21 +00006712 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
6713 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00006714
Eli Friedmane4f22df2012-02-29 04:03:55 +00006715 ExprResult SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
6716 if (SubExpr.isInvalid())
6717 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006718
Eli Friedmane4f22df2012-02-29 04:03:55 +00006719 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
6720 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006721
Peter Collingbournee190dee2011-03-11 19:24:49 +00006722 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
6723 E->getOperatorLoc(),
6724 E->getKind(),
6725 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00006726}
Mike Stump11289f42009-09-09 15:08:12 +00006727
Douglas Gregora16548e2009-08-11 05:31:07 +00006728template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006729ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006730TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006731 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006732 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006733 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006734
John McCalldadc5752010-08-24 06:29:42 +00006735 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006736 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006737 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006738
6739
Douglas Gregora16548e2009-08-11 05:31:07 +00006740 if (!getDerived().AlwaysRebuild() &&
6741 LHS.get() == E->getLHS() &&
6742 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00006743 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006744
John McCallb268a282010-08-23 23:25:46 +00006745 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006746 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00006747 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006748 E->getRBracketLoc());
6749}
Mike Stump11289f42009-09-09 15:08:12 +00006750
6751template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006752ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006753TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006754 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00006755 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00006756 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006757 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006758
6759 // Transform arguments.
6760 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006761 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00006762 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00006763 &ArgChanged))
6764 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006765
Douglas Gregora16548e2009-08-11 05:31:07 +00006766 if (!getDerived().AlwaysRebuild() &&
6767 Callee.get() == E->getCallee() &&
6768 !ArgChanged)
Dmitri Gribenko76bb5cabfa2012-09-10 21:20:09 +00006769 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00006770
Douglas Gregora16548e2009-08-11 05:31:07 +00006771 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00006772 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00006773 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00006774 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006775 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00006776 E->getRParenLoc());
6777}
Mike Stump11289f42009-09-09 15:08:12 +00006778
6779template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006780ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006781TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006782 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00006783 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006784 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006785
Douglas Gregorea972d32011-02-28 21:54:11 +00006786 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorf405d7e2009-08-31 23:41:50 +00006787 if (E->hasQualifier()) {
Douglas Gregorea972d32011-02-28 21:54:11 +00006788 QualifierLoc
6789 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00006790
Douglas Gregorea972d32011-02-28 21:54:11 +00006791 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00006792 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00006793 }
Abramo Bagnara7945c982012-01-27 09:46:47 +00006794 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00006795
Eli Friedman2cfcef62009-12-04 06:40:45 +00006796 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006797 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
6798 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006799 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00006800 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006801
John McCall16df1e52010-03-30 21:47:33 +00006802 NamedDecl *FoundDecl = E->getFoundDecl();
6803 if (FoundDecl == E->getMemberDecl()) {
6804 FoundDecl = Member;
6805 } else {
6806 FoundDecl = cast_or_null<NamedDecl>(
6807 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
6808 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00006809 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00006810 }
6811
Douglas Gregora16548e2009-08-11 05:31:07 +00006812 if (!getDerived().AlwaysRebuild() &&
6813 Base.get() == E->getBase() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00006814 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00006815 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00006816 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00006817 !E->hasExplicitTemplateArgs()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006818
Anders Carlsson9c45ad72009-12-22 05:24:09 +00006819 // Mark it referenced in the new context regardless.
6820 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00006821 SemaRef.MarkMemberReferenced(E);
6822
John McCallc3007a22010-10-26 07:05:15 +00006823 return SemaRef.Owned(E);
Anders Carlsson9c45ad72009-12-22 05:24:09 +00006824 }
Douglas Gregora16548e2009-08-11 05:31:07 +00006825
John McCall6b51f282009-11-23 01:53:49 +00006826 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00006827 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00006828 TransArgs.setLAngleLoc(E->getLAngleLoc());
6829 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006830 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6831 E->getNumTemplateArgs(),
6832 TransArgs))
6833 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00006834 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006835
Douglas Gregora16548e2009-08-11 05:31:07 +00006836 // FIXME: Bogus source location for the operator
6837 SourceLocation FakeOperatorLoc
6838 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
6839
John McCall38836f02010-01-15 08:34:02 +00006840 // FIXME: to do this check properly, we will need to preserve the
6841 // first-qualifier-in-scope here, just in case we had a dependent
6842 // base (and therefore couldn't do the check) and a
6843 // nested-name-qualifier (and therefore could do the lookup).
6844 NamedDecl *FirstQualifierInScope = 0;
6845
John McCallb268a282010-08-23 23:25:46 +00006846 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00006847 E->isArrow(),
Douglas Gregorea972d32011-02-28 21:54:11 +00006848 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00006849 TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006850 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00006851 Member,
John McCall16df1e52010-03-30 21:47:33 +00006852 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00006853 (E->hasExplicitTemplateArgs()
John McCall6b51f282009-11-23 01:53:49 +00006854 ? &TransArgs : 0),
John McCall38836f02010-01-15 08:34:02 +00006855 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00006856}
Mike Stump11289f42009-09-09 15:08:12 +00006857
Douglas Gregora16548e2009-08-11 05:31:07 +00006858template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006859ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006860TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00006861 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006862 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006863 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006864
John McCalldadc5752010-08-24 06:29:42 +00006865 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006866 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006867 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006868
Douglas Gregora16548e2009-08-11 05:31:07 +00006869 if (!getDerived().AlwaysRebuild() &&
6870 LHS.get() == E->getLHS() &&
6871 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00006872 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006873
Lang Hames5de91cc2012-10-02 04:45:10 +00006874 Sema::FPContractStateRAII FPContractState(getSema());
6875 getSema().FPFeatures.fp_contract = E->isFPContractable();
6876
Douglas Gregora16548e2009-08-11 05:31:07 +00006877 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00006878 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006879}
6880
Mike Stump11289f42009-09-09 15:08:12 +00006881template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006882ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006883TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00006884 CompoundAssignOperator *E) {
6885 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006886}
Mike Stump11289f42009-09-09 15:08:12 +00006887
Douglas Gregora16548e2009-08-11 05:31:07 +00006888template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00006889ExprResult TreeTransform<Derived>::
6890TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
6891 // Just rebuild the common and RHS expressions and see whether we
6892 // get any changes.
6893
6894 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
6895 if (commonExpr.isInvalid())
6896 return ExprError();
6897
6898 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
6899 if (rhs.isInvalid())
6900 return ExprError();
6901
6902 if (!getDerived().AlwaysRebuild() &&
6903 commonExpr.get() == e->getCommon() &&
6904 rhs.get() == e->getFalseExpr())
6905 return SemaRef.Owned(e);
6906
6907 return getDerived().RebuildConditionalOperator(commonExpr.take(),
6908 e->getQuestionLoc(),
6909 0,
6910 e->getColonLoc(),
6911 rhs.get());
6912}
6913
6914template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006915ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006916TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00006917 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00006918 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006919 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006920
John McCalldadc5752010-08-24 06:29:42 +00006921 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006922 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006923 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006924
John McCalldadc5752010-08-24 06:29:42 +00006925 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006926 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006927 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006928
Douglas Gregora16548e2009-08-11 05:31:07 +00006929 if (!getDerived().AlwaysRebuild() &&
6930 Cond.get() == E->getCond() &&
6931 LHS.get() == E->getLHS() &&
6932 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00006933 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006934
John McCallb268a282010-08-23 23:25:46 +00006935 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00006936 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00006937 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00006938 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00006939 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006940}
Mike Stump11289f42009-09-09 15:08:12 +00006941
6942template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006943ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006944TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00006945 // Implicit casts are eliminated during transformation, since they
6946 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00006947 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006948}
Mike Stump11289f42009-09-09 15:08:12 +00006949
Douglas Gregora16548e2009-08-11 05:31:07 +00006950template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006951ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006952TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006953 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6954 if (!Type)
6955 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006956
John McCalldadc5752010-08-24 06:29:42 +00006957 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00006958 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006959 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006960 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006961
Douglas Gregora16548e2009-08-11 05:31:07 +00006962 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006963 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006964 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006965 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006966
John McCall97513962010-01-15 18:39:57 +00006967 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006968 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00006969 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006970 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006971}
Mike Stump11289f42009-09-09 15:08:12 +00006972
Douglas Gregora16548e2009-08-11 05:31:07 +00006973template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006974ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006975TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00006976 TypeSourceInfo *OldT = E->getTypeSourceInfo();
6977 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
6978 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00006979 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006980
John McCalldadc5752010-08-24 06:29:42 +00006981 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00006982 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006983 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006984
Douglas Gregora16548e2009-08-11 05:31:07 +00006985 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00006986 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006987 Init.get() == E->getInitializer())
Douglas Gregorc7f46f22011-12-10 00:23:21 +00006988 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006989
John McCall5d7aa7f2010-01-19 22:33:45 +00006990 // Note: the expression type doesn't necessarily match the
6991 // type-as-written, but that's okay, because it should always be
6992 // derivable from the initializer.
6993
John McCalle15bbff2010-01-18 19:35:47 +00006994 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00006995 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00006996 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006997}
Mike Stump11289f42009-09-09 15:08:12 +00006998
Douglas Gregora16548e2009-08-11 05:31:07 +00006999template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007000ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007001TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007002 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00007003 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007004 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007005
Douglas Gregora16548e2009-08-11 05:31:07 +00007006 if (!getDerived().AlwaysRebuild() &&
7007 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007008 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007009
Douglas Gregora16548e2009-08-11 05:31:07 +00007010 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00007011 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00007012 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00007013 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00007014 E->getAccessorLoc(),
7015 E->getAccessor());
7016}
Mike Stump11289f42009-09-09 15:08:12 +00007017
Douglas Gregora16548e2009-08-11 05:31:07 +00007018template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007019ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007020TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007021 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00007022
Benjamin Kramerf0623432012-08-23 22:51:59 +00007023 SmallVector<Expr*, 4> Inits;
Chad Rosier1dcde962012-08-08 18:46:20 +00007024 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00007025 Inits, &InitChanged))
7026 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007027
Douglas Gregora16548e2009-08-11 05:31:07 +00007028 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCallc3007a22010-10-26 07:05:15 +00007029 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007030
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007031 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00007032 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00007033}
Mike Stump11289f42009-09-09 15:08:12 +00007034
Douglas Gregora16548e2009-08-11 05:31:07 +00007035template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007036ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007037TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007038 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00007039
Douglas Gregorebe10102009-08-20 07:17:43 +00007040 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00007041 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00007042 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007043 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007044
Douglas Gregorebe10102009-08-20 07:17:43 +00007045 // transform the designators.
Benjamin Kramerf0623432012-08-23 22:51:59 +00007046 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregora16548e2009-08-11 05:31:07 +00007047 bool ExprChanged = false;
7048 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
7049 DEnd = E->designators_end();
7050 D != DEnd; ++D) {
7051 if (D->isFieldDesignator()) {
7052 Desig.AddDesignator(Designator::getField(D->getFieldName(),
7053 D->getDotLoc(),
7054 D->getFieldLoc()));
7055 continue;
7056 }
Mike Stump11289f42009-09-09 15:08:12 +00007057
Douglas Gregora16548e2009-08-11 05:31:07 +00007058 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00007059 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00007060 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007061 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007062
7063 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007064 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00007065
Douglas Gregora16548e2009-08-11 05:31:07 +00007066 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
7067 ArrayExprs.push_back(Index.release());
7068 continue;
7069 }
Mike Stump11289f42009-09-09 15:08:12 +00007070
Douglas Gregora16548e2009-08-11 05:31:07 +00007071 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00007072 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00007073 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
7074 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007075 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007076
John McCalldadc5752010-08-24 06:29:42 +00007077 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00007078 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007079 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007080
7081 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007082 End.get(),
7083 D->getLBracketLoc(),
7084 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00007085
Douglas Gregora16548e2009-08-11 05:31:07 +00007086 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
7087 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00007088
Douglas Gregora16548e2009-08-11 05:31:07 +00007089 ArrayExprs.push_back(Start.release());
7090 ArrayExprs.push_back(End.release());
7091 }
Mike Stump11289f42009-09-09 15:08:12 +00007092
Douglas Gregora16548e2009-08-11 05:31:07 +00007093 if (!getDerived().AlwaysRebuild() &&
7094 Init.get() == E->getInit() &&
7095 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00007096 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007097
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007098 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00007099 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00007100 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007101}
Mike Stump11289f42009-09-09 15:08:12 +00007102
Douglas Gregora16548e2009-08-11 05:31:07 +00007103template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007104ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007105TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007106 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00007107 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier1dcde962012-08-08 18:46:20 +00007108
Douglas Gregor3da3c062009-10-28 00:29:27 +00007109 // FIXME: Will we ever have proper type location here? Will we actually
7110 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00007111 QualType T = getDerived().TransformType(E->getType());
7112 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00007113 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007114
Douglas Gregora16548e2009-08-11 05:31:07 +00007115 if (!getDerived().AlwaysRebuild() &&
7116 T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00007117 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007118
Douglas Gregora16548e2009-08-11 05:31:07 +00007119 return getDerived().RebuildImplicitValueInitExpr(T);
7120}
Mike Stump11289f42009-09-09 15:08:12 +00007121
Douglas Gregora16548e2009-08-11 05:31:07 +00007122template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007123ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007124TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00007125 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
7126 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007127 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007128
John McCalldadc5752010-08-24 06:29:42 +00007129 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007130 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007131 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007132
Douglas Gregora16548e2009-08-11 05:31:07 +00007133 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00007134 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007135 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00007136 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007137
John McCallb268a282010-08-23 23:25:46 +00007138 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00007139 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007140}
7141
7142template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007143ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007144TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007145 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007146 SmallVector<Expr*, 4> Inits;
Douglas Gregora3efea12011-01-03 19:04:46 +00007147 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
7148 &ArgumentChanged))
7149 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007150
Douglas Gregora16548e2009-08-11 05:31:07 +00007151 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007152 Inits,
Douglas Gregora16548e2009-08-11 05:31:07 +00007153 E->getRParenLoc());
7154}
Mike Stump11289f42009-09-09 15:08:12 +00007155
Douglas Gregora16548e2009-08-11 05:31:07 +00007156/// \brief Transform an address-of-label expression.
7157///
7158/// By default, the transformation of an address-of-label expression always
7159/// rebuilds the expression, so that the label identifier can be resolved to
7160/// the corresponding label statement by semantic analysis.
7161template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007162ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007163TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +00007164 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
7165 E->getLabel());
7166 if (!LD)
7167 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007168
Douglas Gregora16548e2009-08-11 05:31:07 +00007169 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00007170 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +00007171}
Mike Stump11289f42009-09-09 15:08:12 +00007172
7173template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00007174ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007175TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalled7b2782012-04-06 18:20:53 +00007176 SemaRef.ActOnStartStmtExpr();
John McCalldadc5752010-08-24 06:29:42 +00007177 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00007178 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCalled7b2782012-04-06 18:20:53 +00007179 if (SubStmt.isInvalid()) {
7180 SemaRef.ActOnStmtExprError();
John McCallfaf5fb42010-08-26 23:41:50 +00007181 return ExprError();
John McCalled7b2782012-04-06 18:20:53 +00007182 }
Mike Stump11289f42009-09-09 15:08:12 +00007183
Douglas Gregora16548e2009-08-11 05:31:07 +00007184 if (!getDerived().AlwaysRebuild() &&
John McCalled7b2782012-04-06 18:20:53 +00007185 SubStmt.get() == E->getSubStmt()) {
7186 // Calling this an 'error' is unintuitive, but it does the right thing.
7187 SemaRef.ActOnStmtExprError();
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007188 return SemaRef.MaybeBindToTemporary(E);
John McCalled7b2782012-04-06 18:20:53 +00007189 }
Mike Stump11289f42009-09-09 15:08:12 +00007190
7191 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007192 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007193 E->getRParenLoc());
7194}
Mike Stump11289f42009-09-09 15:08:12 +00007195
Douglas Gregora16548e2009-08-11 05:31:07 +00007196template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007197ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007198TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007199 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00007200 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007201 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007202
John McCalldadc5752010-08-24 06:29:42 +00007203 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007204 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007205 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007206
John McCalldadc5752010-08-24 06:29:42 +00007207 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007208 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007209 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007210
Douglas Gregora16548e2009-08-11 05:31:07 +00007211 if (!getDerived().AlwaysRebuild() &&
7212 Cond.get() == E->getCond() &&
7213 LHS.get() == E->getLHS() &&
7214 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00007215 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007216
Douglas Gregora16548e2009-08-11 05:31:07 +00007217 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00007218 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007219 E->getRParenLoc());
7220}
Mike Stump11289f42009-09-09 15:08:12 +00007221
Douglas Gregora16548e2009-08-11 05:31:07 +00007222template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007223ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007224TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007225 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007226}
7227
7228template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007229ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007230TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007231 switch (E->getOperator()) {
7232 case OO_New:
7233 case OO_Delete:
7234 case OO_Array_New:
7235 case OO_Array_Delete:
7236 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier1dcde962012-08-08 18:46:20 +00007237
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007238 case OO_Call: {
7239 // This is a call to an object's operator().
7240 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
7241
7242 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00007243 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007244 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007245 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007246
7247 // FIXME: Poor location information
7248 SourceLocation FakeLParenLoc
7249 = SemaRef.PP.getLocForEndOfToken(
7250 static_cast<Expr *>(Object.get())->getLocEnd());
7251
7252 // Transform the call arguments.
Benjamin Kramerf0623432012-08-23 22:51:59 +00007253 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00007254 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregora3efea12011-01-03 19:04:46 +00007255 Args))
7256 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007257
John McCallb268a282010-08-23 23:25:46 +00007258 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007259 Args,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007260 E->getLocEnd());
7261 }
7262
7263#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
7264 case OO_##Name:
7265#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
7266#include "clang/Basic/OperatorKinds.def"
7267 case OO_Subscript:
7268 // Handled below.
7269 break;
7270
7271 case OO_Conditional:
7272 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007273
7274 case OO_None:
7275 case NUM_OVERLOADED_OPERATORS:
7276 llvm_unreachable("not an overloaded operator?");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007277 }
7278
John McCalldadc5752010-08-24 06:29:42 +00007279 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00007280 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007281 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007282
Richard Smithdb2630f2012-10-21 03:28:35 +00007283 ExprResult First;
7284 if (E->getOperator() == OO_Amp)
7285 First = getDerived().TransformAddressOfOperand(E->getArg(0));
7286 else
7287 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00007288 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007289 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007290
John McCalldadc5752010-08-24 06:29:42 +00007291 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00007292 if (E->getNumArgs() == 2) {
7293 Second = getDerived().TransformExpr(E->getArg(1));
7294 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007295 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007296 }
Mike Stump11289f42009-09-09 15:08:12 +00007297
Douglas Gregora16548e2009-08-11 05:31:07 +00007298 if (!getDerived().AlwaysRebuild() &&
7299 Callee.get() == E->getCallee() &&
7300 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00007301 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007302 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00007303
Lang Hames5de91cc2012-10-02 04:45:10 +00007304 Sema::FPContractStateRAII FPContractState(getSema());
7305 getSema().FPFeatures.fp_contract = E->isFPContractable();
7306
Douglas Gregora16548e2009-08-11 05:31:07 +00007307 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
7308 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00007309 Callee.get(),
7310 First.get(),
7311 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007312}
Mike Stump11289f42009-09-09 15:08:12 +00007313
Douglas Gregora16548e2009-08-11 05:31:07 +00007314template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007315ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007316TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
7317 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007318}
Mike Stump11289f42009-09-09 15:08:12 +00007319
Douglas Gregora16548e2009-08-11 05:31:07 +00007320template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007321ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +00007322TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
7323 // Transform the callee.
7324 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
7325 if (Callee.isInvalid())
7326 return ExprError();
7327
7328 // Transform exec config.
7329 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
7330 if (EC.isInvalid())
7331 return ExprError();
7332
7333 // Transform arguments.
7334 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007335 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00007336 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00007337 &ArgChanged))
7338 return ExprError();
7339
7340 if (!getDerived().AlwaysRebuild() &&
7341 Callee.get() == E->getCallee() &&
7342 !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007343 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbourne41f85462011-02-09 21:07:24 +00007344
7345 // FIXME: Wrong source location information for the '('.
7346 SourceLocation FakeLParenLoc
7347 = ((Expr *)Callee.get())->getSourceRange().getBegin();
7348 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007349 Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00007350 E->getRParenLoc(), EC.get());
7351}
7352
7353template<typename Derived>
7354ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007355TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007356 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7357 if (!Type)
7358 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007359
John McCalldadc5752010-08-24 06:29:42 +00007360 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00007361 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007362 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007363 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007364
Douglas Gregora16548e2009-08-11 05:31:07 +00007365 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007366 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007367 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00007368 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007369 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00007370 E->getStmtClass(),
Fariborz Jahanianf0738712013-02-22 22:02:53 +00007371 E->getAngleBrackets().getBegin(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007372 Type,
Fariborz Jahanianf0738712013-02-22 22:02:53 +00007373 E->getAngleBrackets().getEnd(),
7374 // FIXME. this should be '(' location
7375 E->getAngleBrackets().getEnd(),
John McCallb268a282010-08-23 23:25:46 +00007376 SubExpr.get(),
Abramo Bagnara9fb43862012-10-15 21:08:58 +00007377 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007378}
Mike Stump11289f42009-09-09 15:08:12 +00007379
Douglas Gregora16548e2009-08-11 05:31:07 +00007380template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007381ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007382TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
7383 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007384}
Mike Stump11289f42009-09-09 15:08:12 +00007385
7386template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007387ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007388TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
7389 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00007390}
7391
Douglas Gregora16548e2009-08-11 05:31:07 +00007392template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007393ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007394TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007395 CXXReinterpretCastExpr *E) {
7396 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007397}
Mike Stump11289f42009-09-09 15:08:12 +00007398
Douglas Gregora16548e2009-08-11 05:31:07 +00007399template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007400ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007401TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
7402 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007403}
Mike Stump11289f42009-09-09 15:08:12 +00007404
Douglas Gregora16548e2009-08-11 05:31:07 +00007405template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007406ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007407TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007408 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007409 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7410 if (!Type)
7411 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007412
John McCalldadc5752010-08-24 06:29:42 +00007413 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00007414 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007415 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007416 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007417
Douglas Gregora16548e2009-08-11 05:31:07 +00007418 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007419 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007420 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00007421 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007422
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007423 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Eli Friedman89fe0d52013-08-15 22:02:56 +00007424 E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007425 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007426 E->getRParenLoc());
7427}
Mike Stump11289f42009-09-09 15:08:12 +00007428
Douglas Gregora16548e2009-08-11 05:31:07 +00007429template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007430ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007431TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007432 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00007433 TypeSourceInfo *TInfo
7434 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7435 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007436 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007437
Douglas Gregora16548e2009-08-11 05:31:07 +00007438 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00007439 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00007440 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007441
Douglas Gregor9da64192010-04-26 22:37:10 +00007442 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7443 E->getLocStart(),
7444 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00007445 E->getLocEnd());
7446 }
Mike Stump11289f42009-09-09 15:08:12 +00007447
Eli Friedman456f0182012-01-20 01:26:23 +00007448 // We don't know whether the subexpression is potentially evaluated until
7449 // after we perform semantic analysis. We speculatively assume it is
7450 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregora16548e2009-08-11 05:31:07 +00007451 // potentially evaluated.
Eli Friedman15681d62012-09-26 04:34:21 +00007452 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
7453 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00007454
John McCalldadc5752010-08-24 06:29:42 +00007455 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00007456 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007457 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007458
Douglas Gregora16548e2009-08-11 05:31:07 +00007459 if (!getDerived().AlwaysRebuild() &&
7460 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00007461 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007462
Douglas Gregor9da64192010-04-26 22:37:10 +00007463 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7464 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00007465 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007466 E->getLocEnd());
7467}
7468
7469template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007470ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00007471TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
7472 if (E->isTypeOperand()) {
7473 TypeSourceInfo *TInfo
7474 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7475 if (!TInfo)
7476 return ExprError();
7477
7478 if (!getDerived().AlwaysRebuild() &&
7479 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00007480 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00007481
Douglas Gregor69735112011-03-06 17:40:41 +00007482 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet9f4f2072010-09-08 12:20:18 +00007483 E->getLocStart(),
7484 TInfo,
7485 E->getLocEnd());
7486 }
7487
Francois Pichet9f4f2072010-09-08 12:20:18 +00007488 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7489
7490 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
7491 if (SubExpr.isInvalid())
7492 return ExprError();
7493
7494 if (!getDerived().AlwaysRebuild() &&
7495 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00007496 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00007497
7498 return getDerived().RebuildCXXUuidofExpr(E->getType(),
7499 E->getLocStart(),
7500 SubExpr.get(),
7501 E->getLocEnd());
7502}
7503
7504template<typename Derived>
7505ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007506TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *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
Douglas Gregora16548e2009-08-11 05:31:07 +00007512TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007513 CXXNullPtrLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007514 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007515}
Mike Stump11289f42009-09-09 15:08:12 +00007516
Douglas Gregora16548e2009-08-11 05:31:07 +00007517template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007518ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007519TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Richard Smithc3d2ebb2013-06-07 02:33:37 +00007520 QualType T = getSema().getCurrentThisType();
Mike Stump11289f42009-09-09 15:08:12 +00007521
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00007522 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
7523 // Make sure that we capture 'this'.
7524 getSema().CheckCXXThisCapture(E->getLocStart());
John McCallc3007a22010-10-26 07:05:15 +00007525 return SemaRef.Owned(E);
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00007526 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007527
Douglas Gregorb15af892010-01-07 23:12:05 +00007528 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00007529}
Mike Stump11289f42009-09-09 15:08:12 +00007530
Douglas Gregora16548e2009-08-11 05:31:07 +00007531template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007532ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007533TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007534 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007535 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007536 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007537
Douglas Gregora16548e2009-08-11 05:31:07 +00007538 if (!getDerived().AlwaysRebuild() &&
7539 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00007540 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007541
Douglas Gregor53e191ed2011-07-06 22:04:06 +00007542 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
7543 E->isThrownVariableInScope());
Douglas Gregora16548e2009-08-11 05:31:07 +00007544}
Mike Stump11289f42009-09-09 15:08:12 +00007545
Douglas Gregora16548e2009-08-11 05:31:07 +00007546template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007547ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007548TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00007549 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007550 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
7551 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007552 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00007553 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007554
Chandler Carruth794da4c2010-02-08 06:42:49 +00007555 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007556 Param == E->getParam())
John McCallc3007a22010-10-26 07:05:15 +00007557 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007558
Douglas Gregor033f6752009-12-23 23:03:06 +00007559 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00007560}
Mike Stump11289f42009-09-09 15:08:12 +00007561
Douglas Gregora16548e2009-08-11 05:31:07 +00007562template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007563ExprResult
Richard Smith852c9db2013-04-20 22:23:05 +00007564TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
7565 FieldDecl *Field
7566 = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(),
7567 E->getField()));
7568 if (!Field)
7569 return ExprError();
7570
7571 if (!getDerived().AlwaysRebuild() && Field == E->getField())
7572 return SemaRef.Owned(E);
7573
7574 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
7575}
7576
7577template<typename Derived>
7578ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00007579TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
7580 CXXScalarValueInitExpr *E) {
7581 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7582 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007583 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007584
Douglas Gregora16548e2009-08-11 05:31:07 +00007585 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00007586 T == E->getTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00007587 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007588
Chad Rosier1dcde962012-08-08 18:46:20 +00007589 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregor2b88c112010-09-08 00:15:04 +00007590 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00007591 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007592}
Mike Stump11289f42009-09-09 15:08:12 +00007593
Douglas Gregora16548e2009-08-11 05:31:07 +00007594template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007595ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007596TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007597 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00007598 TypeSourceInfo *AllocTypeInfo
7599 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
7600 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007601 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007602
Douglas Gregora16548e2009-08-11 05:31:07 +00007603 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00007604 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00007605 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007606 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007607
Douglas Gregora16548e2009-08-11 05:31:07 +00007608 // Transform the placement arguments (if any).
7609 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007610 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier1dcde962012-08-08 18:46:20 +00007611 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregora3efea12011-01-03 19:04:46 +00007612 E->getNumPlacementArgs(), true,
7613 PlacementArgs, &ArgumentChanged))
Sebastian Redl6047f072012-02-16 12:22:20 +00007614 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007615
Sebastian Redl6047f072012-02-16 12:22:20 +00007616 // Transform the initializer (if any).
7617 Expr *OldInit = E->getInitializer();
7618 ExprResult NewInit;
7619 if (OldInit)
7620 NewInit = getDerived().TransformExpr(OldInit);
7621 if (NewInit.isInvalid())
7622 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007623
Sebastian Redl6047f072012-02-16 12:22:20 +00007624 // Transform new operator and delete operator.
Douglas Gregord2d9da02010-02-26 00:38:10 +00007625 FunctionDecl *OperatorNew = 0;
7626 if (E->getOperatorNew()) {
7627 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007628 getDerived().TransformDecl(E->getLocStart(),
7629 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00007630 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00007631 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00007632 }
7633
7634 FunctionDecl *OperatorDelete = 0;
7635 if (E->getOperatorDelete()) {
7636 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007637 getDerived().TransformDecl(E->getLocStart(),
7638 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00007639 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00007640 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00007641 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007642
Douglas Gregora16548e2009-08-11 05:31:07 +00007643 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00007644 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007645 ArraySize.get() == E->getArraySize() &&
Sebastian Redl6047f072012-02-16 12:22:20 +00007646 NewInit.get() == OldInit &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00007647 OperatorNew == E->getOperatorNew() &&
7648 OperatorDelete == E->getOperatorDelete() &&
7649 !ArgumentChanged) {
7650 // Mark any declarations we need as referenced.
7651 // FIXME: instantiation-specific.
Douglas Gregord2d9da02010-02-26 00:38:10 +00007652 if (OperatorNew)
Eli Friedmanfa0df832012-02-02 03:46:19 +00007653 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregord2d9da02010-02-26 00:38:10 +00007654 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00007655 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00007656
Sebastian Redl6047f072012-02-16 12:22:20 +00007657 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor72912fb2011-07-26 15:11:03 +00007658 QualType ElementType
7659 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
7660 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
7661 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
7662 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedmanfa0df832012-02-02 03:46:19 +00007663 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor72912fb2011-07-26 15:11:03 +00007664 }
7665 }
7666 }
Sebastian Redl6047f072012-02-16 12:22:20 +00007667
John McCallc3007a22010-10-26 07:05:15 +00007668 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00007669 }
Mike Stump11289f42009-09-09 15:08:12 +00007670
Douglas Gregor0744ef62010-09-07 21:49:58 +00007671 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00007672 if (!ArraySize.get()) {
7673 // If no array size was specified, but the new expression was
7674 // instantiated with an array type (e.g., "new T" where T is
7675 // instantiated with "int[4]"), extract the outer bound from the
7676 // array type as our array size. We do this with constant and
7677 // dependently-sized array types.
7678 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
7679 if (!ArrayT) {
7680 // Do nothing
7681 } else if (const ConstantArrayType *ConsArrayT
7682 = dyn_cast<ConstantArrayType>(ArrayT)) {
Chad Rosier1dcde962012-08-08 18:46:20 +00007683 ArraySize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00007684 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
Chad Rosier1dcde962012-08-08 18:46:20 +00007685 ConsArrayT->getSize(),
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00007686 SemaRef.Context.getSizeType(),
7687 /*FIXME:*/E->getLocStart()));
Douglas Gregor2e9c7952009-12-22 17:13:37 +00007688 AllocType = ConsArrayT->getElementType();
7689 } else if (const DependentSizedArrayType *DepArrayT
7690 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
7691 if (DepArrayT->getSizeExpr()) {
John McCallc3007a22010-10-26 07:05:15 +00007692 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00007693 AllocType = DepArrayT->getElementType();
7694 }
7695 }
7696 }
Sebastian Redl6047f072012-02-16 12:22:20 +00007697
Douglas Gregora16548e2009-08-11 05:31:07 +00007698 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
7699 E->isGlobalNew(),
7700 /*FIXME:*/E->getLocStart(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007701 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00007702 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00007703 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007704 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00007705 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00007706 ArraySize.get(),
Sebastian Redl6047f072012-02-16 12:22:20 +00007707 E->getDirectInitRange(),
7708 NewInit.take());
Douglas Gregora16548e2009-08-11 05:31:07 +00007709}
Mike Stump11289f42009-09-09 15:08:12 +00007710
Douglas Gregora16548e2009-08-11 05:31:07 +00007711template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007712ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007713TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007714 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00007715 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007716 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007717
Douglas Gregord2d9da02010-02-26 00:38:10 +00007718 // Transform the delete operator, if known.
7719 FunctionDecl *OperatorDelete = 0;
7720 if (E->getOperatorDelete()) {
7721 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007722 getDerived().TransformDecl(E->getLocStart(),
7723 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00007724 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00007725 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00007726 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007727
Douglas Gregora16548e2009-08-11 05:31:07 +00007728 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00007729 Operand.get() == E->getArgument() &&
7730 OperatorDelete == E->getOperatorDelete()) {
7731 // Mark any declarations we need as referenced.
7732 // FIXME: instantiation-specific.
7733 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00007734 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00007735
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00007736 if (!E->getArgument()->isTypeDependent()) {
7737 QualType Destroyed = SemaRef.Context.getBaseElementType(
7738 E->getDestroyedType());
7739 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
7740 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +00007741 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedmanfa0df832012-02-02 03:46:19 +00007742 SemaRef.LookupDestructor(Record));
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00007743 }
7744 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007745
John McCallc3007a22010-10-26 07:05:15 +00007746 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00007747 }
Mike Stump11289f42009-09-09 15:08:12 +00007748
Douglas Gregora16548e2009-08-11 05:31:07 +00007749 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
7750 E->isGlobalDelete(),
7751 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00007752 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007753}
Mike Stump11289f42009-09-09 15:08:12 +00007754
Douglas Gregora16548e2009-08-11 05:31:07 +00007755template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007756ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00007757TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007758 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007759 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00007760 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007761 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007762
John McCallba7bf592010-08-24 05:47:05 +00007763 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00007764 bool MayBePseudoDestructor = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00007765 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00007766 E->getOperatorLoc(),
7767 E->isArrow()? tok::arrow : tok::period,
7768 ObjectTypePtr,
7769 MayBePseudoDestructor);
7770 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007771 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007772
John McCallba7bf592010-08-24 05:47:05 +00007773 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +00007774 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
7775 if (QualifierLoc) {
7776 QualifierLoc
7777 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
7778 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +00007779 return ExprError();
7780 }
Douglas Gregora6ce6082011-02-25 18:19:59 +00007781 CXXScopeSpec SS;
7782 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00007783
Douglas Gregor678f90d2010-02-25 01:56:36 +00007784 PseudoDestructorTypeStorage Destroyed;
7785 if (E->getDestroyedTypeInfo()) {
7786 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00007787 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregor579c15f2011-03-02 18:32:08 +00007788 ObjectType, 0, SS);
Douglas Gregor678f90d2010-02-25 01:56:36 +00007789 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007790 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00007791 Destroyed = DestroyedTypeInfo;
Douglas Gregorf39a8dd2011-11-09 02:19:47 +00007792 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregor678f90d2010-02-25 01:56:36 +00007793 // We aren't likely to be able to resolve the identifier down to a type
7794 // now anyway, so just retain the identifier.
7795 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
7796 E->getDestroyedTypeLoc());
7797 } else {
7798 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +00007799 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00007800 *E->getDestroyedTypeIdentifier(),
7801 E->getDestroyedTypeLoc(),
7802 /*Scope=*/0,
7803 SS, ObjectTypePtr,
7804 false);
7805 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007806 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007807
Douglas Gregor678f90d2010-02-25 01:56:36 +00007808 Destroyed
7809 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
7810 E->getDestroyedTypeLoc());
7811 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007812
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007813 TypeSourceInfo *ScopeTypeInfo = 0;
7814 if (E->getScopeTypeInfo()) {
Douglas Gregora88c55b2013-03-08 21:25:01 +00007815 CXXScopeSpec EmptySS;
7816 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
7817 E->getScopeTypeInfo(), ObjectType, 0, EmptySS);
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007818 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007819 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00007820 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007821
John McCallb268a282010-08-23 23:25:46 +00007822 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00007823 E->getOperatorLoc(),
7824 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +00007825 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007826 ScopeTypeInfo,
7827 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00007828 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00007829 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00007830}
Mike Stump11289f42009-09-09 15:08:12 +00007831
Douglas Gregorad8a3362009-09-04 17:36:40 +00007832template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007833ExprResult
John McCalld14a8642009-11-21 08:51:07 +00007834TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007835 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00007836 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
7837 Sema::LookupOrdinaryName);
7838
7839 // Transform all the decls.
7840 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
7841 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007842 NamedDecl *InstD = static_cast<NamedDecl*>(
7843 getDerived().TransformDecl(Old->getNameLoc(),
7844 *I));
John McCall84d87672009-12-10 09:41:52 +00007845 if (!InstD) {
7846 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7847 // This can happen because of dependent hiding.
7848 if (isa<UsingShadowDecl>(*I))
7849 continue;
Serge Pavlov82605302013-09-04 04:50:29 +00007850 else {
7851 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00007852 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00007853 }
John McCall84d87672009-12-10 09:41:52 +00007854 }
John McCalle66edc12009-11-24 19:00:30 +00007855
7856 // Expand using declarations.
7857 if (isa<UsingDecl>(InstD)) {
7858 UsingDecl *UD = cast<UsingDecl>(InstD);
7859 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7860 E = UD->shadow_end(); I != E; ++I)
7861 R.addDecl(*I);
7862 continue;
7863 }
7864
7865 R.addDecl(InstD);
7866 }
7867
7868 // Resolve a kind, but don't do any further analysis. If it's
7869 // ambiguous, the callee needs to deal with it.
7870 R.resolveKind();
7871
7872 // Rebuild the nested-name qualifier, if present.
7873 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00007874 if (Old->getQualifierLoc()) {
7875 NestedNameSpecifierLoc QualifierLoc
7876 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7877 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007878 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007879
Douglas Gregor0da1d432011-02-28 20:01:57 +00007880 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00007881 }
7882
Douglas Gregor9262f472010-04-27 18:19:34 +00007883 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00007884 CXXRecordDecl *NamingClass
7885 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
7886 Old->getNameLoc(),
7887 Old->getNamingClass()));
Serge Pavlov82605302013-09-04 04:50:29 +00007888 if (!NamingClass) {
7889 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00007890 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00007891 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007892
Douglas Gregorda7be082010-04-27 16:10:10 +00007893 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00007894 }
7895
Abramo Bagnara7945c982012-01-27 09:46:47 +00007896 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
7897
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00007898 // If we have neither explicit template arguments, nor the template keyword,
7899 // it's a normal declaration name.
7900 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
John McCalle66edc12009-11-24 19:00:30 +00007901 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
7902
7903 // If we have template arguments, rebuild them, then rebuild the
7904 // templateid expression.
7905 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola3dd531d2012-08-28 04:13:54 +00007906 if (Old->hasExplicitTemplateArgs() &&
7907 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregor62e06f22010-12-20 17:31:10 +00007908 Old->getNumTemplateArgs(),
Serge Pavlov82605302013-09-04 04:50:29 +00007909 TransArgs)) {
7910 R.clear();
Douglas Gregor62e06f22010-12-20 17:31:10 +00007911 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00007912 }
John McCalle66edc12009-11-24 19:00:30 +00007913
Abramo Bagnara7945c982012-01-27 09:46:47 +00007914 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00007915 Old->requiresADL(), &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00007916}
Mike Stump11289f42009-09-09 15:08:12 +00007917
Douglas Gregora16548e2009-08-11 05:31:07 +00007918template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007919ExprResult
Douglas Gregor29c42f22012-02-24 07:38:34 +00007920TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
7921 bool ArgChanged = false;
Dmitri Gribenkof8579502013-01-12 19:30:44 +00007922 SmallVector<TypeSourceInfo *, 4> Args;
Douglas Gregor29c42f22012-02-24 07:38:34 +00007923 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
7924 TypeSourceInfo *From = E->getArg(I);
7925 TypeLoc FromTL = From->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00007926 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
Douglas Gregor29c42f22012-02-24 07:38:34 +00007927 TypeLocBuilder TLB;
7928 TLB.reserve(FromTL.getFullDataSize());
7929 QualType To = getDerived().TransformType(TLB, FromTL);
7930 if (To.isNull())
7931 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007932
Douglas Gregor29c42f22012-02-24 07:38:34 +00007933 if (To == From->getType())
7934 Args.push_back(From);
7935 else {
7936 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7937 ArgChanged = true;
7938 }
7939 continue;
7940 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007941
Douglas Gregor29c42f22012-02-24 07:38:34 +00007942 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00007943
Douglas Gregor29c42f22012-02-24 07:38:34 +00007944 // We have a pack expansion. Instantiate it.
David Blaikie6adc78e2013-02-18 22:06:02 +00007945 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
Douglas Gregor29c42f22012-02-24 07:38:34 +00007946 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
7947 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
7948 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00007949
Douglas Gregor29c42f22012-02-24 07:38:34 +00007950 // Determine whether the set of unexpanded parameter packs can and should
7951 // be expanded.
7952 bool Expand = true;
7953 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00007954 Optional<unsigned> OrigNumExpansions =
7955 ExpansionTL.getTypePtr()->getNumExpansions();
7956 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor29c42f22012-02-24 07:38:34 +00007957 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
7958 PatternTL.getSourceRange(),
7959 Unexpanded,
7960 Expand, RetainExpansion,
7961 NumExpansions))
7962 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007963
Douglas Gregor29c42f22012-02-24 07:38:34 +00007964 if (!Expand) {
7965 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00007966 // transformation on the pack expansion, producing another pack
Douglas Gregor29c42f22012-02-24 07:38:34 +00007967 // expansion.
7968 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier1dcde962012-08-08 18:46:20 +00007969
Douglas Gregor29c42f22012-02-24 07:38:34 +00007970 TypeLocBuilder TLB;
7971 TLB.reserve(From->getTypeLoc().getFullDataSize());
7972
7973 QualType To = getDerived().TransformType(TLB, PatternTL);
7974 if (To.isNull())
7975 return ExprError();
7976
Chad Rosier1dcde962012-08-08 18:46:20 +00007977 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00007978 PatternTL.getSourceRange(),
7979 ExpansionTL.getEllipsisLoc(),
7980 NumExpansions);
7981 if (To.isNull())
7982 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007983
Douglas Gregor29c42f22012-02-24 07:38:34 +00007984 PackExpansionTypeLoc ToExpansionTL
7985 = TLB.push<PackExpansionTypeLoc>(To);
7986 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7987 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7988 continue;
7989 }
7990
7991 // Expand the pack expansion by substituting for each argument in the
7992 // pack(s).
7993 for (unsigned I = 0; I != *NumExpansions; ++I) {
7994 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
7995 TypeLocBuilder TLB;
7996 TLB.reserve(PatternTL.getFullDataSize());
7997 QualType To = getDerived().TransformType(TLB, PatternTL);
7998 if (To.isNull())
7999 return ExprError();
8000
Eli Friedman5e05c4a2013-07-19 21:49:32 +00008001 if (To->containsUnexpandedParameterPack()) {
8002 To = getDerived().RebuildPackExpansionType(To,
8003 PatternTL.getSourceRange(),
8004 ExpansionTL.getEllipsisLoc(),
8005 NumExpansions);
8006 if (To.isNull())
8007 return ExprError();
8008
8009 PackExpansionTypeLoc ToExpansionTL
8010 = TLB.push<PackExpansionTypeLoc>(To);
8011 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8012 }
8013
Douglas Gregor29c42f22012-02-24 07:38:34 +00008014 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8015 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008016
Douglas Gregor29c42f22012-02-24 07:38:34 +00008017 if (!RetainExpansion)
8018 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00008019
Douglas Gregor29c42f22012-02-24 07:38:34 +00008020 // If we're supposed to retain a pack expansion, do so by temporarily
8021 // forgetting the partially-substituted parameter pack.
8022 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
8023
8024 TypeLocBuilder TLB;
8025 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00008026
Douglas Gregor29c42f22012-02-24 07:38:34 +00008027 QualType To = getDerived().TransformType(TLB, PatternTL);
8028 if (To.isNull())
8029 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008030
8031 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00008032 PatternTL.getSourceRange(),
8033 ExpansionTL.getEllipsisLoc(),
8034 NumExpansions);
8035 if (To.isNull())
8036 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008037
Douglas Gregor29c42f22012-02-24 07:38:34 +00008038 PackExpansionTypeLoc ToExpansionTL
8039 = TLB.push<PackExpansionTypeLoc>(To);
8040 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8041 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8042 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008043
Douglas Gregor29c42f22012-02-24 07:38:34 +00008044 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8045 return SemaRef.Owned(E);
8046
8047 return getDerived().RebuildTypeTrait(E->getTrait(),
8048 E->getLocStart(),
8049 Args,
8050 E->getLocEnd());
8051}
8052
8053template<typename Derived>
8054ExprResult
John Wiegley6242b6a2011-04-28 00:16:57 +00008055TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
8056 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
8057 if (!T)
8058 return ExprError();
8059
8060 if (!getDerived().AlwaysRebuild() &&
8061 T == E->getQueriedTypeSourceInfo())
8062 return SemaRef.Owned(E);
8063
8064 ExprResult SubExpr;
8065 {
8066 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8067 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
8068 if (SubExpr.isInvalid())
8069 return ExprError();
8070
8071 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
8072 return SemaRef.Owned(E);
8073 }
8074
8075 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
8076 E->getLocStart(),
8077 T,
8078 SubExpr.get(),
8079 E->getLocEnd());
8080}
8081
8082template<typename Derived>
8083ExprResult
John Wiegleyf9f65842011-04-25 06:54:41 +00008084TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
8085 ExprResult SubExpr;
8086 {
8087 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8088 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
8089 if (SubExpr.isInvalid())
8090 return ExprError();
8091
8092 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
8093 return SemaRef.Owned(E);
8094 }
8095
8096 return getDerived().RebuildExpressionTrait(
8097 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
8098}
8099
8100template<typename Derived>
8101ExprResult
John McCall8cd78132009-11-19 22:55:06 +00008102TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008103 DependentScopeDeclRefExpr *E) {
Richard Smithdb2630f2012-10-21 03:28:35 +00008104 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand*/false);
8105}
8106
8107template<typename Derived>
8108ExprResult
8109TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
8110 DependentScopeDeclRefExpr *E,
8111 bool IsAddressOfOperand) {
Reid Kleckner916ac4d2013-10-15 18:38:02 +00008112 assert(E->getQualifierLoc());
Douglas Gregor3a43fd62011-02-25 20:49:16 +00008113 NestedNameSpecifierLoc QualifierLoc
8114 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
8115 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008116 return ExprError();
Abramo Bagnara7945c982012-01-27 09:46:47 +00008117 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00008118
John McCall31f82722010-11-12 08:19:04 +00008119 // TODO: If this is a conversion-function-id, verify that the
8120 // destination type name (if present) resolves the same way after
8121 // instantiation as it did in the local scope.
8122
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008123 DeclarationNameInfo NameInfo
8124 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
8125 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00008126 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008127
John McCalle66edc12009-11-24 19:00:30 +00008128 if (!E->hasExplicitTemplateArgs()) {
8129 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3a43fd62011-02-25 20:49:16 +00008130 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008131 // Note: it is sufficient to compare the Name component of NameInfo:
8132 // if name has not changed, DNLoc has not changed either.
8133 NameInfo.getName() == E->getDeclName())
John McCallc3007a22010-10-26 07:05:15 +00008134 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00008135
Douglas Gregor3a43fd62011-02-25 20:49:16 +00008136 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008137 TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008138 NameInfo,
Richard Smithdb2630f2012-10-21 03:28:35 +00008139 /*TemplateArgs*/ 0,
8140 IsAddressOfOperand);
Douglas Gregord019ff62009-10-22 17:20:55 +00008141 }
John McCall6b51f282009-11-23 01:53:49 +00008142
8143 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008144 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8145 E->getNumTemplateArgs(),
8146 TransArgs))
8147 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008148
Douglas Gregor3a43fd62011-02-25 20:49:16 +00008149 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008150 TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008151 NameInfo,
Richard Smithdb2630f2012-10-21 03:28:35 +00008152 &TransArgs,
8153 IsAddressOfOperand);
Douglas Gregora16548e2009-08-11 05:31:07 +00008154}
8155
8156template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008157ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008158TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithd59b8322012-12-19 01:39:02 +00008159 // CXXConstructExprs other than for list-initialization and
8160 // CXXTemporaryObjectExpr are always implicit, so when we have
8161 // a 1-argument construction we just transform that argument.
Richard Smithdd2ca572012-11-26 08:32:48 +00008162 if ((E->getNumArgs() == 1 ||
8163 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithd59b8322012-12-19 01:39:02 +00008164 (!getDerived().DropCallArgument(E->getArg(0))) &&
8165 !E->isListInitialization())
Douglas Gregordb56b912010-02-03 03:01:57 +00008166 return getDerived().TransformExpr(E->getArg(0));
8167
Douglas Gregora16548e2009-08-11 05:31:07 +00008168 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
8169
8170 QualType T = getDerived().TransformType(E->getType());
8171 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00008172 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008173
8174 CXXConstructorDecl *Constructor
8175 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008176 getDerived().TransformDecl(E->getLocStart(),
8177 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008178 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00008179 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008180
Douglas Gregora16548e2009-08-11 05:31:07 +00008181 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008182 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00008183 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00008184 &ArgumentChanged))
8185 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008186
Douglas Gregora16548e2009-08-11 05:31:07 +00008187 if (!getDerived().AlwaysRebuild() &&
8188 T == E->getType() &&
8189 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00008190 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00008191 // Mark the constructor as referenced.
8192 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00008193 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00008194 return SemaRef.Owned(E);
Douglas Gregorde550352010-02-26 00:01:57 +00008195 }
Mike Stump11289f42009-09-09 15:08:12 +00008196
Douglas Gregordb121ba2009-12-14 16:27:04 +00008197 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
8198 Constructor, E->isElidable(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008199 Args,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00008200 E->hadMultipleCandidates(),
Richard Smithd59b8322012-12-19 01:39:02 +00008201 E->isListInitialization(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00008202 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00008203 E->getConstructionKind(),
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00008204 E->getParenOrBraceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00008205}
Mike Stump11289f42009-09-09 15:08:12 +00008206
Douglas Gregora16548e2009-08-11 05:31:07 +00008207/// \brief Transform a C++ temporary-binding expression.
8208///
Douglas Gregor363b1512009-12-24 18:51:59 +00008209/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
8210/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00008211template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008212ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008213TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00008214 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008215}
Mike Stump11289f42009-09-09 15:08:12 +00008216
John McCall5d413782010-12-06 08:20:24 +00008217/// \brief Transform a C++ expression that contains cleanups that should
8218/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +00008219///
John McCall5d413782010-12-06 08:20:24 +00008220/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +00008221/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00008222template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008223ExprResult
John McCall5d413782010-12-06 08:20:24 +00008224TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00008225 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008226}
Mike Stump11289f42009-09-09 15:08:12 +00008227
Douglas Gregora16548e2009-08-11 05:31:07 +00008228template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008229ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008230TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00008231 CXXTemporaryObjectExpr *E) {
8232 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8233 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00008234 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008235
Douglas Gregora16548e2009-08-11 05:31:07 +00008236 CXXConstructorDecl *Constructor
8237 = cast_or_null<CXXConstructorDecl>(
Chad Rosier1dcde962012-08-08 18:46:20 +00008238 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008239 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008240 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00008241 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008242
Douglas Gregora16548e2009-08-11 05:31:07 +00008243 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008244 SmallVector<Expr*, 8> Args;
Douglas Gregora16548e2009-08-11 05:31:07 +00008245 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +00008246 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00008247 &ArgumentChanged))
8248 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008249
Douglas Gregora16548e2009-08-11 05:31:07 +00008250 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00008251 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008252 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00008253 !ArgumentChanged) {
8254 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00008255 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00008256 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00008257 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008258
Richard Smithd59b8322012-12-19 01:39:02 +00008259 // FIXME: Pass in E->isListInitialization().
Douglas Gregor2b88c112010-09-08 00:15:04 +00008260 return getDerived().RebuildCXXTemporaryObjectExpr(T,
8261 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008262 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00008263 E->getLocEnd());
8264}
Mike Stump11289f42009-09-09 15:08:12 +00008265
Douglas Gregora16548e2009-08-11 05:31:07 +00008266template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008267ExprResult
Douglas Gregore31e6062012-02-07 10:09:13 +00008268TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008269
8270 // Transform any init-capture expressions before entering the scope of the
8271 // lambda body, because they are not semantically within that scope.
8272 SmallVector<InitCaptureInfoTy, 8> InitCaptureExprsAndTypes;
8273 InitCaptureExprsAndTypes.resize(E->explicit_capture_end() -
8274 E->explicit_capture_begin());
8275
8276 for (LambdaExpr::capture_iterator C = E->capture_begin(),
8277 CEnd = E->capture_end();
8278 C != CEnd; ++C) {
8279 if (!C->isInitCapture())
8280 continue;
8281 EnterExpressionEvaluationContext EEEC(getSema(),
8282 Sema::PotentiallyEvaluated);
8283 ExprResult NewExprInitResult = getDerived().TransformInitializer(
8284 C->getCapturedVar()->getInit(),
8285 C->getCapturedVar()->getInitStyle() == VarDecl::CallInit);
8286
8287 if (NewExprInitResult.isInvalid())
8288 return ExprError();
8289 Expr *NewExprInit = NewExprInitResult.get();
8290
8291 VarDecl *OldVD = C->getCapturedVar();
8292 QualType NewInitCaptureType =
8293 getSema().performLambdaInitCaptureInitialization(C->getLocation(),
8294 OldVD->getType()->isReferenceType(), OldVD->getIdentifier(),
8295 NewExprInit);
8296 NewExprInitResult = NewExprInit;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008297 InitCaptureExprsAndTypes[C - E->capture_begin()] =
8298 std::make_pair(NewExprInitResult, NewInitCaptureType);
8299
8300 }
8301
Faisal Vali524ca282013-11-12 01:40:44 +00008302 LambdaScopeInfo *LSI = getSema().PushLambdaScope();
Faisal Vali2cba1332013-10-23 06:44:28 +00008303 // Transform the template parameters, and add them to the current
8304 // instantiation scope. The null case is handled correctly.
8305 LSI->GLTemplateParameterList = getDerived().TransformTemplateParameterList(
8306 E->getTemplateParameterList());
8307
8308 // Check to see if the TypeSourceInfo of the call operator needs to
8309 // be transformed, and if so do the transformation in the
8310 // CurrentInstantiationScope.
8311
8312 TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo();
8313 FunctionProtoTypeLoc OldCallOpFPTL =
8314 OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>();
8315 TypeSourceInfo *NewCallOpTSI = 0;
8316
8317 const bool CallOpWasAlreadyTransformed =
8318 getDerived().AlreadyTransformed(OldCallOpTSI->getType());
8319
8320 // Use the Old Call Operator's TypeSourceInfo if it is already transformed.
8321 if (CallOpWasAlreadyTransformed)
8322 NewCallOpTSI = OldCallOpTSI;
8323 else {
8324 // Transform the TypeSourceInfo of the Original Lambda's Call Operator.
8325 // The transformation MUST be done in the CurrentInstantiationScope since
8326 // it introduces a mapping of the original to the newly created
8327 // transformed parameters.
8328
8329 TypeLocBuilder NewCallOpTLBuilder;
8330 QualType NewCallOpType = TransformFunctionProtoType(NewCallOpTLBuilder,
8331 OldCallOpFPTL,
8332 0, 0);
8333 NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context,
8334 NewCallOpType);
Faisal Vali2b391ab2013-09-26 19:54:12 +00008335 }
Faisal Vali2cba1332013-10-23 06:44:28 +00008336 // Extract the ParmVarDecls from the NewCallOpTSI and add them to
8337 // the vector below - this will be used to synthesize the
8338 // NewCallOperator. Additionally, add the parameters of the untransformed
8339 // lambda call operator to the CurrentInstantiationScope.
8340 SmallVector<ParmVarDecl *, 4> Params;
8341 {
8342 FunctionProtoTypeLoc NewCallOpFPTL =
8343 NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>();
8344 ParmVarDecl **NewParamDeclArray = NewCallOpFPTL.getParmArray();
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00008345 const unsigned NewNumArgs = NewCallOpFPTL.getNumParams();
Faisal Vali2cba1332013-10-23 06:44:28 +00008346
8347 for (unsigned I = 0; I < NewNumArgs; ++I) {
8348 // If this call operator's type does not require transformation,
8349 // the parameters do not get added to the current instantiation scope,
8350 // - so ADD them! This allows the following to compile when the enclosing
8351 // template is specialized and the entire lambda expression has to be
8352 // transformed.
8353 // template<class T> void foo(T t) {
8354 // auto L = [](auto a) {
8355 // auto M = [](char b) { <-- note: non-generic lambda
8356 // auto N = [](auto c) {
8357 // int x = sizeof(a);
8358 // x = sizeof(b); <-- specifically this line
8359 // x = sizeof(c);
8360 // };
8361 // };
8362 // };
8363 // }
8364 // foo('a')
8365 if (CallOpWasAlreadyTransformed)
8366 getDerived().transformedLocalDecl(NewParamDeclArray[I],
8367 NewParamDeclArray[I]);
8368 // Add to Params array, so these parameters can be used to create
8369 // the newly transformed call operator.
8370 Params.push_back(NewParamDeclArray[I]);
8371 }
8372 }
8373
8374 if (!NewCallOpTSI)
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008375 return ExprError();
8376
Eli Friedmand564afb2012-09-19 01:18:11 +00008377 // Create the local class that will describe the lambda.
8378 CXXRecordDecl *Class
8379 = getSema().createLambdaClosureType(E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +00008380 NewCallOpTSI,
Faisal Valic1a6dc42013-10-23 16:10:50 +00008381 /*KnownDependent=*/false,
8382 E->getCaptureDefault());
8383
Eli Friedmand564afb2012-09-19 01:18:11 +00008384 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
8385
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008386 // Build the call operator.
Faisal Vali2cba1332013-10-23 06:44:28 +00008387 CXXMethodDecl *NewCallOperator
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008388 = getSema().startLambdaDefinition(Class, E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +00008389 NewCallOpTSI,
Douglas Gregoradb376e2012-02-14 22:28:59 +00008390 E->getCallOperator()->getLocEnd(),
Richard Smith505df232012-07-22 23:45:10 +00008391 Params);
Faisal Vali2cba1332013-10-23 06:44:28 +00008392 LSI->CallOperator = NewCallOperator;
Rafael Espindola4b35f272013-10-04 14:28:51 +00008393
Faisal Vali2cba1332013-10-23 06:44:28 +00008394 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
8395
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008396 return getDerived().TransformLambdaScope(E, NewCallOperator,
8397 InitCaptureExprsAndTypes);
Richard Smith2589b9802012-07-25 03:56:55 +00008398}
8399
8400template<typename Derived>
8401ExprResult
8402TreeTransform<Derived>::TransformLambdaScope(LambdaExpr *E,
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008403 CXXMethodDecl *CallOperator,
8404 ArrayRef<InitCaptureInfoTy> InitCaptureExprsAndTypes) {
Richard Smithba71c082013-05-16 06:20:58 +00008405 bool Invalid = false;
8406
Douglas Gregorb4328232012-02-14 00:00:48 +00008407 // Introduce the context of the call operator.
Richard Smith7ff2bcb2014-01-24 01:54:52 +00008408 Sema::ContextRAII SavedContext(getSema(), CallOperator,
8409 /*NewThisContext*/false);
Douglas Gregorb4328232012-02-14 00:00:48 +00008410
Faisal Vali2b391ab2013-09-26 19:54:12 +00008411 LambdaScopeInfo *const LSI = getSema().getCurLambda();
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008412 // Enter the scope of the lambda.
Faisal Vali2b391ab2013-09-26 19:54:12 +00008413 getSema().buildLambdaScope(LSI, CallOperator, E->getIntroducerRange(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008414 E->getCaptureDefault(),
James Dennettddd36ff2013-08-09 23:08:25 +00008415 E->getCaptureDefaultLoc(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008416 E->hasExplicitParameters(),
8417 E->hasExplicitResultType(),
8418 E->isMutable());
Chad Rosier1dcde962012-08-08 18:46:20 +00008419
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008420 // Transform captures.
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008421 bool FinishedExplicitCaptures = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00008422 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008423 CEnd = E->capture_end();
8424 C != CEnd; ++C) {
8425 // When we hit the first implicit capture, tell Sema that we've finished
8426 // the list of explicit captures.
8427 if (!FinishedExplicitCaptures && C->isImplicit()) {
8428 getSema().finishLambdaExplicitCaptures(LSI);
8429 FinishedExplicitCaptures = true;
8430 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008431
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008432 // Capturing 'this' is trivial.
8433 if (C->capturesThis()) {
8434 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
8435 continue;
8436 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008437
Richard Smithba71c082013-05-16 06:20:58 +00008438 // Rebuild init-captures, including the implied field declaration.
8439 if (C->isInitCapture()) {
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008440
8441 InitCaptureInfoTy InitExprTypePair =
8442 InitCaptureExprsAndTypes[C - E->capture_begin()];
8443 ExprResult Init = InitExprTypePair.first;
8444 QualType InitQualType = InitExprTypePair.second;
8445 if (Init.isInvalid() || InitQualType.isNull()) {
Richard Smithba71c082013-05-16 06:20:58 +00008446 Invalid = true;
8447 continue;
8448 }
Richard Smithbb13c9a2013-09-28 04:02:39 +00008449 VarDecl *OldVD = C->getCapturedVar();
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008450 VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl(
8451 OldVD->getLocation(), InitExprTypePair.second,
8452 OldVD->getIdentifier(), Init.get());
Richard Smithbb13c9a2013-09-28 04:02:39 +00008453 if (!NewVD)
Richard Smithba71c082013-05-16 06:20:58 +00008454 Invalid = true;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008455 else {
Richard Smithbb13c9a2013-09-28 04:02:39 +00008456 getDerived().transformedLocalDecl(OldVD, NewVD);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008457 }
Richard Smithbb13c9a2013-09-28 04:02:39 +00008458 getSema().buildInitCaptureField(LSI, NewVD);
Richard Smithba71c082013-05-16 06:20:58 +00008459 continue;
8460 }
8461
8462 assert(C->capturesVariable() && "unexpected kind of lambda capture");
8463
Douglas Gregor3e308b12012-02-14 19:27:52 +00008464 // Determine the capture kind for Sema.
8465 Sema::TryCaptureKind Kind
8466 = C->isImplicit()? Sema::TryCapture_Implicit
8467 : C->getCaptureKind() == LCK_ByCopy
8468 ? Sema::TryCapture_ExplicitByVal
8469 : Sema::TryCapture_ExplicitByRef;
8470 SourceLocation EllipsisLoc;
8471 if (C->isPackExpansion()) {
8472 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
8473 bool ShouldExpand = false;
8474 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00008475 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +00008476 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
8477 C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +00008478 Unexpanded,
8479 ShouldExpand, RetainExpansion,
Richard Smithba71c082013-05-16 06:20:58 +00008480 NumExpansions)) {
8481 Invalid = true;
8482 continue;
8483 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008484
Douglas Gregor3e308b12012-02-14 19:27:52 +00008485 if (ShouldExpand) {
8486 // The transform has determined that we should perform an expansion;
8487 // transform and capture each of the arguments.
8488 // expansion of the pattern. Do so.
8489 VarDecl *Pack = C->getCapturedVar();
8490 for (unsigned I = 0; I != *NumExpansions; ++I) {
8491 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8492 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +00008493 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +00008494 Pack));
8495 if (!CapturedVar) {
8496 Invalid = true;
8497 continue;
8498 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008499
Douglas Gregor3e308b12012-02-14 19:27:52 +00008500 // Capture the transformed variable.
Chad Rosier1dcde962012-08-08 18:46:20 +00008501 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
8502 }
Douglas Gregor3e308b12012-02-14 19:27:52 +00008503 continue;
8504 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008505
Douglas Gregor3e308b12012-02-14 19:27:52 +00008506 EllipsisLoc = C->getEllipsisLoc();
8507 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008508
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008509 // Transform the captured variable.
8510 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +00008511 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008512 C->getCapturedVar()));
8513 if (!CapturedVar) {
8514 Invalid = true;
8515 continue;
8516 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008517
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008518 // Capture the transformed variable.
Douglas Gregorfdf598e2012-02-18 09:37:24 +00008519 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008520 }
8521 if (!FinishedExplicitCaptures)
8522 getSema().finishLambdaExplicitCaptures(LSI);
8523
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008524
8525 // Enter a new evaluation context to insulate the lambda from any
8526 // cleanups from the enclosing full-expression.
Chad Rosier1dcde962012-08-08 18:46:20 +00008527 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008528
8529 if (Invalid) {
Chad Rosier1dcde962012-08-08 18:46:20 +00008530 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008531 /*IsInstantiation=*/true);
8532 return ExprError();
8533 }
8534
8535 // Instantiate the body of the lambda expression.
Douglas Gregorb4328232012-02-14 00:00:48 +00008536 StmtResult Body = getDerived().TransformStmt(E->getBody());
8537 if (Body.isInvalid()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00008538 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
Douglas Gregorb4328232012-02-14 00:00:48 +00008539 /*IsInstantiation=*/true);
Chad Rosier1dcde962012-08-08 18:46:20 +00008540 return ExprError();
Douglas Gregorb4328232012-02-14 00:00:48 +00008541 }
Douglas Gregor7fcbd902012-02-21 00:37:24 +00008542
Chad Rosier1dcde962012-08-08 18:46:20 +00008543 return getSema().ActOnLambdaExpr(E->getLocStart(), Body.take(),
Douglas Gregorb61e8092012-04-04 17:40:10 +00008544 /*CurScope=*/0, /*IsInstantiation=*/true);
Douglas Gregore31e6062012-02-07 10:09:13 +00008545}
8546
8547template<typename Derived>
8548ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008549TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008550 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00008551 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8552 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00008553 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008554
Douglas Gregora16548e2009-08-11 05:31:07 +00008555 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008556 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +00008557 Args.reserve(E->arg_size());
Chad Rosier1dcde962012-08-08 18:46:20 +00008558 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00008559 &ArgumentChanged))
8560 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008561
Douglas Gregora16548e2009-08-11 05:31:07 +00008562 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00008563 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008564 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00008565 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00008566
Douglas Gregora16548e2009-08-11 05:31:07 +00008567 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +00008568 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +00008569 E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008570 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00008571 E->getRParenLoc());
8572}
Mike Stump11289f42009-09-09 15:08:12 +00008573
Douglas Gregora16548e2009-08-11 05:31:07 +00008574template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008575ExprResult
John McCall8cd78132009-11-19 22:55:06 +00008576TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008577 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008578 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00008579 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00008580 Expr *OldBase;
8581 QualType BaseType;
8582 QualType ObjectType;
8583 if (!E->isImplicitAccess()) {
8584 OldBase = E->getBase();
8585 Base = getDerived().TransformExpr(OldBase);
8586 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008587 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008588
John McCall2d74de92009-12-01 22:10:20 +00008589 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +00008590 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +00008591 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00008592 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00008593 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00008594 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00008595 ObjectTy,
8596 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00008597 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008598 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00008599
John McCallba7bf592010-08-24 05:47:05 +00008600 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +00008601 BaseType = ((Expr*) Base.get())->getType();
8602 } else {
8603 OldBase = 0;
8604 BaseType = getDerived().TransformType(E->getBaseType());
8605 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
8606 }
Mike Stump11289f42009-09-09 15:08:12 +00008607
Douglas Gregora5cb6da2009-10-20 05:58:46 +00008608 // Transform the first part of the nested-name-specifier that qualifies
8609 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00008610 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00008611 = getDerived().TransformFirstQualifierInScope(
Douglas Gregore16af532011-02-28 18:50:33 +00008612 E->getFirstQualifierFoundInScope(),
8613 E->getQualifierLoc().getBeginLoc());
Mike Stump11289f42009-09-09 15:08:12 +00008614
Douglas Gregore16af532011-02-28 18:50:33 +00008615 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00008616 if (E->getQualifier()) {
Douglas Gregore16af532011-02-28 18:50:33 +00008617 QualifierLoc
8618 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
8619 ObjectType,
8620 FirstQualifierInScope);
8621 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008622 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +00008623 }
Mike Stump11289f42009-09-09 15:08:12 +00008624
Abramo Bagnara7945c982012-01-27 09:46:47 +00008625 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
8626
John McCall31f82722010-11-12 08:19:04 +00008627 // TODO: If this is a conversion-function-id, verify that the
8628 // destination type name (if present) resolves the same way after
8629 // instantiation as it did in the local scope.
8630
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008631 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +00008632 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008633 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00008634 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008635
John McCall2d74de92009-12-01 22:10:20 +00008636 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00008637 // This is a reference to a member without an explicitly-specified
8638 // template argument list. Optimize for this common case.
8639 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00008640 Base.get() == OldBase &&
8641 BaseType == E->getBaseType() &&
Douglas Gregore16af532011-02-28 18:50:33 +00008642 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008643 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00008644 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCallc3007a22010-10-26 07:05:15 +00008645 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00008646
John McCallb268a282010-08-23 23:25:46 +00008647 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00008648 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00008649 E->isArrow(),
8650 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00008651 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008652 TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00008653 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008654 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00008655 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00008656 }
8657
John McCall6b51f282009-11-23 01:53:49 +00008658 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008659 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8660 E->getNumTemplateArgs(),
8661 TransArgs))
8662 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008663
John McCallb268a282010-08-23 23:25:46 +00008664 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00008665 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00008666 E->isArrow(),
8667 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00008668 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008669 TemplateKWLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +00008670 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008671 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00008672 &TransArgs);
8673}
8674
8675template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008676ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008677TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00008678 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00008679 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00008680 QualType BaseType;
8681 if (!Old->isImplicitAccess()) {
8682 Base = getDerived().TransformExpr(Old->getBase());
8683 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008684 return ExprError();
Richard Smithcab9a7d2011-10-26 19:06:56 +00008685 Base = getSema().PerformMemberExprBaseConversion(Base.take(),
8686 Old->isArrow());
8687 if (Base.isInvalid())
8688 return ExprError();
8689 BaseType = Base.get()->getType();
John McCall2d74de92009-12-01 22:10:20 +00008690 } else {
8691 BaseType = getDerived().TransformType(Old->getBaseType());
8692 }
John McCall10eae182009-11-30 22:42:35 +00008693
Douglas Gregor0da1d432011-02-28 20:01:57 +00008694 NestedNameSpecifierLoc QualifierLoc;
8695 if (Old->getQualifierLoc()) {
8696 QualifierLoc
8697 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
8698 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008699 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00008700 }
8701
Abramo Bagnara7945c982012-01-27 09:46:47 +00008702 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
8703
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008704 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +00008705 Sema::LookupOrdinaryName);
8706
8707 // Transform all the decls.
8708 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
8709 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008710 NamedDecl *InstD = static_cast<NamedDecl*>(
8711 getDerived().TransformDecl(Old->getMemberLoc(),
8712 *I));
John McCall84d87672009-12-10 09:41:52 +00008713 if (!InstD) {
8714 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
8715 // This can happen because of dependent hiding.
8716 if (isa<UsingShadowDecl>(*I))
8717 continue;
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00008718 else {
8719 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00008720 return ExprError();
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00008721 }
John McCall84d87672009-12-10 09:41:52 +00008722 }
John McCall10eae182009-11-30 22:42:35 +00008723
8724 // Expand using declarations.
8725 if (isa<UsingDecl>(InstD)) {
8726 UsingDecl *UD = cast<UsingDecl>(InstD);
8727 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
8728 E = UD->shadow_end(); I != E; ++I)
8729 R.addDecl(*I);
8730 continue;
8731 }
8732
8733 R.addDecl(InstD);
8734 }
8735
8736 R.resolveKind();
8737
Douglas Gregor9262f472010-04-27 18:19:34 +00008738 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00008739 if (Old->getNamingClass()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00008740 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00008741 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00008742 Old->getMemberLoc(),
8743 Old->getNamingClass()));
8744 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00008745 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008746
Douglas Gregorda7be082010-04-27 16:10:10 +00008747 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00008748 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008749
John McCall10eae182009-11-30 22:42:35 +00008750 TemplateArgumentListInfo TransArgs;
8751 if (Old->hasExplicitTemplateArgs()) {
8752 TransArgs.setLAngleLoc(Old->getLAngleLoc());
8753 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008754 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
8755 Old->getNumTemplateArgs(),
8756 TransArgs))
8757 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00008758 }
John McCall38836f02010-01-15 08:34:02 +00008759
8760 // FIXME: to do this check properly, we will need to preserve the
8761 // first-qualifier-in-scope here, just in case we had a dependent
8762 // base (and therefore couldn't do the check) and a
8763 // nested-name-qualifier (and therefore could do the lookup).
8764 NamedDecl *FirstQualifierInScope = 0;
Chad Rosier1dcde962012-08-08 18:46:20 +00008765
John McCallb268a282010-08-23 23:25:46 +00008766 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00008767 BaseType,
John McCall10eae182009-11-30 22:42:35 +00008768 Old->getOperatorLoc(),
8769 Old->isArrow(),
Douglas Gregor0da1d432011-02-28 20:01:57 +00008770 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008771 TemplateKWLoc,
John McCall38836f02010-01-15 08:34:02 +00008772 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00008773 R,
8774 (Old->hasExplicitTemplateArgs()
8775 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00008776}
8777
8778template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008779ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +00008780TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Alexis Hunt414e3e32011-05-31 19:54:49 +00008781 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00008782 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
8783 if (SubExpr.isInvalid())
8784 return ExprError();
8785
8786 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCallc3007a22010-10-26 07:05:15 +00008787 return SemaRef.Owned(E);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00008788
8789 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
8790}
8791
8792template<typename Derived>
8793ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +00008794TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +00008795 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
8796 if (Pattern.isInvalid())
8797 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008798
Douglas Gregor0f836ea2011-01-13 00:19:55 +00008799 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
8800 return SemaRef.Owned(E);
8801
Douglas Gregorb8840002011-01-14 21:20:45 +00008802 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
8803 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +00008804}
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008805
8806template<typename Derived>
8807ExprResult
8808TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
8809 // If E is not value-dependent, then nothing will change when we transform it.
8810 // Note: This is an instantiation-centric view.
8811 if (!E->isValueDependent())
8812 return SemaRef.Owned(E);
8813
8814 // Note: None of the implementations of TryExpandParameterPacks can ever
8815 // produce a diagnostic when given only a single unexpanded parameter pack,
Chad Rosier1dcde962012-08-08 18:46:20 +00008816 // so
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008817 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
8818 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00008819 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00008820 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +00008821 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikieb9c168a2011-09-22 02:34:54 +00008822 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00008823 ShouldExpand, RetainExpansion,
8824 NumExpansions))
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008825 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008826
Douglas Gregorab96bcf2011-10-10 18:59:29 +00008827 if (RetainExpansion)
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008828 return SemaRef.Owned(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00008829
Douglas Gregorab96bcf2011-10-10 18:59:29 +00008830 NamedDecl *Pack = E->getPack();
8831 if (!ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00008832 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
Douglas Gregorab96bcf2011-10-10 18:59:29 +00008833 Pack));
8834 if (!Pack)
8835 return ExprError();
8836 }
8837
Chad Rosier1dcde962012-08-08 18:46:20 +00008838
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008839 // We now know the length of the parameter pack, so build a new expression
8840 // that stores that length.
Chad Rosier1dcde962012-08-08 18:46:20 +00008841 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
8842 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregorab96bcf2011-10-10 18:59:29 +00008843 NumExpansions);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008844}
8845
Douglas Gregore8e9dd62011-01-03 17:17:50 +00008846template<typename Derived>
8847ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +00008848TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
8849 SubstNonTypeTemplateParmPackExpr *E) {
8850 // Default behavior is to do nothing with this transformation.
8851 return SemaRef.Owned(E);
8852}
8853
8854template<typename Derived>
8855ExprResult
John McCall7c454bb2011-07-15 05:09:51 +00008856TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
8857 SubstNonTypeTemplateParmExpr *E) {
8858 // Default behavior is to do nothing with this transformation.
8859 return SemaRef.Owned(E);
8860}
8861
8862template<typename Derived>
8863ExprResult
Richard Smithb15fe3a2012-09-12 00:56:43 +00008864TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
8865 // Default behavior is to do nothing with this transformation.
8866 return SemaRef.Owned(E);
8867}
8868
8869template<typename Derived>
8870ExprResult
Douglas Gregorfe314812011-06-21 17:03:29 +00008871TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
8872 MaterializeTemporaryExpr *E) {
8873 return getDerived().TransformExpr(E->GetTemporaryExpr());
8874}
Chad Rosier1dcde962012-08-08 18:46:20 +00008875
Douglas Gregorfe314812011-06-21 17:03:29 +00008876template<typename Derived>
8877ExprResult
Richard Smithcc1b96d2013-06-12 22:31:48 +00008878TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
8879 CXXStdInitializerListExpr *E) {
8880 return getDerived().TransformExpr(E->getSubExpr());
8881}
8882
8883template<typename Derived>
8884ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008885TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00008886 return SemaRef.MaybeBindToTemporary(E);
8887}
8888
8889template<typename Derived>
8890ExprResult
8891TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Jordy Rose8986c5992012-03-12 17:53:02 +00008892 return SemaRef.Owned(E);
Ted Kremeneke65b0862012-03-06 20:05:56 +00008893}
8894
8895template<typename Derived>
8896ExprResult
Patrick Beard0caa3942012-04-19 00:25:12 +00008897TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
8898 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
8899 if (SubExpr.isInvalid())
8900 return ExprError();
8901
8902 if (!getDerived().AlwaysRebuild() &&
8903 SubExpr.get() == E->getSubExpr())
8904 return SemaRef.Owned(E);
8905
8906 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremeneke65b0862012-03-06 20:05:56 +00008907}
8908
8909template<typename Derived>
8910ExprResult
8911TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
8912 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +00008913 SmallVector<Expr *, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +00008914 bool ArgChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00008915 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremeneke65b0862012-03-06 20:05:56 +00008916 /*IsCall=*/false, Elements, &ArgChanged))
8917 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008918
Ted Kremeneke65b0862012-03-06 20:05:56 +00008919 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8920 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00008921
Ted Kremeneke65b0862012-03-06 20:05:56 +00008922 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
8923 Elements.data(),
8924 Elements.size());
8925}
8926
8927template<typename Derived>
8928ExprResult
8929TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier1dcde962012-08-08 18:46:20 +00008930 ObjCDictionaryLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00008931 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +00008932 SmallVector<ObjCDictionaryElement, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +00008933 bool ArgChanged = false;
8934 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
8935 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier1dcde962012-08-08 18:46:20 +00008936
Ted Kremeneke65b0862012-03-06 20:05:56 +00008937 if (OrigElement.isPackExpansion()) {
8938 // This key/value element is a pack expansion.
8939 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
8940 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
8941 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
8942 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
8943
8944 // Determine whether the set of unexpanded parameter packs can
8945 // and should be expanded.
8946 bool Expand = true;
8947 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00008948 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
8949 Optional<unsigned> NumExpansions = OrigNumExpansions;
Ted Kremeneke65b0862012-03-06 20:05:56 +00008950 SourceRange PatternRange(OrigElement.Key->getLocStart(),
8951 OrigElement.Value->getLocEnd());
8952 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
8953 PatternRange,
8954 Unexpanded,
8955 Expand, RetainExpansion,
8956 NumExpansions))
8957 return ExprError();
8958
8959 if (!Expand) {
8960 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00008961 // transformation on the pack expansion, producing another pack
Ted Kremeneke65b0862012-03-06 20:05:56 +00008962 // expansion.
8963 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
8964 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8965 if (Key.isInvalid())
8966 return ExprError();
8967
8968 if (Key.get() != OrigElement.Key)
8969 ArgChanged = true;
8970
8971 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8972 if (Value.isInvalid())
8973 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008974
Ted Kremeneke65b0862012-03-06 20:05:56 +00008975 if (Value.get() != OrigElement.Value)
8976 ArgChanged = true;
8977
Chad Rosier1dcde962012-08-08 18:46:20 +00008978 ObjCDictionaryElement Expansion = {
Ted Kremeneke65b0862012-03-06 20:05:56 +00008979 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
8980 };
8981 Elements.push_back(Expansion);
8982 continue;
8983 }
8984
8985 // Record right away that the argument was changed. This needs
8986 // to happen even if the array expands to nothing.
8987 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00008988
Ted Kremeneke65b0862012-03-06 20:05:56 +00008989 // The transform has determined that we should perform an elementwise
8990 // expansion of the pattern. Do so.
8991 for (unsigned I = 0; I != *NumExpansions; ++I) {
8992 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8993 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8994 if (Key.isInvalid())
8995 return ExprError();
8996
8997 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8998 if (Value.isInvalid())
8999 return ExprError();
9000
Chad Rosier1dcde962012-08-08 18:46:20 +00009001 ObjCDictionaryElement Element = {
Ted Kremeneke65b0862012-03-06 20:05:56 +00009002 Key.get(), Value.get(), SourceLocation(), NumExpansions
9003 };
9004
9005 // If any unexpanded parameter packs remain, we still have a
9006 // pack expansion.
9007 if (Key.get()->containsUnexpandedParameterPack() ||
9008 Value.get()->containsUnexpandedParameterPack())
9009 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier1dcde962012-08-08 18:46:20 +00009010
Ted Kremeneke65b0862012-03-06 20:05:56 +00009011 Elements.push_back(Element);
9012 }
9013
9014 // We've finished with this pack expansion.
9015 continue;
9016 }
9017
9018 // Transform and check key.
9019 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
9020 if (Key.isInvalid())
9021 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009022
Ted Kremeneke65b0862012-03-06 20:05:56 +00009023 if (Key.get() != OrigElement.Key)
9024 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009025
Ted Kremeneke65b0862012-03-06 20:05:56 +00009026 // Transform and check value.
9027 ExprResult Value
9028 = getDerived().TransformExpr(OrigElement.Value);
9029 if (Value.isInvalid())
9030 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009031
Ted Kremeneke65b0862012-03-06 20:05:56 +00009032 if (Value.get() != OrigElement.Value)
9033 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009034
9035 ObjCDictionaryElement Element = {
David Blaikie7a30dc52013-02-21 01:47:18 +00009036 Key.get(), Value.get(), SourceLocation(), None
Ted Kremeneke65b0862012-03-06 20:05:56 +00009037 };
9038 Elements.push_back(Element);
9039 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009040
Ted Kremeneke65b0862012-03-06 20:05:56 +00009041 if (!getDerived().AlwaysRebuild() && !ArgChanged)
9042 return SemaRef.MaybeBindToTemporary(E);
9043
9044 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
9045 Elements.data(),
9046 Elements.size());
Douglas Gregora16548e2009-08-11 05:31:07 +00009047}
9048
Mike Stump11289f42009-09-09 15:08:12 +00009049template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009050ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009051TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00009052 TypeSourceInfo *EncodedTypeInfo
9053 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
9054 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009055 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009056
Douglas Gregora16548e2009-08-11 05:31:07 +00009057 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00009058 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00009059 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009060
9061 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00009062 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00009063 E->getRParenLoc());
9064}
Mike Stump11289f42009-09-09 15:08:12 +00009065
Douglas Gregora16548e2009-08-11 05:31:07 +00009066template<typename Derived>
John McCall31168b02011-06-15 23:02:42 +00009067ExprResult TreeTransform<Derived>::
9068TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
John McCallbc489892013-04-11 02:14:26 +00009069 // This is a kind of implicit conversion, and it needs to get dropped
9070 // and recomputed for the same general reasons that ImplicitCastExprs
9071 // do, as well a more specific one: this expression is only valid when
9072 // it appears *immediately* as an argument expression.
9073 return getDerived().TransformExpr(E->getSubExpr());
John McCall31168b02011-06-15 23:02:42 +00009074}
9075
9076template<typename Derived>
9077ExprResult TreeTransform<Derived>::
9078TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier1dcde962012-08-08 18:46:20 +00009079 TypeSourceInfo *TSInfo
John McCall31168b02011-06-15 23:02:42 +00009080 = getDerived().TransformType(E->getTypeInfoAsWritten());
9081 if (!TSInfo)
9082 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009083
John McCall31168b02011-06-15 23:02:42 +00009084 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier1dcde962012-08-08 18:46:20 +00009085 if (Result.isInvalid())
John McCall31168b02011-06-15 23:02:42 +00009086 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009087
John McCall31168b02011-06-15 23:02:42 +00009088 if (!getDerived().AlwaysRebuild() &&
9089 TSInfo == E->getTypeInfoAsWritten() &&
9090 Result.get() == E->getSubExpr())
9091 return SemaRef.Owned(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009092
John McCall31168b02011-06-15 23:02:42 +00009093 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier1dcde962012-08-08 18:46:20 +00009094 E->getBridgeKeywordLoc(), TSInfo,
John McCall31168b02011-06-15 23:02:42 +00009095 Result.get());
9096}
9097
9098template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009099ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009100TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009101 // Transform arguments.
9102 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009103 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +00009104 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +00009105 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009106 &ArgChanged))
9107 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009108
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009109 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
9110 // Class message: transform the receiver type.
9111 TypeSourceInfo *ReceiverTypeInfo
9112 = getDerived().TransformType(E->getClassReceiverTypeInfo());
9113 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009114 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009115
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009116 // If nothing changed, just retain the existing message send.
9117 if (!getDerived().AlwaysRebuild() &&
9118 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009119 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009120
9121 // Build a new class message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009122 SmallVector<SourceLocation, 16> SelLocs;
9123 E->getSelectorLocs(SelLocs);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009124 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
9125 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009126 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009127 E->getMethodDecl(),
9128 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009129 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009130 E->getRightLoc());
9131 }
9132
9133 // Instance message: transform the receiver
9134 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
9135 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +00009136 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009137 = getDerived().TransformExpr(E->getInstanceReceiver());
9138 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009139 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009140
9141 // If nothing changed, just retain the existing message send.
9142 if (!getDerived().AlwaysRebuild() &&
9143 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009144 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009145
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009146 // Build a new instance message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009147 SmallVector<SourceLocation, 16> SelLocs;
9148 E->getSelectorLocs(SelLocs);
John McCallb268a282010-08-23 23:25:46 +00009149 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009150 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009151 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009152 E->getMethodDecl(),
9153 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009154 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009155 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00009156}
9157
Mike Stump11289f42009-09-09 15:08:12 +00009158template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009159ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009160TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00009161 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009162}
9163
Mike Stump11289f42009-09-09 15:08:12 +00009164template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009165ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009166TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00009167 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009168}
9169
Mike Stump11289f42009-09-09 15:08:12 +00009170template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009171ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009172TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00009173 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00009174 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00009175 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009176 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +00009177
9178 // We don't need to transform the ivar; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +00009179
Douglas Gregord51d90d2010-04-26 20:11:03 +00009180 // If nothing changed, just retain the existing expression.
9181 if (!getDerived().AlwaysRebuild() &&
9182 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00009183 return SemaRef.Owned(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009184
John McCallb268a282010-08-23 23:25:46 +00009185 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00009186 E->getLocation(),
9187 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +00009188}
9189
Mike Stump11289f42009-09-09 15:08:12 +00009190template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009191ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009192TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +00009193 // 'super' and types never change. Property never changes. Just
9194 // retain the existing expression.
9195 if (!E->isObjectReceiver())
John McCallc3007a22010-10-26 07:05:15 +00009196 return SemaRef.Owned(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009197
Douglas Gregor9faee212010-04-26 20:47:02 +00009198 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00009199 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +00009200 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009201 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009202
Douglas Gregor9faee212010-04-26 20:47:02 +00009203 // We don't need to transform the property; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +00009204
Douglas Gregor9faee212010-04-26 20:47:02 +00009205 // If nothing changed, just retain the existing expression.
9206 if (!getDerived().AlwaysRebuild() &&
9207 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00009208 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009209
John McCallb7bd14f2010-12-02 01:19:52 +00009210 if (E->isExplicitProperty())
9211 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
9212 E->getExplicitProperty(),
9213 E->getLocation());
9214
9215 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall526ab472011-10-25 17:37:35 +00009216 SemaRef.Context.PseudoObjectTy,
John McCallb7bd14f2010-12-02 01:19:52 +00009217 E->getImplicitPropertyGetter(),
9218 E->getImplicitPropertySetter(),
9219 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00009220}
9221
Mike Stump11289f42009-09-09 15:08:12 +00009222template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009223ExprResult
Ted Kremeneke65b0862012-03-06 20:05:56 +00009224TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
9225 // Transform the base expression.
9226 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
9227 if (Base.isInvalid())
9228 return ExprError();
9229
9230 // Transform the key expression.
9231 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
9232 if (Key.isInvalid())
9233 return ExprError();
9234
9235 // If nothing changed, just retain the existing expression.
9236 if (!getDerived().AlwaysRebuild() &&
9237 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
9238 return SemaRef.Owned(E);
9239
Chad Rosier1dcde962012-08-08 18:46:20 +00009240 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremeneke65b0862012-03-06 20:05:56 +00009241 Base.get(), Key.get(),
9242 E->getAtIndexMethodDecl(),
9243 E->setAtIndexMethodDecl());
9244}
9245
9246template<typename Derived>
9247ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009248TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00009249 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00009250 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00009251 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009252 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009253
Douglas Gregord51d90d2010-04-26 20:11:03 +00009254 // If nothing changed, just retain the existing expression.
9255 if (!getDerived().AlwaysRebuild() &&
9256 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00009257 return SemaRef.Owned(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009258
John McCallb268a282010-08-23 23:25:46 +00009259 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00009260 E->getOpLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00009261 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +00009262}
9263
Mike Stump11289f42009-09-09 15:08:12 +00009264template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009265ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009266TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009267 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009268 SmallVector<Expr*, 8> SubExprs;
Douglas Gregora3efea12011-01-03 19:04:46 +00009269 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier1dcde962012-08-08 18:46:20 +00009270 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00009271 SubExprs, &ArgumentChanged))
9272 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009273
Douglas Gregora16548e2009-08-11 05:31:07 +00009274 if (!getDerived().AlwaysRebuild() &&
9275 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00009276 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00009277
Douglas Gregora16548e2009-08-11 05:31:07 +00009278 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009279 SubExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00009280 E->getRParenLoc());
9281}
9282
Mike Stump11289f42009-09-09 15:08:12 +00009283template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009284ExprResult
Hal Finkelc4d7c822013-09-18 03:29:45 +00009285TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) {
9286 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
9287 if (SrcExpr.isInvalid())
9288 return ExprError();
9289
9290 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
9291 if (!Type)
9292 return ExprError();
9293
9294 if (!getDerived().AlwaysRebuild() &&
9295 Type == E->getTypeSourceInfo() &&
9296 SrcExpr.get() == E->getSrcExpr())
9297 return SemaRef.Owned(E);
9298
9299 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
9300 SrcExpr.get(), Type,
9301 E->getRParenLoc());
9302}
9303
9304template<typename Derived>
9305ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009306TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +00009307 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier1dcde962012-08-08 18:46:20 +00009308
John McCall490112f2011-02-04 18:33:18 +00009309 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
9310 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
9311
9312 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahaniandd5eb9d2011-12-03 17:47:53 +00009313 blockScope->TheDecl->setBlockMissingReturnType(
9314 oldBlock->blockMissingReturnType());
Chad Rosier1dcde962012-08-08 18:46:20 +00009315
Chris Lattner01cf8db2011-07-20 06:58:45 +00009316 SmallVector<ParmVarDecl*, 4> params;
9317 SmallVector<QualType, 4> paramTypes;
Chad Rosier1dcde962012-08-08 18:46:20 +00009318
Fariborz Jahanian1babe772010-07-09 18:44:02 +00009319 // Parameter substitution.
John McCall490112f2011-02-04 18:33:18 +00009320 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
9321 oldBlock->param_begin(),
9322 oldBlock->param_size(),
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +00009323 0, paramTypes, &params)) {
9324 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009325 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +00009326 }
John McCall490112f2011-02-04 18:33:18 +00009327
Jordan Rosea0a86be2013-03-08 22:25:36 +00009328 const FunctionProtoType *exprFunctionType = E->getFunctionType();
Eli Friedman34b49062012-01-26 03:00:14 +00009329 QualType exprResultType =
Alp Toker314cc812014-01-25 16:55:45 +00009330 getDerived().TransformType(exprFunctionType->getReturnType());
Douglas Gregor476e3022011-01-19 21:32:01 +00009331
Jordan Rose5c382722013-03-08 21:51:21 +00009332 QualType functionType =
9333 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +00009334 exprFunctionType->getExtProtoInfo());
John McCall490112f2011-02-04 18:33:18 +00009335 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +00009336
9337 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +00009338 if (!params.empty())
David Blaikie9c70e042011-09-21 18:16:56 +00009339 blockScope->TheDecl->setParams(params);
Eli Friedman34b49062012-01-26 03:00:14 +00009340
9341 if (!oldBlock->blockMissingReturnType()) {
9342 blockScope->HasImplicitReturnType = false;
9343 blockScope->ReturnType = exprResultType;
9344 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009345
John McCall3882ace2011-01-05 12:14:39 +00009346 // Transform the body
John McCall490112f2011-02-04 18:33:18 +00009347 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +00009348 if (body.isInvalid()) {
9349 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
John McCall3882ace2011-01-05 12:14:39 +00009350 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +00009351 }
John McCall3882ace2011-01-05 12:14:39 +00009352
John McCall490112f2011-02-04 18:33:18 +00009353#ifndef NDEBUG
9354 // In builds with assertions, make sure that we captured everything we
9355 // captured before.
Douglas Gregor4385d8b2011-05-20 15:32:55 +00009356 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
9357 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
9358 e = oldBlock->capture_end(); i != e; ++i) {
9359 VarDecl *oldCapture = i->getVariable();
John McCall490112f2011-02-04 18:33:18 +00009360
Douglas Gregor4385d8b2011-05-20 15:32:55 +00009361 // Ignore parameter packs.
9362 if (isa<ParmVarDecl>(oldCapture) &&
9363 cast<ParmVarDecl>(oldCapture)->isParameterPack())
9364 continue;
John McCall490112f2011-02-04 18:33:18 +00009365
Douglas Gregor4385d8b2011-05-20 15:32:55 +00009366 VarDecl *newCapture =
9367 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
9368 oldCapture));
9369 assert(blockScope->CaptureMap.count(newCapture));
9370 }
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00009371 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCall490112f2011-02-04 18:33:18 +00009372 }
9373#endif
9374
9375 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
9376 /*Scope=*/0);
Douglas Gregora16548e2009-08-11 05:31:07 +00009377}
9378
Mike Stump11289f42009-09-09 15:08:12 +00009379template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009380ExprResult
Tanya Lattner55808c12011-06-04 00:47:47 +00009381TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikie83d382b2011-09-23 05:06:16 +00009382 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner55808c12011-06-04 00:47:47 +00009383}
Eli Friedmandf14b3a2011-10-11 02:20:01 +00009384
9385template<typename Derived>
9386ExprResult
9387TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedman8d3e43f2011-10-14 22:48:56 +00009388 QualType RetTy = getDerived().TransformType(E->getType());
9389 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009390 SmallVector<Expr*, 8> SubExprs;
Eli Friedman8d3e43f2011-10-14 22:48:56 +00009391 SubExprs.reserve(E->getNumSubExprs());
9392 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
9393 SubExprs, &ArgumentChanged))
9394 return ExprError();
9395
9396 if (!getDerived().AlwaysRebuild() &&
9397 !ArgumentChanged)
9398 return SemaRef.Owned(E);
9399
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009400 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedman8d3e43f2011-10-14 22:48:56 +00009401 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedmandf14b3a2011-10-11 02:20:01 +00009402}
Chad Rosier1dcde962012-08-08 18:46:20 +00009403
Douglas Gregora16548e2009-08-11 05:31:07 +00009404//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00009405// Type reconstruction
9406//===----------------------------------------------------------------------===//
9407
Mike Stump11289f42009-09-09 15:08:12 +00009408template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00009409QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
9410 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00009411 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009412 getDerived().getBaseEntity());
9413}
9414
Mike Stump11289f42009-09-09 15:08:12 +00009415template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00009416QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
9417 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00009418 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009419 getDerived().getBaseEntity());
9420}
9421
Mike Stump11289f42009-09-09 15:08:12 +00009422template<typename Derived>
9423QualType
John McCall70dd5f62009-10-30 00:06:24 +00009424TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
9425 bool WrittenAsLValue,
9426 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00009427 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +00009428 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00009429}
9430
9431template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009432QualType
John McCall70dd5f62009-10-30 00:06:24 +00009433TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
9434 QualType ClassType,
9435 SourceLocation Sigil) {
Reid Kleckner0503a872013-12-05 01:23:43 +00009436 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil,
9437 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00009438}
9439
9440template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009441QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00009442TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
9443 ArrayType::ArraySizeModifier SizeMod,
9444 const llvm::APInt *Size,
9445 Expr *SizeExpr,
9446 unsigned IndexTypeQuals,
9447 SourceRange BracketsRange) {
9448 if (SizeExpr || !Size)
9449 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
9450 IndexTypeQuals, BracketsRange,
9451 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00009452
9453 QualType Types[] = {
9454 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
9455 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
9456 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00009457 };
Craig Toppere5ce8312013-07-15 03:38:40 +00009458 const unsigned NumTypes = llvm::array_lengthof(Types);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009459 QualType SizeType;
9460 for (unsigned I = 0; I != NumTypes; ++I)
9461 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
9462 SizeType = Types[I];
9463 break;
9464 }
Mike Stump11289f42009-09-09 15:08:12 +00009465
Eli Friedman9562f392012-01-25 23:20:27 +00009466 // Note that we can return a VariableArrayType here in the case where
9467 // the element type was a dependent VariableArrayType.
9468 IntegerLiteral *ArraySize
9469 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
9470 /*FIXME*/BracketsRange.getBegin());
9471 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009472 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00009473 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00009474}
Mike Stump11289f42009-09-09 15:08:12 +00009475
Douglas Gregord6ff3322009-08-04 16:50:30 +00009476template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009477QualType
9478TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009479 ArrayType::ArraySizeModifier SizeMod,
9480 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00009481 unsigned IndexTypeQuals,
9482 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00009483 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00009484 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009485}
9486
9487template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009488QualType
Mike Stump11289f42009-09-09 15:08:12 +00009489TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009490 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00009491 unsigned IndexTypeQuals,
9492 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00009493 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00009494 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009495}
Mike Stump11289f42009-09-09 15:08:12 +00009496
Douglas Gregord6ff3322009-08-04 16:50:30 +00009497template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009498QualType
9499TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009500 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00009501 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009502 unsigned IndexTypeQuals,
9503 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00009504 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00009505 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009506 IndexTypeQuals, BracketsRange);
9507}
9508
9509template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009510QualType
9511TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009512 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00009513 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009514 unsigned IndexTypeQuals,
9515 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00009516 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00009517 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009518 IndexTypeQuals, BracketsRange);
9519}
9520
9521template<typename Derived>
9522QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +00009523 unsigned NumElements,
9524 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00009525 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +00009526 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009527}
Mike Stump11289f42009-09-09 15:08:12 +00009528
Douglas Gregord6ff3322009-08-04 16:50:30 +00009529template<typename Derived>
9530QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
9531 unsigned NumElements,
9532 SourceLocation AttributeLoc) {
9533 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
9534 NumElements, true);
9535 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00009536 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
9537 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +00009538 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009539}
Mike Stump11289f42009-09-09 15:08:12 +00009540
Douglas Gregord6ff3322009-08-04 16:50:30 +00009541template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009542QualType
9543TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +00009544 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009545 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +00009546 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009547}
Mike Stump11289f42009-09-09 15:08:12 +00009548
Douglas Gregord6ff3322009-08-04 16:50:30 +00009549template<typename Derived>
Jordan Rose5c382722013-03-08 21:51:21 +00009550QualType TreeTransform<Derived>::RebuildFunctionProtoType(
9551 QualType T,
9552 llvm::MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +00009553 const FunctionProtoType::ExtProtoInfo &EPI) {
9554 return SemaRef.BuildFunctionType(T, ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009555 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +00009556 getDerived().getBaseEntity(),
Jordan Rosea0a86be2013-03-08 22:25:36 +00009557 EPI);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009558}
Mike Stump11289f42009-09-09 15:08:12 +00009559
Douglas Gregord6ff3322009-08-04 16:50:30 +00009560template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00009561QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
9562 return SemaRef.Context.getFunctionNoProtoType(T);
9563}
9564
9565template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00009566QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
9567 assert(D && "no decl found");
9568 if (D->isInvalidDecl()) return QualType();
9569
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009570 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +00009571 TypeDecl *Ty;
9572 if (isa<UsingDecl>(D)) {
9573 UsingDecl *Using = cast<UsingDecl>(D);
Enea Zaffanellae05a3cf2013-07-22 10:54:09 +00009574 assert(Using->hasTypename() &&
John McCallb96ec562009-12-04 22:46:56 +00009575 "UnresolvedUsingTypenameDecl transformed to non-typename using");
9576
9577 // A valid resolved using typename decl points to exactly one type decl.
9578 assert(++Using->shadow_begin() == Using->shadow_end());
9579 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +00009580
John McCallb96ec562009-12-04 22:46:56 +00009581 } else {
9582 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
9583 "UnresolvedUsingTypenameDecl transformed to non-using decl");
9584 Ty = cast<UnresolvedUsingTypenameDecl>(D);
9585 }
9586
9587 return SemaRef.Context.getTypeDeclType(Ty);
9588}
9589
9590template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00009591QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
9592 SourceLocation Loc) {
9593 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009594}
9595
9596template<typename Derived>
9597QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
9598 return SemaRef.Context.getTypeOfType(Underlying);
9599}
9600
9601template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00009602QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
9603 SourceLocation Loc) {
9604 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009605}
9606
9607template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00009608QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
9609 UnaryTransformType::UTTKind UKind,
9610 SourceLocation Loc) {
9611 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
9612}
9613
9614template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00009615QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00009616 TemplateName Template,
9617 SourceLocation TemplateNameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +00009618 TemplateArgumentListInfo &TemplateArgs) {
John McCall6b51f282009-11-23 01:53:49 +00009619 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009620}
Mike Stump11289f42009-09-09 15:08:12 +00009621
Douglas Gregor1135c352009-08-06 05:28:30 +00009622template<typename Derived>
Eli Friedman0dfb8892011-10-06 23:00:33 +00009623QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
9624 SourceLocation KWLoc) {
9625 return SemaRef.BuildAtomicType(ValueType, KWLoc);
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,
Douglas Gregor71dc5092009-08-06 06:41:21 +00009631 bool TemplateKW,
9632 TemplateDecl *Template) {
Douglas Gregor9db53502011-03-02 18:07:45 +00009633 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00009634 Template);
9635}
9636
9637template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009638TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00009639TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
9640 const IdentifierInfo &Name,
9641 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +00009642 QualType ObjectType,
9643 NamedDecl *FirstQualifierInScope) {
Douglas Gregor9db53502011-03-02 18:07:45 +00009644 UnqualifiedId TemplateName;
9645 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregorbb119652010-06-16 23:00:59 +00009646 Sema::TemplateTy Template;
Abramo Bagnara7945c982012-01-27 09:46:47 +00009647 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregorbb119652010-06-16 23:00:59 +00009648 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009649 SS, TemplateKWLoc, TemplateName,
John McCallba7bf592010-08-24 05:47:05 +00009650 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00009651 /*EnteringContext=*/false,
9652 Template);
John McCall31f82722010-11-12 08:19:04 +00009653 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +00009654}
Mike Stump11289f42009-09-09 15:08:12 +00009655
Douglas Gregora16548e2009-08-11 05:31:07 +00009656template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00009657TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00009658TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +00009659 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +00009660 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +00009661 QualType ObjectType) {
Douglas Gregor71395fa2009-11-04 00:56:37 +00009662 UnqualifiedId Name;
Douglas Gregor9db53502011-03-02 18:07:45 +00009663 // FIXME: Bogus location information.
Abramo Bagnara7945c982012-01-27 09:46:47 +00009664 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregor9db53502011-03-02 18:07:45 +00009665 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnara7945c982012-01-27 09:46:47 +00009666 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregorbb119652010-06-16 23:00:59 +00009667 Sema::TemplateTy Template;
9668 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009669 SS, TemplateKWLoc, Name,
John McCallba7bf592010-08-24 05:47:05 +00009670 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00009671 /*EnteringContext=*/false,
9672 Template);
Serge Pavlov9ddb76e2013-08-27 13:15:56 +00009673 return Template.get();
Douglas Gregor71395fa2009-11-04 00:56:37 +00009674}
Chad Rosier1dcde962012-08-08 18:46:20 +00009675
Douglas Gregor71395fa2009-11-04 00:56:37 +00009676template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009677ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009678TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
9679 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00009680 Expr *OrigCallee,
9681 Expr *First,
9682 Expr *Second) {
9683 Expr *Callee = OrigCallee->IgnoreParenCasts();
9684 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00009685
Douglas Gregora16548e2009-08-11 05:31:07 +00009686 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00009687 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +00009688 if (!First->getType()->isOverloadableType() &&
9689 !Second->getType()->isOverloadableType())
9690 return getSema().CreateBuiltinArraySubscriptExpr(First,
9691 Callee->getLocStart(),
9692 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00009693 } else if (Op == OO_Arrow) {
9694 // -> is never a builtin operation.
John McCallb268a282010-08-23 23:25:46 +00009695 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
9696 } else if (Second == 0 || isPostIncDec) {
9697 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009698 // The argument is not of overloadable type, so try to create a
9699 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +00009700 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00009701 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00009702
John McCallb268a282010-08-23 23:25:46 +00009703 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00009704 }
9705 } else {
John McCallb268a282010-08-23 23:25:46 +00009706 if (!First->getType()->isOverloadableType() &&
9707 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009708 // Neither of the arguments is an overloadable type, so try to
9709 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +00009710 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00009711 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00009712 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +00009713 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009714 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009715
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009716 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00009717 }
9718 }
Mike Stump11289f42009-09-09 15:08:12 +00009719
9720 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00009721 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00009722 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00009723
John McCallb268a282010-08-23 23:25:46 +00009724 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +00009725 assert(ULE->requiresADL());
9726
9727 // FIXME: Do we have to check
9728 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall4c4c1df2010-01-26 03:27:55 +00009729 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00009730 } else {
Richard Smith58db83d2012-11-28 21:47:39 +00009731 // If we've resolved this to a particular non-member function, just call
9732 // that function. If we resolved it to a member function,
9733 // CreateOverloaded* will find that function for us.
9734 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
9735 if (!isa<CXXMethodDecl>(ND))
9736 Functions.addDecl(ND);
John McCalld14a8642009-11-21 08:51:07 +00009737 }
Mike Stump11289f42009-09-09 15:08:12 +00009738
Douglas Gregora16548e2009-08-11 05:31:07 +00009739 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +00009740 Expr *Args[2] = { First, Second };
9741 unsigned NumArgs = 1 + (Second != 0);
Mike Stump11289f42009-09-09 15:08:12 +00009742
Douglas Gregora16548e2009-08-11 05:31:07 +00009743 // Create the overloaded operator invocation for unary operators.
9744 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +00009745 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00009746 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +00009747 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00009748 }
Mike Stump11289f42009-09-09 15:08:12 +00009749
Douglas Gregore9d62932011-07-15 16:25:15 +00009750 if (Op == OO_Subscript) {
9751 SourceLocation LBrace;
9752 SourceLocation RBrace;
9753
9754 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
9755 DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
9756 LBrace = SourceLocation::getFromRawEncoding(
9757 NameLoc.CXXOperatorName.BeginOpNameLoc);
9758 RBrace = SourceLocation::getFromRawEncoding(
9759 NameLoc.CXXOperatorName.EndOpNameLoc);
9760 } else {
9761 LBrace = Callee->getLocStart();
9762 RBrace = OpLoc;
9763 }
9764
9765 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
9766 First, Second);
9767 }
Sebastian Redladba46e2009-10-29 20:17:01 +00009768
Douglas Gregora16548e2009-08-11 05:31:07 +00009769 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +00009770 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00009771 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00009772 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
9773 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009774 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009775
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009776 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00009777}
Mike Stump11289f42009-09-09 15:08:12 +00009778
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009779template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00009780ExprResult
John McCallb268a282010-08-23 23:25:46 +00009781TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009782 SourceLocation OperatorLoc,
9783 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +00009784 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009785 TypeSourceInfo *ScopeType,
9786 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00009787 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00009788 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +00009789 QualType BaseType = Base->getType();
9790 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009791 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier1dcde962012-08-08 18:46:20 +00009792 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +00009793 !BaseType->getAs<PointerType>()->getPointeeType()
9794 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009795 // This pseudo-destructor expression is still a pseudo-destructor.
John McCallb268a282010-08-23 23:25:46 +00009796 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009797 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00009798 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00009799 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009800 /*FIXME?*/true);
9801 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009802
Douglas Gregor678f90d2010-02-25 01:56:36 +00009803 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009804 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
9805 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
9806 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
9807 NameInfo.setNamedTypeInfo(DestroyedType);
9808
Richard Smith8e4a3862012-05-15 06:15:11 +00009809 // The scope type is now known to be a valid nested name specifier
9810 // component. Tack it on to the end of the nested name specifier.
9811 if (ScopeType)
9812 SS.Extend(SemaRef.Context, SourceLocation(),
9813 ScopeType->getTypeLoc(), CCLoc);
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009814
Abramo Bagnara7945c982012-01-27 09:46:47 +00009815 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCallb268a282010-08-23 23:25:46 +00009816 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009817 OperatorLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009818 SS, TemplateKWLoc,
9819 /*FIXME: FirstQualifier*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009820 NameInfo,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009821 /*TemplateArgs*/ 0);
9822}
9823
Tareq A. Siraj24110cc2013-04-16 18:53:08 +00009824template<typename Derived>
9825StmtResult
9826TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
Wei Pan17fbf6e2013-05-04 03:59:06 +00009827 SourceLocation Loc = S->getLocStart();
9828 unsigned NumParams = S->getCapturedDecl()->getNumParams();
9829 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/0,
9830 S->getCapturedRegionKind(), NumParams);
9831 StmtResult Body = getDerived().TransformStmt(S->getCapturedStmt());
9832
9833 if (Body.isInvalid()) {
9834 getSema().ActOnCapturedRegionError();
9835 return StmtError();
9836 }
9837
9838 return getSema().ActOnCapturedRegionEnd(Body.take());
Tareq A. Siraj24110cc2013-04-16 18:53:08 +00009839}
9840
Douglas Gregord6ff3322009-08-04 16:50:30 +00009841} // end namespace clang
9842
9843#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H