blob: f113891882578e1145df968ce038f78ef243ba93 [file] [log] [blame]
Chris Lattnercab02a62011-02-17 20:34:02 +00001//===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Chris Lattnercab02a62011-02-17 20:34:02 +00007//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00008//
9// This file implements a semantic tree transformation that takes a given
10// AST and rebuilds it, possibly transforming some nodes in the process.
11//
Chris Lattnercab02a62011-02-17 20:34:02 +000012//===----------------------------------------------------------------------===//
13
Douglas Gregord6ff3322009-08-04 16:50:30 +000014#ifndef LLVM_CLANG_SEMA_TREETRANSFORM_H
15#define LLVM_CLANG_SEMA_TREETRANSFORM_H
16
Chandler Carruth3a022472012-12-04 09:13:33 +000017#include "TypeLocBuilder.h"
Douglas Gregor2b6ca462009-09-03 21:38:09 +000018#include "clang/AST/Decl.h"
John McCallde6836a2010-08-24 07:21:54 +000019#include "clang/AST/DeclObjC.h"
Richard Smith3f1b5d02011-05-05 21:57:07 +000020#include "clang/AST/DeclTemplate.h"
Douglas Gregor766b0bb2009-08-06 22:17:10 +000021#include "clang/AST/Expr.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000022#include "clang/AST/ExprCXX.h"
23#include "clang/AST/ExprObjC.h"
Douglas Gregorebe10102009-08-20 07:17:43 +000024#include "clang/AST/Stmt.h"
25#include "clang/AST/StmtCXX.h"
26#include "clang/AST/StmtObjC.h"
Alexey Bataev5ec3eb12013-07-19 03:13:43 +000027#include "clang/AST/StmtOpenMP.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000028#include "clang/Lex/Preprocessor.h"
Chandler Carruth3a022472012-12-04 09:13:33 +000029#include "clang/Sema/Designator.h"
30#include "clang/Sema/Lookup.h"
31#include "clang/Sema/Ownership.h"
32#include "clang/Sema/ParsedTemplate.h"
33#include "clang/Sema/ScopeInfo.h"
34#include "clang/Sema/SemaDiagnostic.h"
35#include "clang/Sema/SemaInternal.h"
David Blaikieb9c168a2011-09-22 02:34:54 +000036#include "llvm/ADT/ArrayRef.h"
John McCall550e0c22009-10-21 00:40:46 +000037#include "llvm/Support/ErrorHandling.h"
Douglas Gregord6ff3322009-08-04 16:50:30 +000038#include <algorithm>
39
40namespace clang {
John McCallaab3e412010-08-25 08:40:02 +000041using namespace sema;
Mike Stump11289f42009-09-09 15:08:12 +000042
Douglas Gregord6ff3322009-08-04 16:50:30 +000043/// \brief A semantic tree transformation that allows one to transform one
44/// abstract syntax tree into another.
45///
Mike Stump11289f42009-09-09 15:08:12 +000046/// A new tree transformation is defined by creating a new subclass \c X of
47/// \c TreeTransform<X> and then overriding certain operations to provide
48/// behavior specific to that transformation. For example, template
Douglas Gregord6ff3322009-08-04 16:50:30 +000049/// instantiation is implemented as a tree transformation where the
50/// transformation of TemplateTypeParmType nodes involves substituting the
51/// template arguments for their corresponding template parameters; a similar
52/// transformation is performed for non-type template parameters and
53/// template template parameters.
54///
55/// This tree-transformation template uses static polymorphism to allow
Mike Stump11289f42009-09-09 15:08:12 +000056/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregord6ff3322009-08-04 16:50:30 +000057/// override any of the transformation or rebuild operators by providing an
58/// operation with the same signature as the default implementation. The
59/// overridding function should not be virtual.
60///
61/// Semantic tree transformations are split into two stages, either of which
62/// can be replaced by a subclass. The "transform" step transforms an AST node
63/// or the parts of an AST node using the various transformation functions,
64/// then passes the pieces on to the "rebuild" step, which constructs a new AST
65/// node of the appropriate kind from the pieces. The default transformation
66/// routines recursively transform the operands to composite AST nodes (e.g.,
67/// the pointee type of a PointerType node) and, if any of those operand nodes
68/// were changed by the transformation, invokes the rebuild operation to create
69/// a new AST node.
70///
Mike Stump11289f42009-09-09 15:08:12 +000071/// Subclasses can customize the transformation at various levels. The
Douglas Gregore922c772009-08-04 22:27:00 +000072/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregorfd35cde2011-03-02 18:50:38 +000073/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(),
Douglas Gregord6ff3322009-08-04 16:50:30 +000074/// TransformTemplateName(), or TransformTemplateArgument() with entirely
75/// new implementations.
76///
77/// For more fine-grained transformations, subclasses can replace any of the
78/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
Douglas Gregorebe10102009-08-20 07:17:43 +000079/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregord6ff3322009-08-04 16:50:30 +000080/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump11289f42009-09-09 15:08:12 +000081/// to substitute template arguments for their corresponding template
Douglas Gregord6ff3322009-08-04 16:50:30 +000082/// parameters. Additionally, subclasses can override the \c RebuildXXX
83/// functions to control how AST nodes are rebuilt when their operands change.
84/// By default, \c TreeTransform will invoke semantic analysis to rebuild
85/// AST nodes. However, certain other tree transformations (e.g, cloning) may
86/// be able to use more efficient rebuild steps.
87///
88/// There are a handful of other functions that can be overridden, allowing one
Mike Stump11289f42009-09-09 15:08:12 +000089/// to avoid traversing nodes that don't need any transformation
Douglas Gregord6ff3322009-08-04 16:50:30 +000090/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
91/// operands have not changed (\c AlwaysRebuild()), and customize the
92/// default locations and entity names used for type-checking
93/// (\c getBaseLocation(), \c getBaseEntity()).
Douglas Gregord6ff3322009-08-04 16:50:30 +000094template<typename Derived>
95class TreeTransform {
Douglas Gregora8bac7f2011-01-10 07:32:04 +000096 /// \brief Private RAII object that helps us forget and then re-remember
97 /// the template argument corresponding to a partially-substituted parameter
98 /// pack.
99 class ForgetPartiallySubstitutedPackRAII {
100 Derived &Self;
101 TemplateArgument Old;
Chad Rosier1dcde962012-08-08 18:46:20 +0000102
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000103 public:
104 ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) {
105 Old = Self.ForgetPartiallySubstitutedPack();
106 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000107
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000108 ~ForgetPartiallySubstitutedPackRAII() {
109 Self.RememberPartiallySubstitutedPack(Old);
110 }
111 };
Chad Rosier1dcde962012-08-08 18:46:20 +0000112
Douglas Gregord6ff3322009-08-04 16:50:30 +0000113protected:
114 Sema &SemaRef;
Chad Rosier1dcde962012-08-08 18:46:20 +0000115
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000116 /// \brief The set of local declarations that have been transformed, for
117 /// cases where we are forced to build new declarations within the transformer
118 /// rather than in the subclass (e.g., lambda closure types).
119 llvm::DenseMap<Decl *, Decl *> TransformedLocalDecls;
Chad Rosier1dcde962012-08-08 18:46:20 +0000120
Mike Stump11289f42009-09-09 15:08:12 +0000121public:
Douglas Gregord6ff3322009-08-04 16:50:30 +0000122 /// \brief Initializes a new tree transformer.
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000123 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump11289f42009-09-09 15:08:12 +0000124
Douglas Gregord6ff3322009-08-04 16:50:30 +0000125 /// \brief Retrieves a reference to the derived class.
126 Derived &getDerived() { return static_cast<Derived&>(*this); }
127
128 /// \brief Retrieves a reference to the derived class.
Mike Stump11289f42009-09-09 15:08:12 +0000129 const Derived &getDerived() const {
130 return static_cast<const Derived&>(*this);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000131 }
132
John McCalldadc5752010-08-24 06:29:42 +0000133 static inline ExprResult Owned(Expr *E) { return E; }
134 static inline StmtResult Owned(Stmt *S) { return S; }
John McCallb268a282010-08-23 23:25:46 +0000135
Douglas Gregord6ff3322009-08-04 16:50:30 +0000136 /// \brief Retrieves a reference to the semantic analysis object used for
137 /// this tree transform.
138 Sema &getSema() const { return SemaRef; }
Mike Stump11289f42009-09-09 15:08:12 +0000139
Douglas Gregord6ff3322009-08-04 16:50:30 +0000140 /// \brief Whether the transformation should always rebuild AST nodes, even
141 /// if none of the children have changed.
142 ///
143 /// Subclasses may override this function to specify when the transformation
144 /// should rebuild all AST nodes.
Richard Smith2aa81a72013-11-07 20:07:17 +0000145 ///
146 /// We must always rebuild all AST nodes when performing variadic template
147 /// pack expansion, in order to avoid violating the AST invariant that each
148 /// statement node appears at most once in its containing declaration.
149 bool AlwaysRebuild() { return SemaRef.ArgumentPackSubstitutionIndex != -1; }
Mike Stump11289f42009-09-09 15:08:12 +0000150
Douglas Gregord6ff3322009-08-04 16:50:30 +0000151 /// \brief Returns the location of the entity being transformed, if that
152 /// information was not available elsewhere in the AST.
153 ///
Mike Stump11289f42009-09-09 15:08:12 +0000154 /// By default, returns no source-location information. Subclasses can
Douglas Gregord6ff3322009-08-04 16:50:30 +0000155 /// provide an alternative implementation that provides better location
156 /// information.
157 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump11289f42009-09-09 15:08:12 +0000158
Douglas Gregord6ff3322009-08-04 16:50:30 +0000159 /// \brief Returns the name of the entity being transformed, if that
160 /// information was not available elsewhere in the AST.
161 ///
162 /// By default, returns an empty name. Subclasses can provide an alternative
163 /// implementation with a more precise name.
164 DeclarationName getBaseEntity() { return DeclarationName(); }
165
Douglas Gregora16548e2009-08-11 05:31:07 +0000166 /// \brief Sets the "base" location and entity when that
167 /// information is known based on another transformation.
168 ///
169 /// By default, the source location and entity are ignored. Subclasses can
170 /// override this function to provide a customized implementation.
171 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump11289f42009-09-09 15:08:12 +0000172
Douglas Gregora16548e2009-08-11 05:31:07 +0000173 /// \brief RAII object that temporarily sets the base location and entity
174 /// used for reporting diagnostics in types.
175 class TemporaryBase {
176 TreeTransform &Self;
177 SourceLocation OldLocation;
178 DeclarationName OldEntity;
Mike Stump11289f42009-09-09 15:08:12 +0000179
Douglas Gregora16548e2009-08-11 05:31:07 +0000180 public:
181 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump11289f42009-09-09 15:08:12 +0000182 DeclarationName Entity) : Self(Self) {
Douglas Gregora16548e2009-08-11 05:31:07 +0000183 OldLocation = Self.getDerived().getBaseLocation();
184 OldEntity = Self.getDerived().getBaseEntity();
Chad Rosier1dcde962012-08-08 18:46:20 +0000185
Douglas Gregora518d5b2011-01-25 17:51:48 +0000186 if (Location.isValid())
187 Self.getDerived().setBase(Location, Entity);
Douglas Gregora16548e2009-08-11 05:31:07 +0000188 }
Mike Stump11289f42009-09-09 15:08:12 +0000189
Douglas Gregora16548e2009-08-11 05:31:07 +0000190 ~TemporaryBase() {
191 Self.getDerived().setBase(OldLocation, OldEntity);
192 }
193 };
Mike Stump11289f42009-09-09 15:08:12 +0000194
195 /// \brief Determine whether the given type \p T has already been
Douglas Gregord6ff3322009-08-04 16:50:30 +0000196 /// transformed.
197 ///
198 /// Subclasses can provide an alternative implementation of this routine
Mike Stump11289f42009-09-09 15:08:12 +0000199 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregord6ff3322009-08-04 16:50:30 +0000200 /// not change. For example, template instantiation need not traverse
201 /// non-dependent types.
202 bool AlreadyTransformed(QualType T) {
203 return T.isNull();
204 }
205
Douglas Gregord196a582009-12-14 19:27:10 +0000206 /// \brief Determine whether the given call argument should be dropped, e.g.,
207 /// because it is a default argument.
208 ///
209 /// Subclasses can provide an alternative implementation of this routine to
210 /// determine which kinds of call arguments get dropped. By default,
211 /// CXXDefaultArgument nodes are dropped (prior to transformation).
212 bool DropCallArgument(Expr *E) {
213 return E->isDefaultArgument();
214 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000215
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000216 /// \brief Determine whether we should expand a pack expansion with the
217 /// given set of parameter packs into separate arguments by repeatedly
218 /// transforming the pattern.
219 ///
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000220 /// By default, the transformer never tries to expand pack expansions.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000221 /// Subclasses can override this routine to provide different behavior.
222 ///
223 /// \param EllipsisLoc The location of the ellipsis that identifies the
224 /// pack expansion.
225 ///
226 /// \param PatternRange The source range that covers the entire pattern of
227 /// the pack expansion.
228 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000229 /// \param Unexpanded The set of unexpanded parameter packs within the
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000230 /// pattern.
231 ///
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000232 /// \param ShouldExpand Will be set to \c true if the transformer should
233 /// expand the corresponding pack expansions into separate arguments. When
234 /// set, \c NumExpansions must also be set.
235 ///
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000236 /// \param RetainExpansion Whether the caller should add an unexpanded
237 /// pack expansion after all of the expanded arguments. This is used
238 /// when extending explicitly-specified template argument packs per
239 /// C++0x [temp.arg.explicit]p9.
240 ///
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000241 /// \param NumExpansions The number of separate arguments that will be in
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000242 /// the expanded form of the corresponding pack expansion. This is both an
243 /// input and an output parameter, which can be set by the caller if the
244 /// number of expansions is known a priori (e.g., due to a prior substitution)
245 /// and will be set by the callee when the number of expansions is known.
246 /// The callee must set this value when \c ShouldExpand is \c true; it may
247 /// set this value in other cases.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000248 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000249 /// \returns true if an error occurred (e.g., because the parameter packs
250 /// are to be instantiated with arguments of different lengths), false
251 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000252 /// must be set.
253 bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
254 SourceRange PatternRange,
Dmitri Gribenkof8579502013-01-12 19:30:44 +0000255 ArrayRef<UnexpandedParameterPack> Unexpanded,
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000256 bool &ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000257 bool &RetainExpansion,
David Blaikie05785d12013-02-20 22:23:23 +0000258 Optional<unsigned> &NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000259 ShouldExpand = false;
260 return false;
261 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000262
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000263 /// \brief "Forget" about the partially-substituted pack template argument,
264 /// when performing an instantiation that must preserve the parameter pack
265 /// use.
266 ///
267 /// This routine is meant to be overridden by the template instantiator.
268 TemplateArgument ForgetPartiallySubstitutedPack() {
269 return TemplateArgument();
270 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000271
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000272 /// \brief "Remember" the partially-substituted pack template argument
273 /// after performing an instantiation that must preserve the parameter pack
274 /// use.
275 ///
276 /// This routine is meant to be overridden by the template instantiator.
277 void RememberPartiallySubstitutedPack(TemplateArgument Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000278
Douglas Gregorf3010112011-01-07 16:43:16 +0000279 /// \brief Note to the derived class when a function parameter pack is
280 /// being expanded.
281 void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000282
Douglas Gregord6ff3322009-08-04 16:50:30 +0000283 /// \brief Transforms the given type into another type.
284 ///
John McCall550e0c22009-10-21 00:40:46 +0000285 /// By default, this routine transforms a type by creating a
John McCallbcd03502009-12-07 02:54:59 +0000286 /// TypeSourceInfo for it and delegating to the appropriate
John McCall550e0c22009-10-21 00:40:46 +0000287 /// function. This is expensive, but we don't mind, because
288 /// this method is deprecated anyway; all users should be
John McCallbcd03502009-12-07 02:54:59 +0000289 /// switched to storing TypeSourceInfos.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000290 ///
291 /// \returns the transformed type.
John McCall31f82722010-11-12 08:19:04 +0000292 QualType TransformType(QualType T);
Mike Stump11289f42009-09-09 15:08:12 +0000293
John McCall550e0c22009-10-21 00:40:46 +0000294 /// \brief Transforms the given type-with-location into a new
295 /// type-with-location.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000296 ///
John McCall550e0c22009-10-21 00:40:46 +0000297 /// By default, this routine transforms a type by delegating to the
298 /// appropriate TransformXXXType to build a new type. Subclasses
299 /// may override this function (to take over all type
300 /// transformations) or some set of the TransformXXXType functions
301 /// to alter the transformation.
John McCall31f82722010-11-12 08:19:04 +0000302 TypeSourceInfo *TransformType(TypeSourceInfo *DI);
John McCall550e0c22009-10-21 00:40:46 +0000303
304 /// \brief Transform the given type-with-location into a new
305 /// type, collecting location information in the given builder
306 /// as necessary.
307 ///
John McCall31f82722010-11-12 08:19:04 +0000308 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
Mike Stump11289f42009-09-09 15:08:12 +0000309
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000310 /// \brief Transform the given statement.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000311 ///
Mike Stump11289f42009-09-09 15:08:12 +0000312 /// By default, this routine transforms a statement by delegating to the
Douglas Gregorebe10102009-08-20 07:17:43 +0000313 /// appropriate TransformXXXStmt function to transform a specific kind of
314 /// statement or the TransformExpr() function to transform an expression.
315 /// Subclasses may override this function to transform statements using some
316 /// other mechanism.
317 ///
318 /// \returns the transformed statement.
John McCalldadc5752010-08-24 06:29:42 +0000319 StmtResult TransformStmt(Stmt *S);
Mike Stump11289f42009-09-09 15:08:12 +0000320
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000321 /// \brief Transform the given statement.
322 ///
323 /// By default, this routine transforms a statement by delegating to the
324 /// appropriate TransformOMPXXXClause function to transform a specific kind
325 /// of clause. Subclasses may override this function to transform statements
326 /// using some other mechanism.
327 ///
328 /// \returns the transformed OpenMP clause.
329 OMPClause *TransformOMPClause(OMPClause *S);
330
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000331 /// \brief Transform the given expression.
332 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000333 /// By default, this routine transforms an expression by delegating to the
334 /// appropriate TransformXXXExpr function to build a new expression.
335 /// Subclasses may override this function to transform expressions using some
336 /// other mechanism.
337 ///
338 /// \returns the transformed expression.
John McCalldadc5752010-08-24 06:29:42 +0000339 ExprResult TransformExpr(Expr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000340
Richard Smithd59b8322012-12-19 01:39:02 +0000341 /// \brief Transform the given initializer.
342 ///
343 /// By default, this routine transforms an initializer by stripping off the
344 /// semantic nodes added by initialization, then passing the result to
345 /// TransformExpr or TransformExprs.
346 ///
347 /// \returns the transformed initializer.
348 ExprResult TransformInitializer(Expr *Init, bool CXXDirectInit);
349
Douglas Gregora3efea12011-01-03 19:04:46 +0000350 /// \brief Transform the given list of expressions.
351 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000352 /// This routine transforms a list of expressions by invoking
353 /// \c TransformExpr() for each subexpression. However, it also provides
Douglas Gregora3efea12011-01-03 19:04:46 +0000354 /// support for variadic templates by expanding any pack expansions (if the
355 /// derived class permits such expansion) along the way. When pack expansions
356 /// are present, the number of outputs may not equal the number of inputs.
357 ///
358 /// \param Inputs The set of expressions to be transformed.
359 ///
360 /// \param NumInputs The number of expressions in \c Inputs.
361 ///
362 /// \param IsCall If \c true, then this transform is being performed on
Chad Rosier1dcde962012-08-08 18:46:20 +0000363 /// function-call arguments, and any arguments that should be dropped, will
Douglas Gregora3efea12011-01-03 19:04:46 +0000364 /// be.
365 ///
366 /// \param Outputs The transformed input expressions will be added to this
367 /// vector.
368 ///
369 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
370 /// due to transformation.
371 ///
372 /// \returns true if an error occurred, false otherwise.
373 bool TransformExprs(Expr **Inputs, unsigned NumInputs, bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +0000374 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregora3efea12011-01-03 19:04:46 +0000375 bool *ArgChanged = 0);
Chad Rosier1dcde962012-08-08 18:46:20 +0000376
Douglas Gregord6ff3322009-08-04 16:50:30 +0000377 /// \brief Transform the given declaration, which is referenced from a type
378 /// or expression.
379 ///
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000380 /// By default, acts as the identity function on declarations, unless the
381 /// transformer has had to transform the declaration itself. Subclasses
Douglas Gregor1135c352009-08-06 05:28:30 +0000382 /// may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000383 Decl *TransformDecl(SourceLocation Loc, Decl *D) {
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000384 llvm::DenseMap<Decl *, Decl *>::iterator Known
385 = TransformedLocalDecls.find(D);
386 if (Known != TransformedLocalDecls.end())
387 return Known->second;
Chad Rosier1dcde962012-08-08 18:46:20 +0000388
389 return D;
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000390 }
Douglas Gregorebe10102009-08-20 07:17:43 +0000391
Chad Rosier1dcde962012-08-08 18:46:20 +0000392 /// \brief Transform the attributes associated with the given declaration and
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000393 /// place them on the new declaration.
394 ///
395 /// By default, this operation does nothing. Subclasses may override this
396 /// behavior to transform attributes.
397 void transformAttrs(Decl *Old, Decl *New) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000398
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000399 /// \brief Note that a local declaration has been transformed by this
400 /// transformer.
401 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000402 /// Local declarations are typically transformed via a call to
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000403 /// TransformDefinition. However, in some cases (e.g., lambda expressions),
404 /// the transformer itself has to transform the declarations. This routine
405 /// can be overridden by a subclass that keeps track of such mappings.
406 void transformedLocalDecl(Decl *Old, Decl *New) {
407 TransformedLocalDecls[Old] = New;
408 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000409
Douglas Gregorebe10102009-08-20 07:17:43 +0000410 /// \brief Transform the definition of the given declaration.
411 ///
Mike Stump11289f42009-09-09 15:08:12 +0000412 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregorebe10102009-08-20 07:17:43 +0000413 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000414 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
415 return getDerived().TransformDecl(Loc, D);
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000416 }
Mike Stump11289f42009-09-09 15:08:12 +0000417
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000418 /// \brief Transform the given declaration, which was the first part of a
419 /// nested-name-specifier in a member access expression.
420 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000421 /// This specific declaration transformation only applies to the first
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000422 /// identifier in a nested-name-specifier of a member access expression, e.g.,
423 /// the \c T in \c x->T::member
424 ///
425 /// By default, invokes TransformDecl() to transform the declaration.
426 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000427 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
428 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000429 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000430
Douglas Gregor14454802011-02-25 02:25:35 +0000431 /// \brief Transform the given nested-name-specifier with source-location
432 /// information.
433 ///
434 /// By default, transforms all of the types and declarations within the
435 /// nested-name-specifier. Subclasses may override this function to provide
436 /// alternate behavior.
437 NestedNameSpecifierLoc TransformNestedNameSpecifierLoc(
438 NestedNameSpecifierLoc NNS,
439 QualType ObjectType = QualType(),
440 NamedDecl *FirstQualifierInScope = 0);
441
Douglas Gregorf816bd72009-09-03 22:13:48 +0000442 /// \brief Transform the given declaration name.
443 ///
444 /// By default, transforms the types of conversion function, constructor,
445 /// and destructor names and then (if needed) rebuilds the declaration name.
446 /// Identifiers and selectors are returned unmodified. Sublcasses may
447 /// override this function to provide alternate behavior.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000448 DeclarationNameInfo
John McCall31f82722010-11-12 08:19:04 +0000449 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump11289f42009-09-09 15:08:12 +0000450
Douglas Gregord6ff3322009-08-04 16:50:30 +0000451 /// \brief Transform the given template name.
Mike Stump11289f42009-09-09 15:08:12 +0000452 ///
Douglas Gregor9db53502011-03-02 18:07:45 +0000453 /// \param SS The nested-name-specifier that qualifies the template
454 /// name. This nested-name-specifier must already have been transformed.
455 ///
456 /// \param Name The template name to transform.
457 ///
458 /// \param NameLoc The source location of the template name.
459 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000460 /// \param ObjectType If we're translating a template name within a member
Douglas Gregor9db53502011-03-02 18:07:45 +0000461 /// access expression, this is the type of the object whose member template
462 /// is being referenced.
463 ///
464 /// \param FirstQualifierInScope If the first part of a nested-name-specifier
465 /// also refers to a name within the current (lexical) scope, this is the
466 /// declaration it refers to.
467 ///
468 /// By default, transforms the template name by transforming the declarations
469 /// and nested-name-specifiers that occur within the template name.
470 /// Subclasses may override this function to provide alternate behavior.
471 TemplateName TransformTemplateName(CXXScopeSpec &SS,
472 TemplateName Name,
Abramo Bagnara7945c982012-01-27 09:46:47 +0000473 SourceLocation NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +0000474 QualType ObjectType = QualType(),
475 NamedDecl *FirstQualifierInScope = 0);
476
Douglas Gregord6ff3322009-08-04 16:50:30 +0000477 /// \brief Transform the given template argument.
478 ///
Mike Stump11289f42009-09-09 15:08:12 +0000479 /// By default, this operation transforms the type, expression, or
480 /// declaration stored within the template argument and constructs a
Douglas Gregore922c772009-08-04 22:27:00 +0000481 /// new template argument from the transformed result. Subclasses may
482 /// override this function to provide alternate behavior.
John McCall0ad16662009-10-29 08:12:44 +0000483 ///
484 /// Returns true if there was an error.
485 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
486 TemplateArgumentLoc &Output);
487
Douglas Gregor62e06f22010-12-20 17:31:10 +0000488 /// \brief Transform the given set of template arguments.
489 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000490 /// By default, this operation transforms all of the template arguments
Douglas Gregor62e06f22010-12-20 17:31:10 +0000491 /// in the input set using \c TransformTemplateArgument(), and appends
492 /// the transformed arguments to the output list.
493 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000494 /// Note that this overload of \c TransformTemplateArguments() is merely
495 /// a convenience function. Subclasses that wish to override this behavior
496 /// should override the iterator-based member template version.
497 ///
Douglas Gregor62e06f22010-12-20 17:31:10 +0000498 /// \param Inputs The set of template arguments to be transformed.
499 ///
500 /// \param NumInputs The number of template arguments in \p Inputs.
501 ///
502 /// \param Outputs The set of transformed template arguments output by this
503 /// routine.
504 ///
505 /// Returns true if an error occurred.
506 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
507 unsigned NumInputs,
Douglas Gregorfe921a72010-12-20 23:36:19 +0000508 TemplateArgumentListInfo &Outputs) {
509 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs);
510 }
Douglas Gregor42cafa82010-12-20 17:42:22 +0000511
512 /// \brief Transform the given set of template arguments.
513 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000514 /// By default, this operation transforms all of the template arguments
Douglas Gregor42cafa82010-12-20 17:42:22 +0000515 /// in the input set using \c TransformTemplateArgument(), and appends
Chad Rosier1dcde962012-08-08 18:46:20 +0000516 /// the transformed arguments to the output list.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000517 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000518 /// \param First An iterator to the first template argument.
519 ///
520 /// \param Last An iterator one step past the last template argument.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000521 ///
522 /// \param Outputs The set of transformed template arguments output by this
523 /// routine.
524 ///
525 /// Returns true if an error occurred.
Douglas Gregorfe921a72010-12-20 23:36:19 +0000526 template<typename InputIterator>
527 bool TransformTemplateArguments(InputIterator First,
528 InputIterator Last,
529 TemplateArgumentListInfo &Outputs);
Douglas Gregor42cafa82010-12-20 17:42:22 +0000530
John McCall0ad16662009-10-29 08:12:44 +0000531 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
532 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
533 TemplateArgumentLoc &ArgLoc);
534
John McCallbcd03502009-12-07 02:54:59 +0000535 /// \brief Fakes up a TypeSourceInfo for a type.
536 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
537 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall0ad16662009-10-29 08:12:44 +0000538 getDerived().getBaseLocation());
539 }
Mike Stump11289f42009-09-09 15:08:12 +0000540
John McCall550e0c22009-10-21 00:40:46 +0000541#define ABSTRACT_TYPELOC(CLASS, PARENT)
542#define TYPELOC(CLASS, PARENT) \
John McCall31f82722010-11-12 08:19:04 +0000543 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCall550e0c22009-10-21 00:40:46 +0000544#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +0000545
Douglas Gregor3024f072012-04-16 07:05:22 +0000546 QualType TransformFunctionProtoType(TypeLocBuilder &TLB,
547 FunctionProtoTypeLoc TL,
548 CXXRecordDecl *ThisContext,
549 unsigned ThisTypeQuals);
550
David Majnemerfad8f482013-10-15 09:33:02 +0000551 StmtResult TransformSEHHandler(Stmt *Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +0000552
Chad Rosier1dcde962012-08-08 18:46:20 +0000553 QualType
John McCall31f82722010-11-12 08:19:04 +0000554 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
555 TemplateSpecializationTypeLoc TL,
556 TemplateName Template);
557
Chad Rosier1dcde962012-08-08 18:46:20 +0000558 QualType
John McCall31f82722010-11-12 08:19:04 +0000559 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
560 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +0000561 TemplateName Template,
562 CXXScopeSpec &SS);
Douglas Gregor5a064722011-02-28 17:23:35 +0000563
Chad Rosier1dcde962012-08-08 18:46:20 +0000564 QualType
Douglas Gregor5a064722011-02-28 17:23:35 +0000565 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
Douglas Gregora7a795b2011-03-01 20:11:18 +0000566 DependentTemplateSpecializationTypeLoc TL,
567 NestedNameSpecifierLoc QualifierLoc);
568
John McCall58f10c32010-03-11 09:03:00 +0000569 /// \brief Transforms the parameters of a function type into the
570 /// given vectors.
571 ///
572 /// The result vectors should be kept in sync; null entries in the
573 /// variables vector are acceptable.
574 ///
575 /// Return true on error.
Douglas Gregordd472162011-01-07 00:20:55 +0000576 bool TransformFunctionTypeParams(SourceLocation Loc,
577 ParmVarDecl **Params, unsigned NumParams,
578 const QualType *ParamTypes,
Chris Lattner01cf8db2011-07-20 06:58:45 +0000579 SmallVectorImpl<QualType> &PTypes,
580 SmallVectorImpl<ParmVarDecl*> *PVars);
John McCall58f10c32010-03-11 09:03:00 +0000581
582 /// \brief Transforms a single function-type parameter. Return null
583 /// on error.
John McCall8fb0d9d2011-05-01 22:35:37 +0000584 ///
585 /// \param indexAdjustment - A number to add to the parameter's
586 /// scope index; can be negative
Douglas Gregor715e4612011-01-14 22:40:04 +0000587 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +0000588 int indexAdjustment,
David Blaikie05785d12013-02-20 22:23:23 +0000589 Optional<unsigned> NumExpansions,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +0000590 bool ExpectParameterPack);
John McCall58f10c32010-03-11 09:03:00 +0000591
John McCall31f82722010-11-12 08:19:04 +0000592 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall0ad16662009-10-29 08:12:44 +0000593
John McCalldadc5752010-08-24 06:29:42 +0000594 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
595 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +0000596
597 typedef std::pair<ExprResult, QualType> InitCaptureInfoTy;
Richard Smith2589b9802012-07-25 03:56:55 +0000598 /// \brief Transform the captures and body of a lambda expression.
Faisal Vali5fb7c3c2013-12-05 01:40:41 +0000599 ExprResult TransformLambdaScope(LambdaExpr *E, CXXMethodDecl *CallOperator,
600 ArrayRef<InitCaptureInfoTy> InitCaptureExprsAndTypes);
Richard Smith2589b9802012-07-25 03:56:55 +0000601
Faisal Vali2cba1332013-10-23 06:44:28 +0000602 TemplateParameterList *TransformTemplateParameterList(
603 TemplateParameterList *TPL) {
604 return TPL;
605 }
606
Richard Smithdb2630f2012-10-21 03:28:35 +0000607 ExprResult TransformAddressOfOperand(Expr *E);
608 ExprResult TransformDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E,
609 bool IsAddressOfOperand);
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000610 StmtResult TransformOMPExecutableDirective(OMPExecutableDirective *S);
Richard Smithdb2630f2012-10-21 03:28:35 +0000611
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000612// FIXME: We use LLVM_ATTRIBUTE_NOINLINE because inlining causes a ridiculous
613// amount of stack usage with clang.
Douglas Gregorebe10102009-08-20 07:17:43 +0000614#define STMT(Node, Parent) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000615 LLVM_ATTRIBUTE_NOINLINE \
John McCalldadc5752010-08-24 06:29:42 +0000616 StmtResult Transform##Node(Node *S);
Douglas Gregora16548e2009-08-11 05:31:07 +0000617#define EXPR(Node, Parent) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000618 LLVM_ATTRIBUTE_NOINLINE \
John McCalldadc5752010-08-24 06:29:42 +0000619 ExprResult Transform##Node(Node *E);
Alexis Huntabb2ac82010-05-18 06:22:21 +0000620#define ABSTRACT_STMT(Stmt)
Alexis Hunt656bb312010-05-05 15:24:00 +0000621#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +0000622
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000623#define OPENMP_CLAUSE(Name, Class) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000624 LLVM_ATTRIBUTE_NOINLINE \
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000625 OMPClause *Transform ## Class(Class *S);
626#include "clang/Basic/OpenMPKinds.def"
627
Douglas Gregord6ff3322009-08-04 16:50:30 +0000628 /// \brief Build a new pointer type given its pointee type.
629 ///
630 /// By default, performs semantic analysis when building the pointer type.
631 /// Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000632 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000633
634 /// \brief Build a new block pointer type given its pointee type.
635 ///
Mike Stump11289f42009-09-09 15:08:12 +0000636 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000637 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000638 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000639
John McCall70dd5f62009-10-30 00:06:24 +0000640 /// \brief Build a new reference type given the type it references.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000641 ///
John McCall70dd5f62009-10-30 00:06:24 +0000642 /// By default, performs semantic analysis when building the
643 /// reference type. Subclasses may override this routine to provide
644 /// different behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000645 ///
John McCall70dd5f62009-10-30 00:06:24 +0000646 /// \param LValue whether the type was written with an lvalue sigil
647 /// or an rvalue sigil.
648 QualType RebuildReferenceType(QualType ReferentType,
649 bool LValue,
650 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000651
Douglas Gregord6ff3322009-08-04 16:50:30 +0000652 /// \brief Build a new member pointer type given the pointee type and the
653 /// class type it refers into.
654 ///
655 /// By default, performs semantic analysis when building the member pointer
656 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000657 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
658 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000659
Douglas Gregord6ff3322009-08-04 16:50:30 +0000660 /// \brief Build a new array type given the element type, size
661 /// modifier, size of the array (if known), size expression, and index type
662 /// qualifiers.
663 ///
664 /// By default, performs semantic analysis when building the array type.
665 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000666 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-08-04 16:50:30 +0000667 QualType RebuildArrayType(QualType ElementType,
668 ArrayType::ArraySizeModifier SizeMod,
669 const llvm::APInt *Size,
670 Expr *SizeExpr,
671 unsigned IndexTypeQuals,
672 SourceRange BracketsRange);
Mike Stump11289f42009-09-09 15:08:12 +0000673
Douglas Gregord6ff3322009-08-04 16:50:30 +0000674 /// \brief Build a new constant array type given the element type, size
675 /// modifier, (known) size of the array, and index type qualifiers.
676 ///
677 /// By default, performs semantic analysis when building the array type.
678 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000679 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000680 ArrayType::ArraySizeModifier SizeMod,
681 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +0000682 unsigned IndexTypeQuals,
683 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000684
Douglas Gregord6ff3322009-08-04 16:50:30 +0000685 /// \brief Build a new incomplete array type given the element type, size
686 /// modifier, and index type qualifiers.
687 ///
688 /// By default, performs semantic analysis when building the array type.
689 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000690 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000691 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +0000692 unsigned IndexTypeQuals,
693 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000694
Mike Stump11289f42009-09-09 15:08:12 +0000695 /// \brief Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000696 /// size modifier, size expression, and index type qualifiers.
697 ///
698 /// By default, performs semantic analysis when building the array type.
699 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000700 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000701 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000702 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000703 unsigned IndexTypeQuals,
704 SourceRange BracketsRange);
705
Mike Stump11289f42009-09-09 15:08:12 +0000706 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000707 /// size modifier, size expression, and index type qualifiers.
708 ///
709 /// By default, performs semantic analysis when building the array type.
710 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000711 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000712 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000713 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000714 unsigned IndexTypeQuals,
715 SourceRange BracketsRange);
716
717 /// \brief Build a new vector type given the element type and
718 /// number of elements.
719 ///
720 /// By default, performs semantic analysis when building the vector type.
721 /// Subclasses may override this routine to provide different behavior.
John Thompson22334602010-02-05 00:12:22 +0000722 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsonaeb56442010-11-10 21:56:12 +0000723 VectorType::VectorKind VecKind);
Mike Stump11289f42009-09-09 15:08:12 +0000724
Douglas Gregord6ff3322009-08-04 16:50:30 +0000725 /// \brief Build a new extended vector type given the element type and
726 /// number of elements.
727 ///
728 /// By default, performs semantic analysis when building the vector type.
729 /// Subclasses may override this routine to provide different behavior.
730 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
731 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000732
733 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000734 /// given the element type and number of elements.
735 ///
736 /// By default, performs semantic analysis when building the vector type.
737 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000738 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +0000739 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000740 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000741
Douglas Gregord6ff3322009-08-04 16:50:30 +0000742 /// \brief Build a new function type.
743 ///
744 /// By default, performs semantic analysis when building the function type.
745 /// Subclasses may override this routine to provide different behavior.
746 QualType RebuildFunctionProtoType(QualType T,
Jordan Rose5c382722013-03-08 21:51:21 +0000747 llvm::MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +0000748 const FunctionProtoType::ExtProtoInfo &EPI);
Mike Stump11289f42009-09-09 15:08:12 +0000749
John McCall550e0c22009-10-21 00:40:46 +0000750 /// \brief Build a new unprototyped function type.
751 QualType RebuildFunctionNoProtoType(QualType ResultType);
752
John McCallb96ec562009-12-04 22:46:56 +0000753 /// \brief Rebuild an unresolved typename type, given the decl that
754 /// the UnresolvedUsingTypenameDecl was transformed to.
755 QualType RebuildUnresolvedUsingType(Decl *D);
756
Douglas Gregord6ff3322009-08-04 16:50:30 +0000757 /// \brief Build a new typedef type.
Richard Smithdda56e42011-04-15 14:24:37 +0000758 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
Douglas Gregord6ff3322009-08-04 16:50:30 +0000759 return SemaRef.Context.getTypeDeclType(Typedef);
760 }
761
762 /// \brief Build a new class/struct/union type.
763 QualType RebuildRecordType(RecordDecl *Record) {
764 return SemaRef.Context.getTypeDeclType(Record);
765 }
766
767 /// \brief Build a new Enum type.
768 QualType RebuildEnumType(EnumDecl *Enum) {
769 return SemaRef.Context.getTypeDeclType(Enum);
770 }
John McCallfcc33b02009-09-05 00:15:47 +0000771
Mike Stump11289f42009-09-09 15:08:12 +0000772 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000773 ///
774 /// By default, performs semantic analysis when building the typeof type.
775 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000776 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000777
Mike Stump11289f42009-09-09 15:08:12 +0000778 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000779 ///
780 /// By default, builds a new TypeOfType with the given underlying type.
781 QualType RebuildTypeOfType(QualType Underlying);
782
Alexis Hunte852b102011-05-24 22:41:36 +0000783 /// \brief Build a new unary transform type.
784 QualType RebuildUnaryTransformType(QualType BaseType,
785 UnaryTransformType::UTTKind UKind,
786 SourceLocation Loc);
787
Richard Smith74aeef52013-04-26 16:15:35 +0000788 /// \brief Build a new C++11 decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000789 ///
790 /// By default, performs semantic analysis when building the decltype type.
791 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000792 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump11289f42009-09-09 15:08:12 +0000793
Richard Smith74aeef52013-04-26 16:15:35 +0000794 /// \brief Build a new C++11 auto type.
Richard Smith30482bc2011-02-20 03:19:35 +0000795 ///
796 /// By default, builds a new AutoType with the given deduced type.
Richard Smith74aeef52013-04-26 16:15:35 +0000797 QualType RebuildAutoType(QualType Deduced, bool IsDecltypeAuto) {
Richard Smith27d807c2013-04-30 13:56:41 +0000798 // Note, IsDependent is always false here: we implicitly convert an 'auto'
799 // which has been deduced to a dependent type into an undeduced 'auto', so
800 // that we'll retry deduction after the transformation.
Faisal Vali2b391ab2013-09-26 19:54:12 +0000801 return SemaRef.Context.getAutoType(Deduced, IsDecltypeAuto,
802 /*IsDependent*/ false);
Richard Smith30482bc2011-02-20 03:19:35 +0000803 }
804
Douglas Gregord6ff3322009-08-04 16:50:30 +0000805 /// \brief Build a new template specialization type.
806 ///
807 /// By default, performs semantic analysis when building the template
808 /// specialization type. Subclasses may override this routine to provide
809 /// different behavior.
810 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000811 SourceLocation TemplateLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000812 TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000813
Abramo Bagnara924a8f32010-12-10 16:29:40 +0000814 /// \brief Build a new parenthesized type.
815 ///
816 /// By default, builds a new ParenType type from the inner type.
817 /// Subclasses may override this routine to provide different behavior.
818 QualType RebuildParenType(QualType InnerType) {
819 return SemaRef.Context.getParenType(InnerType);
820 }
821
Douglas Gregord6ff3322009-08-04 16:50:30 +0000822 /// \brief Build a new qualified name type.
823 ///
Abramo Bagnara6150c882010-05-11 21:36:43 +0000824 /// By default, builds a new ElaboratedType type from the keyword,
825 /// the nested-name-specifier and the named type.
826 /// Subclasses may override this routine to provide different behavior.
John McCall954b5de2010-11-04 19:04:38 +0000827 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
828 ElaboratedTypeKeyword Keyword,
Douglas Gregor844cb502011-03-01 18:12:44 +0000829 NestedNameSpecifierLoc QualifierLoc,
830 QualType Named) {
Chad Rosier1dcde962012-08-08 18:46:20 +0000831 return SemaRef.Context.getElaboratedType(Keyword,
832 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor844cb502011-03-01 18:12:44 +0000833 Named);
Mike Stump11289f42009-09-09 15:08:12 +0000834 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000835
836 /// \brief Build a new typename type that refers to a template-id.
837 ///
Abramo Bagnarad7548482010-05-19 21:37:53 +0000838 /// By default, builds a new DependentNameType type from the
839 /// nested-name-specifier and the given type. Subclasses may override
840 /// this routine to provide different behavior.
John McCallc392f372010-06-11 00:33:02 +0000841 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregora7a795b2011-03-01 20:11:18 +0000842 ElaboratedTypeKeyword Keyword,
843 NestedNameSpecifierLoc QualifierLoc,
844 const IdentifierInfo *Name,
845 SourceLocation NameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000846 TemplateArgumentListInfo &Args) {
Douglas Gregora7a795b2011-03-01 20:11:18 +0000847 // Rebuild the template name.
848 // TODO: avoid TemplateName abstraction
Douglas Gregor9db53502011-03-02 18:07:45 +0000849 CXXScopeSpec SS;
850 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +0000851 TemplateName InstName
Douglas Gregor9db53502011-03-02 18:07:45 +0000852 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(), 0);
Chad Rosier1dcde962012-08-08 18:46:20 +0000853
Douglas Gregora7a795b2011-03-01 20:11:18 +0000854 if (InstName.isNull())
855 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +0000856
Douglas Gregora7a795b2011-03-01 20:11:18 +0000857 // If it's still dependent, make a dependent specialization.
858 if (InstName.getAsDependentTemplateName())
Chad Rosier1dcde962012-08-08 18:46:20 +0000859 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
860 QualifierLoc.getNestedNameSpecifier(),
861 Name,
Douglas Gregora7a795b2011-03-01 20:11:18 +0000862 Args);
Chad Rosier1dcde962012-08-08 18:46:20 +0000863
Douglas Gregora7a795b2011-03-01 20:11:18 +0000864 // Otherwise, make an elaborated type wrapping a non-dependent
865 // specialization.
866 QualType T =
867 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
868 if (T.isNull()) return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +0000869
Douglas Gregora7a795b2011-03-01 20:11:18 +0000870 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == 0)
871 return T;
Chad Rosier1dcde962012-08-08 18:46:20 +0000872
873 return SemaRef.Context.getElaboratedType(Keyword,
874 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregora7a795b2011-03-01 20:11:18 +0000875 T);
876 }
877
Douglas Gregord6ff3322009-08-04 16:50:30 +0000878 /// \brief Build a new typename type that refers to an identifier.
879 ///
880 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarad7548482010-05-19 21:37:53 +0000881 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000882 /// different behavior.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000883 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000884 SourceLocation KeywordLoc,
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000885 NestedNameSpecifierLoc QualifierLoc,
886 const IdentifierInfo *Id,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000887 SourceLocation IdLoc) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000888 CXXScopeSpec SS;
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000889 SS.Adopt(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +0000890
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000891 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000892 // If the name is still dependent, just build a new dependent name type.
893 if (!SemaRef.computeDeclContext(SS))
Chad Rosier1dcde962012-08-08 18:46:20 +0000894 return SemaRef.Context.getDependentNameType(Keyword,
895 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000896 Id);
Douglas Gregore677daf2010-03-31 22:19:08 +0000897 }
898
Abramo Bagnara6150c882010-05-11 21:36:43 +0000899 if (Keyword == ETK_None || Keyword == ETK_Typename)
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000900 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
Douglas Gregor9cbc22b2011-02-28 22:42:13 +0000901 *Id, IdLoc);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000902
903 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
904
Abramo Bagnarad7548482010-05-19 21:37:53 +0000905 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregore677daf2010-03-31 22:19:08 +0000906 // into a non-dependent elaborated-type-specifier. Find the tag we're
907 // referring to.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000908 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregore677daf2010-03-31 22:19:08 +0000909 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
910 if (!DC)
911 return QualType();
912
John McCallbf8c5192010-05-27 06:40:31 +0000913 if (SemaRef.RequireCompleteDeclContext(SS, DC))
914 return QualType();
915
Douglas Gregore677daf2010-03-31 22:19:08 +0000916 TagDecl *Tag = 0;
917 SemaRef.LookupQualifiedName(Result, DC);
918 switch (Result.getResultKind()) {
919 case LookupResult::NotFound:
920 case LookupResult::NotFoundInCurrentInstantiation:
921 break;
Chad Rosier1dcde962012-08-08 18:46:20 +0000922
Douglas Gregore677daf2010-03-31 22:19:08 +0000923 case LookupResult::Found:
924 Tag = Result.getAsSingle<TagDecl>();
925 break;
Chad Rosier1dcde962012-08-08 18:46:20 +0000926
Douglas Gregore677daf2010-03-31 22:19:08 +0000927 case LookupResult::FoundOverloaded:
928 case LookupResult::FoundUnresolvedValue:
929 llvm_unreachable("Tag lookup cannot find non-tags");
Chad Rosier1dcde962012-08-08 18:46:20 +0000930
Douglas Gregore677daf2010-03-31 22:19:08 +0000931 case LookupResult::Ambiguous:
932 // Let the LookupResult structure handle ambiguities.
933 return QualType();
934 }
935
936 if (!Tag) {
Nick Lewycky0c438082011-01-24 19:01:04 +0000937 // Check where the name exists but isn't a tag type and use that to emit
938 // better diagnostics.
939 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
940 SemaRef.LookupQualifiedName(Result, DC);
941 switch (Result.getResultKind()) {
942 case LookupResult::Found:
943 case LookupResult::FoundOverloaded:
944 case LookupResult::FoundUnresolvedValue: {
Richard Smith3f1b5d02011-05-05 21:57:07 +0000945 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
Nick Lewycky0c438082011-01-24 19:01:04 +0000946 unsigned Kind = 0;
947 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
Richard Smithdda56e42011-04-15 14:24:37 +0000948 else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2;
949 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3;
Nick Lewycky0c438082011-01-24 19:01:04 +0000950 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
951 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
952 break;
Richard Smith3f1b5d02011-05-05 21:57:07 +0000953 }
Nick Lewycky0c438082011-01-24 19:01:04 +0000954 default:
Nick Lewycky0c438082011-01-24 19:01:04 +0000955 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
Stephan Tolksdorfeb7708d2014-03-13 20:34:03 +0000956 << Kind << Id << DC << QualifierLoc.getSourceRange();
Nick Lewycky0c438082011-01-24 19:01:04 +0000957 break;
958 }
Douglas Gregore677daf2010-03-31 22:19:08 +0000959 return QualType();
960 }
Abramo Bagnara6150c882010-05-11 21:36:43 +0000961
Richard Trieucaa33d32011-06-10 03:11:26 +0000962 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
963 IdLoc, *Id)) {
Abramo Bagnarad7548482010-05-19 21:37:53 +0000964 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregore677daf2010-03-31 22:19:08 +0000965 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
966 return QualType();
967 }
968
969 // Build the elaborated-type-specifier type.
970 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Chad Rosier1dcde962012-08-08 18:46:20 +0000971 return SemaRef.Context.getElaboratedType(Keyword,
972 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000973 T);
Douglas Gregor1135c352009-08-06 05:28:30 +0000974 }
Mike Stump11289f42009-09-09 15:08:12 +0000975
Douglas Gregor822d0302011-01-12 17:07:58 +0000976 /// \brief Build a new pack expansion type.
977 ///
978 /// By default, builds a new PackExpansionType type from the given pattern.
979 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000980 QualType RebuildPackExpansionType(QualType Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +0000981 SourceRange PatternRange,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000982 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +0000983 Optional<unsigned> NumExpansions) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000984 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
985 NumExpansions);
Douglas Gregor822d0302011-01-12 17:07:58 +0000986 }
987
Eli Friedman0dfb8892011-10-06 23:00:33 +0000988 /// \brief Build a new atomic type given its value type.
989 ///
990 /// By default, performs semantic analysis when building the atomic type.
991 /// Subclasses may override this routine to provide different behavior.
992 QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
993
Douglas Gregor71dc5092009-08-06 06:41:21 +0000994 /// \brief Build a new template name given a nested name specifier, a flag
995 /// indicating whether the "template" keyword was provided, and the template
996 /// that the template name refers to.
997 ///
998 /// By default, builds the new template name directly. Subclasses may override
999 /// this routine to provide different behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001000 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +00001001 bool TemplateKW,
1002 TemplateDecl *Template);
1003
Douglas Gregor71dc5092009-08-06 06:41:21 +00001004 /// \brief Build a new template name given a nested name specifier and the
1005 /// name that is referred to as a template.
1006 ///
1007 /// By default, performs semantic analysis to determine whether the name can
1008 /// be resolved to a specific template, then builds the appropriate kind of
1009 /// template name. Subclasses may override this routine to provide different
1010 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001011 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
1012 const IdentifierInfo &Name,
1013 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +00001014 QualType ObjectType,
1015 NamedDecl *FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00001016
Douglas Gregor71395fa2009-11-04 00:56:37 +00001017 /// \brief Build a new template name given a nested name specifier and the
1018 /// overloaded operator name that is referred to as a template.
1019 ///
1020 /// By default, performs semantic analysis to determine whether the name can
1021 /// be resolved to a specific template, then builds the appropriate kind of
1022 /// template name. Subclasses may override this routine to provide different
1023 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001024 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +00001025 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +00001026 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +00001027 QualType ObjectType);
Douglas Gregor5590be02011-01-15 06:45:20 +00001028
1029 /// \brief Build a new template name given a template template parameter pack
Chad Rosier1dcde962012-08-08 18:46:20 +00001030 /// and the
Douglas Gregor5590be02011-01-15 06:45:20 +00001031 ///
1032 /// By default, performs semantic analysis to determine whether the name can
1033 /// be resolved to a specific template, then builds the appropriate kind of
1034 /// template name. Subclasses may override this routine to provide different
1035 /// behavior.
1036 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
1037 const TemplateArgument &ArgPack) {
1038 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
1039 }
1040
Douglas Gregorebe10102009-08-20 07:17:43 +00001041 /// \brief Build a new compound statement.
1042 ///
1043 /// By default, performs semantic analysis to build the new statement.
1044 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001045 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001046 MultiStmtArg Statements,
1047 SourceLocation RBraceLoc,
1048 bool IsStmtExpr) {
John McCallb268a282010-08-23 23:25:46 +00001049 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00001050 IsStmtExpr);
1051 }
1052
1053 /// \brief Build a new case statement.
1054 ///
1055 /// By default, performs semantic analysis to build the new statement.
1056 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001057 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCallb268a282010-08-23 23:25:46 +00001058 Expr *LHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001059 SourceLocation EllipsisLoc,
John McCallb268a282010-08-23 23:25:46 +00001060 Expr *RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001061 SourceLocation ColonLoc) {
John McCallb268a282010-08-23 23:25:46 +00001062 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001063 ColonLoc);
1064 }
Mike Stump11289f42009-09-09 15:08:12 +00001065
Douglas Gregorebe10102009-08-20 07:17:43 +00001066 /// \brief Attach the body to a new case statement.
1067 ///
1068 /// By default, performs semantic analysis to build the new statement.
1069 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001070 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001071 getSema().ActOnCaseStmtBody(S, Body);
1072 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00001073 }
Mike Stump11289f42009-09-09 15:08:12 +00001074
Douglas Gregorebe10102009-08-20 07:17:43 +00001075 /// \brief Build a new default statement.
1076 ///
1077 /// By default, performs semantic analysis to build the new statement.
1078 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001079 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001080 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +00001081 Stmt *SubStmt) {
1082 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregorebe10102009-08-20 07:17:43 +00001083 /*CurScope=*/0);
1084 }
Mike Stump11289f42009-09-09 15:08:12 +00001085
Douglas Gregorebe10102009-08-20 07:17:43 +00001086 /// \brief Build a new label statement.
1087 ///
1088 /// By default, performs semantic analysis to build the new statement.
1089 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001090 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1091 SourceLocation ColonLoc, Stmt *SubStmt) {
1092 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregorebe10102009-08-20 07:17:43 +00001093 }
Mike Stump11289f42009-09-09 15:08:12 +00001094
Richard Smithc202b282012-04-14 00:33:13 +00001095 /// \brief Build a new label statement.
1096 ///
1097 /// By default, performs semantic analysis to build the new statement.
1098 /// Subclasses may override this routine to provide different behavior.
Alexander Kornienko20f6fc62012-07-09 10:04:07 +00001099 StmtResult RebuildAttributedStmt(SourceLocation AttrLoc,
1100 ArrayRef<const Attr*> Attrs,
Richard Smithc202b282012-04-14 00:33:13 +00001101 Stmt *SubStmt) {
1102 return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt);
1103 }
1104
Douglas Gregorebe10102009-08-20 07:17:43 +00001105 /// \brief Build a new "if" statement.
1106 ///
1107 /// By default, performs semantic analysis to build the new statement.
1108 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001109 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Chad Rosier1dcde962012-08-08 18:46:20 +00001110 VarDecl *CondVar, Stmt *Then,
Chris Lattnercab02a62011-02-17 20:34:02 +00001111 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00001112 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregorebe10102009-08-20 07:17:43 +00001113 }
Mike Stump11289f42009-09-09 15:08:12 +00001114
Douglas Gregorebe10102009-08-20 07:17:43 +00001115 /// \brief Start building a new switch statement.
1116 ///
1117 /// By default, performs semantic analysis to build the new statement.
1118 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001119 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001120 Expr *Cond, VarDecl *CondVar) {
Chad Rosier1dcde962012-08-08 18:46:20 +00001121 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCall48871652010-08-21 09:40:31 +00001122 CondVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00001123 }
Mike Stump11289f42009-09-09 15:08:12 +00001124
Douglas Gregorebe10102009-08-20 07:17:43 +00001125 /// \brief Attach the body to the switch statement.
1126 ///
1127 /// By default, performs semantic analysis to build the new statement.
1128 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001129 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001130 Stmt *Switch, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001131 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001132 }
1133
1134 /// \brief Build a new while statement.
1135 ///
1136 /// By default, performs semantic analysis to build the new statement.
1137 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001138 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1139 VarDecl *CondVar, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001140 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001141 }
Mike Stump11289f42009-09-09 15:08:12 +00001142
Douglas Gregorebe10102009-08-20 07:17:43 +00001143 /// \brief Build a new do-while statement.
1144 ///
1145 /// By default, performs semantic analysis to build the new statement.
1146 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001147 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001148 SourceLocation WhileLoc, SourceLocation LParenLoc,
1149 Expr *Cond, SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001150 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1151 Cond, RParenLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001152 }
1153
1154 /// \brief Build a new for statement.
1155 ///
1156 /// By default, performs semantic analysis to build the new statement.
1157 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001158 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
Chad Rosier1dcde962012-08-08 18:46:20 +00001159 Stmt *Init, Sema::FullExprArg Cond,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001160 VarDecl *CondVar, Sema::FullExprArg Inc,
1161 SourceLocation RParenLoc, Stmt *Body) {
Chad Rosier1dcde962012-08-08 18:46:20 +00001162 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001163 CondVar, Inc, RParenLoc, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001164 }
Mike Stump11289f42009-09-09 15:08:12 +00001165
Douglas Gregorebe10102009-08-20 07:17:43 +00001166 /// \brief Build a new goto statement.
1167 ///
1168 /// By default, performs semantic analysis to build the new statement.
1169 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001170 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1171 LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001172 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregorebe10102009-08-20 07:17:43 +00001173 }
1174
1175 /// \brief Build a new indirect goto statement.
1176 ///
1177 /// By default, performs semantic analysis to build the new statement.
1178 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001179 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001180 SourceLocation StarLoc,
1181 Expr *Target) {
John McCallb268a282010-08-23 23:25:46 +00001182 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregorebe10102009-08-20 07:17:43 +00001183 }
Mike Stump11289f42009-09-09 15:08:12 +00001184
Douglas Gregorebe10102009-08-20 07:17:43 +00001185 /// \brief Build a new return statement.
1186 ///
1187 /// By default, performs semantic analysis to build the new statement.
1188 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001189 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
John McCallb268a282010-08-23 23:25:46 +00001190 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregorebe10102009-08-20 07:17:43 +00001191 }
Mike Stump11289f42009-09-09 15:08:12 +00001192
Douglas Gregorebe10102009-08-20 07:17:43 +00001193 /// \brief Build a new declaration statement.
1194 ///
1195 /// By default, performs semantic analysis to build the new statement.
1196 /// Subclasses may override this routine to provide different behavior.
Rafael Espindolaab417692013-07-09 12:05:01 +00001197 StmtResult RebuildDeclStmt(llvm::MutableArrayRef<Decl *> Decls,
1198 SourceLocation StartLoc, SourceLocation EndLoc) {
1199 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls);
Richard Smith2abf6762011-02-23 00:37:57 +00001200 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001201 }
Mike Stump11289f42009-09-09 15:08:12 +00001202
Anders Carlssonaaeef072010-01-24 05:50:09 +00001203 /// \brief Build a new inline asm statement.
1204 ///
1205 /// By default, performs semantic analysis to build the new statement.
1206 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001207 StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
1208 bool IsVolatile, unsigned NumOutputs,
1209 unsigned NumInputs, IdentifierInfo **Names,
1210 MultiExprArg Constraints, MultiExprArg Exprs,
1211 Expr *AsmString, MultiExprArg Clobbers,
1212 SourceLocation RParenLoc) {
1213 return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1214 NumInputs, Names, Constraints, Exprs,
1215 AsmString, Clobbers, RParenLoc);
Anders Carlssonaaeef072010-01-24 05:50:09 +00001216 }
Douglas Gregor306de2f2010-04-22 23:59:56 +00001217
Chad Rosier32503022012-06-11 20:47:18 +00001218 /// \brief Build a new MS style inline asm statement.
1219 ///
1220 /// By default, performs semantic analysis to build the new statement.
1221 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001222 StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc,
John McCallf413f5e2013-05-03 00:10:13 +00001223 ArrayRef<Token> AsmToks,
1224 StringRef AsmString,
1225 unsigned NumOutputs, unsigned NumInputs,
1226 ArrayRef<StringRef> Constraints,
1227 ArrayRef<StringRef> Clobbers,
1228 ArrayRef<Expr*> Exprs,
1229 SourceLocation EndLoc) {
1230 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString,
1231 NumOutputs, NumInputs,
1232 Constraints, Clobbers, Exprs, EndLoc);
Chad Rosier32503022012-06-11 20:47:18 +00001233 }
1234
James Dennett2a4d13c2012-06-15 07:13:21 +00001235 /// \brief Build a new Objective-C \@try statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001236 ///
1237 /// By default, performs semantic analysis to build the new statement.
1238 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001239 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001240 Stmt *TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +00001241 MultiStmtArg CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001242 Stmt *Finally) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001243 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001244 Finally);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001245 }
1246
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001247 /// \brief Rebuild an Objective-C exception declaration.
1248 ///
1249 /// By default, performs semantic analysis to build the new declaration.
1250 /// Subclasses may override this routine to provide different behavior.
1251 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1252 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaradff19302011-03-08 08:55:46 +00001253 return getSema().BuildObjCExceptionDecl(TInfo, T,
1254 ExceptionDecl->getInnerLocStart(),
1255 ExceptionDecl->getLocation(),
1256 ExceptionDecl->getIdentifier());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001257 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001258
James Dennett2a4d13c2012-06-15 07:13:21 +00001259 /// \brief Build a new Objective-C \@catch statement.
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001260 ///
1261 /// By default, performs semantic analysis to build the new statement.
1262 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001263 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001264 SourceLocation RParenLoc,
1265 VarDecl *Var,
John McCallb268a282010-08-23 23:25:46 +00001266 Stmt *Body) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001267 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001268 Var, Body);
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001269 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001270
James Dennett2a4d13c2012-06-15 07:13:21 +00001271 /// \brief Build a new Objective-C \@finally statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001272 ///
1273 /// By default, performs semantic analysis to build the new statement.
1274 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001275 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001276 Stmt *Body) {
1277 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001278 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001279
James Dennett2a4d13c2012-06-15 07:13:21 +00001280 /// \brief Build a new Objective-C \@throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +00001281 ///
1282 /// By default, performs semantic analysis to build the new statement.
1283 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001284 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001285 Expr *Operand) {
1286 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregor2900c162010-04-22 21:44:01 +00001287 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001288
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001289 /// \brief Build a new OpenMP executable directive.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001290 ///
1291 /// By default, performs semantic analysis to build the new statement.
1292 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001293 StmtResult RebuildOMPExecutableDirective(OpenMPDirectiveKind Kind,
1294 ArrayRef<OMPClause *> Clauses,
1295 Stmt *AStmt,
1296 SourceLocation StartLoc,
1297 SourceLocation EndLoc) {
1298 return getSema().ActOnOpenMPExecutableDirective(Kind, Clauses, AStmt,
1299 StartLoc, EndLoc);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001300 }
1301
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001302 /// \brief Build a new OpenMP 'if' clause.
1303 ///
1304 /// By default, performs semantic analysis to build the new statement.
1305 /// Subclasses may override this routine to provide different behavior.
1306 OMPClause *RebuildOMPIfClause(Expr *Condition,
1307 SourceLocation StartLoc,
1308 SourceLocation LParenLoc,
1309 SourceLocation EndLoc) {
1310 return getSema().ActOnOpenMPIfClause(Condition, StartLoc,
1311 LParenLoc, EndLoc);
1312 }
1313
Alexey Bataev568a8332014-03-06 06:15:19 +00001314 /// \brief Build a new OpenMP 'num_threads' clause.
1315 ///
1316 /// By default, performs semantic analysis to build the new statement.
1317 /// Subclasses may override this routine to provide different behavior.
1318 OMPClause *RebuildOMPNumThreadsClause(Expr *NumThreads,
1319 SourceLocation StartLoc,
1320 SourceLocation LParenLoc,
1321 SourceLocation EndLoc) {
1322 return getSema().ActOnOpenMPNumThreadsClause(NumThreads, StartLoc,
1323 LParenLoc, EndLoc);
1324 }
1325
Alexey Bataev62c87d22014-03-21 04:51:18 +00001326 /// \brief Build a new OpenMP 'safelen' clause.
1327 ///
1328 /// By default, performs semantic analysis to build the new statement.
1329 /// Subclasses may override this routine to provide different behavior.
1330 OMPClause *RebuildOMPSafelenClause(Expr *Len, SourceLocation StartLoc,
1331 SourceLocation LParenLoc,
1332 SourceLocation EndLoc) {
1333 return getSema().ActOnOpenMPSafelenClause(Len, StartLoc, LParenLoc, EndLoc);
1334 }
1335
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001336 /// \brief Build a new OpenMP 'default' clause.
1337 ///
1338 /// By default, performs semantic analysis to build the new statement.
1339 /// Subclasses may override this routine to provide different behavior.
1340 OMPClause *RebuildOMPDefaultClause(OpenMPDefaultClauseKind Kind,
1341 SourceLocation KindKwLoc,
1342 SourceLocation StartLoc,
1343 SourceLocation LParenLoc,
1344 SourceLocation EndLoc) {
1345 return getSema().ActOnOpenMPDefaultClause(Kind, KindKwLoc,
1346 StartLoc, LParenLoc, EndLoc);
1347 }
1348
1349 /// \brief Build a new OpenMP 'private' clause.
1350 ///
1351 /// By default, performs semantic analysis to build the new statement.
1352 /// Subclasses may override this routine to provide different behavior.
1353 OMPClause *RebuildOMPPrivateClause(ArrayRef<Expr *> VarList,
1354 SourceLocation StartLoc,
1355 SourceLocation LParenLoc,
1356 SourceLocation EndLoc) {
1357 return getSema().ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc,
1358 EndLoc);
1359 }
1360
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001361 /// \brief Build a new OpenMP 'firstprivate' clause.
1362 ///
1363 /// By default, performs semantic analysis to build the new statement.
1364 /// Subclasses may override this routine to provide different behavior.
1365 OMPClause *RebuildOMPFirstprivateClause(ArrayRef<Expr *> VarList,
1366 SourceLocation StartLoc,
1367 SourceLocation LParenLoc,
1368 SourceLocation EndLoc) {
1369 return getSema().ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc,
1370 EndLoc);
1371 }
1372
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001373 /// \brief Build a new OpenMP 'shared' clause.
1374 ///
1375 /// By default, performs semantic analysis to build the new statement.
1376 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev758e55e2013-09-06 18:03:48 +00001377 OMPClause *RebuildOMPSharedClause(ArrayRef<Expr *> VarList,
1378 SourceLocation StartLoc,
1379 SourceLocation LParenLoc,
1380 SourceLocation EndLoc) {
1381 return getSema().ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc,
1382 EndLoc);
1383 }
1384
Alexander Musman8dba6642014-04-22 13:09:42 +00001385 /// \brief Build a new OpenMP 'linear' clause.
1386 ///
1387 /// By default, performs semantic analysis to build the new statement.
1388 /// Subclasses may override this routine to provide different behavior.
1389 OMPClause *RebuildOMPLinearClause(ArrayRef<Expr *> VarList, Expr *Step,
1390 SourceLocation StartLoc,
1391 SourceLocation LParenLoc,
1392 SourceLocation ColonLoc,
1393 SourceLocation EndLoc) {
1394 return getSema().ActOnOpenMPLinearClause(VarList, Step, StartLoc, LParenLoc,
1395 ColonLoc, EndLoc);
1396 }
1397
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001398 /// \brief Build a new OpenMP 'copyin' clause.
1399 ///
1400 /// By default, performs semantic analysis to build the new statement.
1401 /// Subclasses may override this routine to provide different behavior.
1402 OMPClause *RebuildOMPCopyinClause(ArrayRef<Expr *> VarList,
1403 SourceLocation StartLoc,
1404 SourceLocation LParenLoc,
1405 SourceLocation EndLoc) {
1406 return getSema().ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc,
1407 EndLoc);
1408 }
1409
James Dennett2a4d13c2012-06-15 07:13:21 +00001410 /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
John McCalld9bb7432011-07-27 21:50:02 +00001411 ///
1412 /// By default, performs semantic analysis to build the new statement.
1413 /// Subclasses may override this routine to provide different behavior.
1414 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1415 Expr *object) {
1416 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1417 }
1418
James Dennett2a4d13c2012-06-15 07:13:21 +00001419 /// \brief Build a new Objective-C \@synchronized statement.
Douglas Gregor6148de72010-04-22 22:01:21 +00001420 ///
Douglas Gregor6148de72010-04-22 22:01:21 +00001421 /// By default, performs semantic analysis to build the new statement.
1422 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001423 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCalld9bb7432011-07-27 21:50:02 +00001424 Expr *Object, Stmt *Body) {
1425 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor6148de72010-04-22 22:01:21 +00001426 }
Douglas Gregorf68a5082010-04-22 23:10:45 +00001427
James Dennett2a4d13c2012-06-15 07:13:21 +00001428 /// \brief Build a new Objective-C \@autoreleasepool statement.
John McCall31168b02011-06-15 23:02:42 +00001429 ///
1430 /// By default, performs semantic analysis to build the new statement.
1431 /// Subclasses may override this routine to provide different behavior.
1432 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1433 Stmt *Body) {
1434 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1435 }
John McCall53848232011-07-27 01:07:15 +00001436
Douglas Gregorf68a5082010-04-22 23:10:45 +00001437 /// \brief Build a new Objective-C fast enumeration statement.
1438 ///
1439 /// By default, performs semantic analysis to build the new statement.
1440 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001441 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001442 Stmt *Element,
1443 Expr *Collection,
1444 SourceLocation RParenLoc,
1445 Stmt *Body) {
Sam Panzer2c4ca0f2012-08-16 21:47:25 +00001446 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001447 Element,
John McCallb268a282010-08-23 23:25:46 +00001448 Collection,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001449 RParenLoc);
1450 if (ForEachStmt.isInvalid())
1451 return StmtError();
1452
1453 return getSema().FinishObjCForCollectionStmt(ForEachStmt.take(), Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +00001454 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001455
Douglas Gregorebe10102009-08-20 07:17:43 +00001456 /// \brief Build a new C++ exception declaration.
1457 ///
1458 /// By default, performs semantic analysis to build the new decaration.
1459 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaradff19302011-03-08 08:55:46 +00001460 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +00001461 TypeSourceInfo *Declarator,
Abramo Bagnaradff19302011-03-08 08:55:46 +00001462 SourceLocation StartLoc,
1463 SourceLocation IdLoc,
1464 IdentifierInfo *Id) {
Douglas Gregor40965fa2011-04-14 22:32:28 +00001465 VarDecl *Var = getSema().BuildExceptionDeclaration(0, Declarator,
1466 StartLoc, IdLoc, Id);
1467 if (Var)
1468 getSema().CurContext->addDecl(Var);
1469 return Var;
Douglas Gregorebe10102009-08-20 07:17:43 +00001470 }
1471
1472 /// \brief Build a new C++ catch statement.
1473 ///
1474 /// By default, performs semantic analysis to build the new statement.
1475 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001476 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001477 VarDecl *ExceptionDecl,
1478 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00001479 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1480 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00001481 }
Mike Stump11289f42009-09-09 15:08:12 +00001482
Douglas Gregorebe10102009-08-20 07:17:43 +00001483 /// \brief Build a new C++ try statement.
1484 ///
1485 /// By default, performs semantic analysis to build the new statement.
1486 /// Subclasses may override this routine to provide different behavior.
Robert Wilhelmcafda822013-08-22 09:20:03 +00001487 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock,
1488 ArrayRef<Stmt *> Handlers) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001489 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00001490 }
Mike Stump11289f42009-09-09 15:08:12 +00001491
Richard Smith02e85f32011-04-14 22:09:26 +00001492 /// \brief Build a new C++0x range-based for statement.
1493 ///
1494 /// By default, performs semantic analysis to build the new statement.
1495 /// Subclasses may override this routine to provide different behavior.
1496 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1497 SourceLocation ColonLoc,
1498 Stmt *Range, Stmt *BeginEnd,
1499 Expr *Cond, Expr *Inc,
1500 Stmt *LoopVar,
1501 SourceLocation RParenLoc) {
Douglas Gregorf7106af2013-04-08 18:40:13 +00001502 // If we've just learned that the range is actually an Objective-C
1503 // collection, treat this as an Objective-C fast enumeration loop.
1504 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
1505 if (RangeStmt->isSingleDecl()) {
1506 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
Douglas Gregor39aaeef2013-05-02 18:35:56 +00001507 if (RangeVar->isInvalidDecl())
1508 return StmtError();
1509
Douglas Gregorf7106af2013-04-08 18:40:13 +00001510 Expr *RangeExpr = RangeVar->getInit();
1511 if (!RangeExpr->isTypeDependent() &&
1512 RangeExpr->getType()->isObjCObjectPointerType())
1513 return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, RangeExpr,
1514 RParenLoc);
1515 }
1516 }
1517 }
1518
Richard Smith02e85f32011-04-14 22:09:26 +00001519 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
Richard Smitha05b3b52012-09-20 21:52:32 +00001520 Cond, Inc, LoopVar, RParenLoc,
1521 Sema::BFRK_Rebuild);
Richard Smith02e85f32011-04-14 22:09:26 +00001522 }
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001523
1524 /// \brief Build a new C++0x range-based for statement.
1525 ///
1526 /// By default, performs semantic analysis to build the new statement.
1527 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00001528 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001529 bool IsIfExists,
1530 NestedNameSpecifierLoc QualifierLoc,
1531 DeclarationNameInfo NameInfo,
1532 Stmt *Nested) {
1533 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1534 QualifierLoc, NameInfo, Nested);
1535 }
1536
Richard Smith02e85f32011-04-14 22:09:26 +00001537 /// \brief Attach body to a C++0x range-based for statement.
1538 ///
1539 /// By default, performs semantic analysis to finish the new statement.
1540 /// Subclasses may override this routine to provide different behavior.
1541 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1542 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1543 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001544
David Majnemerfad8f482013-10-15 09:33:02 +00001545 StmtResult RebuildSEHTryStmt(bool IsCXXTry, SourceLocation TryLoc,
1546 Stmt *TryBlock, Stmt *Handler) {
1547 return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +00001548 }
1549
David Majnemerfad8f482013-10-15 09:33:02 +00001550 StmtResult RebuildSEHExceptStmt(SourceLocation Loc, Expr *FilterExpr,
John Wiegley1c0675e2011-04-28 01:08:34 +00001551 Stmt *Block) {
David Majnemerfad8f482013-10-15 09:33:02 +00001552 return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001553 }
1554
David Majnemerfad8f482013-10-15 09:33:02 +00001555 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, Stmt *Block) {
1556 return getSema().ActOnSEHFinallyBlock(Loc, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001557 }
1558
Douglas Gregora16548e2009-08-11 05:31:07 +00001559 /// \brief Build a new expression that references a declaration.
1560 ///
1561 /// By default, performs semantic analysis to build the new expression.
1562 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001563 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00001564 LookupResult &R,
1565 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00001566 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1567 }
1568
1569
1570 /// \brief Build a new expression that references a declaration.
1571 ///
1572 /// By default, performs semantic analysis to build the new expression.
1573 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorea972d32011-02-28 21:54:11 +00001574 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001575 ValueDecl *VD,
1576 const DeclarationNameInfo &NameInfo,
1577 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001578 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001579 SS.Adopt(QualifierLoc);
John McCallce546572009-12-08 09:08:17 +00001580
1581 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001582
1583 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001584 }
Mike Stump11289f42009-09-09 15:08:12 +00001585
Douglas Gregora16548e2009-08-11 05:31:07 +00001586 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001587 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001588 /// By default, performs semantic analysis to build the new expression.
1589 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001590 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00001591 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00001592 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001593 }
1594
Douglas Gregorad8a3362009-09-04 17:36:40 +00001595 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001596 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001597 /// By default, performs semantic analysis to build the new expression.
1598 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001599 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora6ce6082011-02-25 18:19:59 +00001600 SourceLocation OperatorLoc,
1601 bool isArrow,
1602 CXXScopeSpec &SS,
1603 TypeSourceInfo *ScopeType,
1604 SourceLocation CCLoc,
1605 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001606 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001607
Douglas Gregora16548e2009-08-11 05:31:07 +00001608 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001609 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001610 /// By default, performs semantic analysis to build the new expression.
1611 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001612 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001613 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001614 Expr *SubExpr) {
1615 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001616 }
Mike Stump11289f42009-09-09 15:08:12 +00001617
Douglas Gregor882211c2010-04-28 22:16:22 +00001618 /// \brief Build a new builtin offsetof expression.
1619 ///
1620 /// By default, performs semantic analysis to build the new expression.
1621 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001622 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor882211c2010-04-28 22:16:22 +00001623 TypeSourceInfo *Type,
John McCallfaf5fb42010-08-26 23:41:50 +00001624 Sema::OffsetOfComponent *Components,
Douglas Gregor882211c2010-04-28 22:16:22 +00001625 unsigned NumComponents,
1626 SourceLocation RParenLoc) {
1627 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1628 NumComponents, RParenLoc);
1629 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001630
1631 /// \brief Build a new sizeof, alignof or vec_step expression with a
Peter Collingbournee190dee2011-03-11 19:24:49 +00001632 /// type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001633 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001634 /// By default, performs semantic analysis to build the new expression.
1635 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001636 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1637 SourceLocation OpLoc,
1638 UnaryExprOrTypeTrait ExprKind,
1639 SourceRange R) {
1640 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001641 }
1642
Peter Collingbournee190dee2011-03-11 19:24:49 +00001643 /// \brief Build a new sizeof, alignof or vec step expression with an
1644 /// expression argument.
Mike Stump11289f42009-09-09 15:08:12 +00001645 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001646 /// By default, performs semantic analysis to build the new expression.
1647 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001648 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1649 UnaryExprOrTypeTrait ExprKind,
1650 SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00001651 ExprResult Result
Chandler Carrutha923fb22011-05-29 07:32:14 +00001652 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregora16548e2009-08-11 05:31:07 +00001653 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001654 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001655
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001656 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001657 }
Mike Stump11289f42009-09-09 15:08:12 +00001658
Douglas Gregora16548e2009-08-11 05:31:07 +00001659 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001660 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001661 /// By default, performs semantic analysis to build the new expression.
1662 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001663 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001664 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00001665 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001666 SourceLocation RBracketLoc) {
John McCallb268a282010-08-23 23:25:46 +00001667 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1668 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001669 RBracketLoc);
1670 }
1671
1672 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00001673 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001674 /// By default, performs semantic analysis to build the new expression.
1675 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001676 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001677 MultiExprArg Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00001678 SourceLocation RParenLoc,
1679 Expr *ExecConfig = 0) {
John McCallb268a282010-08-23 23:25:46 +00001680 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001681 Args, RParenLoc, ExecConfig);
Douglas Gregora16548e2009-08-11 05:31:07 +00001682 }
1683
1684 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001685 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001686 /// By default, performs semantic analysis to build the new expression.
1687 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001688 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001689 bool isArrow,
Douglas Gregorea972d32011-02-28 21:54:11 +00001690 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001691 SourceLocation TemplateKWLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001692 const DeclarationNameInfo &MemberNameInfo,
1693 ValueDecl *Member,
1694 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001695 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00001696 NamedDecl *FirstQualifierInScope) {
Richard Smithcab9a7d2011-10-26 19:06:56 +00001697 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
1698 isArrow);
Anders Carlsson5da84842009-09-01 04:26:58 +00001699 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00001700 // We have a reference to an unnamed field. This is always the
1701 // base of an anonymous struct/union member access, i.e. the
1702 // field is always of record type.
Douglas Gregorea972d32011-02-28 21:54:11 +00001703 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCall7decc9e2010-11-18 06:31:45 +00001704 assert(Member->getType()->isRecordType() &&
1705 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00001706
Richard Smithcab9a7d2011-10-26 19:06:56 +00001707 BaseResult =
1708 getSema().PerformObjectMemberConversion(BaseResult.take(),
John Wiegley01296292011-04-08 18:41:53 +00001709 QualifierLoc.getNestedNameSpecifier(),
1710 FoundDecl, Member);
1711 if (BaseResult.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001712 return ExprError();
John Wiegley01296292011-04-08 18:41:53 +00001713 Base = BaseResult.take();
John McCall7decc9e2010-11-18 06:31:45 +00001714 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump11289f42009-09-09 15:08:12 +00001715 MemberExpr *ME =
John McCallb268a282010-08-23 23:25:46 +00001716 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001717 Member, MemberNameInfo,
John McCall7decc9e2010-11-18 06:31:45 +00001718 cast<FieldDecl>(Member)->getType(),
1719 VK, OK_Ordinary);
Anders Carlsson5da84842009-09-01 04:26:58 +00001720 return getSema().Owned(ME);
1721 }
Mike Stump11289f42009-09-09 15:08:12 +00001722
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001723 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001724 SS.Adopt(QualifierLoc);
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001725
John Wiegley01296292011-04-08 18:41:53 +00001726 Base = BaseResult.take();
John McCallb268a282010-08-23 23:25:46 +00001727 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00001728
John McCall16df1e52010-03-30 21:47:33 +00001729 // FIXME: this involves duplicating earlier analysis in a lot of
1730 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001731 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001732 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001733 R.resolveKind();
1734
John McCallb268a282010-08-23 23:25:46 +00001735 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001736 SS, TemplateKWLoc,
1737 FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001738 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001739 }
Mike Stump11289f42009-09-09 15:08:12 +00001740
Douglas Gregora16548e2009-08-11 05:31:07 +00001741 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001742 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001743 /// By default, performs semantic analysis to build the new expression.
1744 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001745 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001746 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001747 Expr *LHS, Expr *RHS) {
1748 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001749 }
1750
1751 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001752 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001753 /// By default, performs semantic analysis to build the new expression.
1754 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001755 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCallc07a0c72011-02-17 10:25:35 +00001756 SourceLocation QuestionLoc,
1757 Expr *LHS,
1758 SourceLocation ColonLoc,
1759 Expr *RHS) {
John McCallb268a282010-08-23 23:25:46 +00001760 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1761 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001762 }
1763
Douglas Gregora16548e2009-08-11 05:31:07 +00001764 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001765 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001766 /// By default, performs semantic analysis to build the new expression.
1767 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001768 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00001769 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001770 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001771 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001772 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001773 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001774 }
Mike Stump11289f42009-09-09 15:08:12 +00001775
Douglas Gregora16548e2009-08-11 05:31:07 +00001776 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001777 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001778 /// By default, performs semantic analysis to build the new expression.
1779 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001780 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001781 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001782 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001783 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001784 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001785 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001786 }
Mike Stump11289f42009-09-09 15:08:12 +00001787
Douglas Gregora16548e2009-08-11 05:31:07 +00001788 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001789 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001790 /// By default, performs semantic analysis to build the new expression.
1791 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001792 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001793 SourceLocation OpLoc,
1794 SourceLocation AccessorLoc,
1795 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001796
John McCall10eae182009-11-30 22:42:35 +00001797 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001798 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00001799 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00001800 OpLoc, /*IsArrow*/ false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001801 SS, SourceLocation(),
1802 /*FirstQualifierInScope*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001803 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00001804 /* TemplateArgs */ 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00001805 }
Mike Stump11289f42009-09-09 15:08:12 +00001806
Douglas Gregora16548e2009-08-11 05:31:07 +00001807 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001808 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001809 /// By default, performs semantic analysis to build the new expression.
1810 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001811 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCall542e7c62011-07-06 07:30:07 +00001812 MultiExprArg Inits,
1813 SourceLocation RBraceLoc,
1814 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00001815 ExprResult Result
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001816 = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
Douglas Gregord3d93062009-11-09 17:16:50 +00001817 if (Result.isInvalid() || ResultTy->isDependentType())
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001818 return Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00001819
Douglas Gregord3d93062009-11-09 17:16:50 +00001820 // Patch in the result type we were given, which may have been computed
1821 // when the initial InitListExpr was built.
1822 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1823 ILE->setType(ResultTy);
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001824 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001825 }
Mike Stump11289f42009-09-09 15:08:12 +00001826
Douglas Gregora16548e2009-08-11 05:31:07 +00001827 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001828 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001829 /// By default, performs semantic analysis to build the new expression.
1830 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001831 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00001832 MultiExprArg ArrayExprs,
1833 SourceLocation EqualOrColonLoc,
1834 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001835 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00001836 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001837 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001838 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001839 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001840 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001841
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001842 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001843 }
Mike Stump11289f42009-09-09 15:08:12 +00001844
Douglas Gregora16548e2009-08-11 05:31:07 +00001845 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001846 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001847 /// By default, builds the implicit value initialization without performing
1848 /// any semantic analysis. Subclasses may override this routine to provide
1849 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001850 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001851 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1852 }
Mike Stump11289f42009-09-09 15:08:12 +00001853
Douglas Gregora16548e2009-08-11 05:31:07 +00001854 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001855 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001856 /// By default, performs semantic analysis to build the new expression.
1857 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001858 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001859 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001860 SourceLocation RParenLoc) {
1861 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001862 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001863 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001864 }
1865
1866 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001867 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001868 /// By default, performs semantic analysis to build the new expression.
1869 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001870 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redla9351792012-02-11 23:51:47 +00001871 MultiExprArg SubExprs,
1872 SourceLocation RParenLoc) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001873 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001874 }
Mike Stump11289f42009-09-09 15:08:12 +00001875
Douglas Gregora16548e2009-08-11 05:31:07 +00001876 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001877 ///
1878 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00001879 /// rather than attempting to map the label statement itself.
1880 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001881 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001882 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001883 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregora16548e2009-08-11 05:31:07 +00001884 }
Mike Stump11289f42009-09-09 15:08:12 +00001885
Douglas Gregora16548e2009-08-11 05:31:07 +00001886 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00001887 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001888 /// By default, performs semantic analysis to build the new expression.
1889 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001890 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001891 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00001892 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001893 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001894 }
Mike Stump11289f42009-09-09 15:08:12 +00001895
Douglas Gregora16548e2009-08-11 05:31:07 +00001896 /// \brief Build a new __builtin_choose_expr expression.
1897 ///
1898 /// By default, performs semantic analysis to build the new expression.
1899 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001900 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001901 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001902 SourceLocation RParenLoc) {
1903 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001904 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001905 RParenLoc);
1906 }
Mike Stump11289f42009-09-09 15:08:12 +00001907
Peter Collingbourne91147592011-04-15 00:35:48 +00001908 /// \brief Build a new generic selection expression.
1909 ///
1910 /// By default, performs semantic analysis to build the new expression.
1911 /// Subclasses may override this routine to provide different behavior.
1912 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
1913 SourceLocation DefaultLoc,
1914 SourceLocation RParenLoc,
1915 Expr *ControllingExpr,
Dmitri Gribenko82360372013-05-10 13:06:58 +00001916 ArrayRef<TypeSourceInfo *> Types,
1917 ArrayRef<Expr *> Exprs) {
Peter Collingbourne91147592011-04-15 00:35:48 +00001918 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
Dmitri Gribenko82360372013-05-10 13:06:58 +00001919 ControllingExpr, Types, Exprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00001920 }
1921
Douglas Gregora16548e2009-08-11 05:31:07 +00001922 /// \brief Build a new overloaded operator call expression.
1923 ///
1924 /// By default, performs semantic analysis to build the new expression.
1925 /// The semantic analysis provides the behavior of template instantiation,
1926 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00001927 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00001928 /// argument-dependent lookup, etc. Subclasses may override this routine to
1929 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001930 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00001931 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00001932 Expr *Callee,
1933 Expr *First,
1934 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00001935
1936 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00001937 /// reinterpret_cast.
1938 ///
1939 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00001940 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00001941 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001942 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001943 Stmt::StmtClass Class,
1944 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001945 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001946 SourceLocation RAngleLoc,
1947 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001948 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001949 SourceLocation RParenLoc) {
1950 switch (Class) {
1951 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001952 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001953 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001954 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001955
1956 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001957 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001958 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001959 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001960
Douglas Gregora16548e2009-08-11 05:31:07 +00001961 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001962 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001963 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001964 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001965 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001966
Douglas Gregora16548e2009-08-11 05:31:07 +00001967 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001968 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001969 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001970 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001971
Douglas Gregora16548e2009-08-11 05:31:07 +00001972 default:
David Blaikie83d382b2011-09-23 05:06:16 +00001973 llvm_unreachable("Invalid C++ named cast");
Douglas Gregora16548e2009-08-11 05:31:07 +00001974 }
Douglas Gregora16548e2009-08-11 05:31:07 +00001975 }
Mike Stump11289f42009-09-09 15:08:12 +00001976
Douglas Gregora16548e2009-08-11 05:31:07 +00001977 /// \brief Build a new C++ static_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 RebuildCXXStaticCastExpr(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_static_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++ dynamic_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 RebuildCXXDynamicCastExpr(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_dynamic_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 }
2010
2011 /// \brief Build a new C++ reinterpret_cast expression.
2012 ///
2013 /// By default, performs semantic analysis to build the new expression.
2014 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002015 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002016 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002017 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002018 SourceLocation RAngleLoc,
2019 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002020 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002021 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002022 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00002023 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002024 SourceRange(LAngleLoc, RAngleLoc),
2025 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002026 }
2027
2028 /// \brief Build a new C++ const_cast expression.
2029 ///
2030 /// By default, performs semantic analysis to build the new expression.
2031 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002032 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002033 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002034 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002035 SourceLocation RAngleLoc,
2036 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002037 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002038 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002039 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00002040 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002041 SourceRange(LAngleLoc, RAngleLoc),
2042 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002043 }
Mike Stump11289f42009-09-09 15:08:12 +00002044
Douglas Gregora16548e2009-08-11 05:31:07 +00002045 /// \brief Build a new C++ functional-style cast expression.
2046 ///
2047 /// By default, performs semantic analysis to build the new expression.
2048 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002049 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
2050 SourceLocation LParenLoc,
2051 Expr *Sub,
2052 SourceLocation RParenLoc) {
2053 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00002054 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00002055 RParenLoc);
2056 }
Mike Stump11289f42009-09-09 15:08:12 +00002057
Douglas Gregora16548e2009-08-11 05:31:07 +00002058 /// \brief Build a new C++ typeid(type) expression.
2059 ///
2060 /// By default, performs semantic analysis to build the new expression.
2061 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002062 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002063 SourceLocation TypeidLoc,
2064 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002065 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002066 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002067 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002068 }
Mike Stump11289f42009-09-09 15:08:12 +00002069
Francois Pichet9f4f2072010-09-08 12:20:18 +00002070
Douglas Gregora16548e2009-08-11 05:31:07 +00002071 /// \brief Build a new C++ typeid(expr) expression.
2072 ///
2073 /// By default, performs semantic analysis to build the new expression.
2074 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002075 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002076 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00002077 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002078 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002079 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002080 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002081 }
2082
Francois Pichet9f4f2072010-09-08 12:20:18 +00002083 /// \brief Build a new C++ __uuidof(type) expression.
2084 ///
2085 /// By default, performs semantic analysis to build the new expression.
2086 /// Subclasses may override this routine to provide different behavior.
2087 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2088 SourceLocation TypeidLoc,
2089 TypeSourceInfo *Operand,
2090 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002091 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
Francois Pichet9f4f2072010-09-08 12:20:18 +00002092 RParenLoc);
2093 }
2094
2095 /// \brief Build a new C++ __uuidof(expr) expression.
2096 ///
2097 /// By default, performs semantic analysis to build the new expression.
2098 /// Subclasses may override this routine to provide different behavior.
2099 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2100 SourceLocation TypeidLoc,
2101 Expr *Operand,
2102 SourceLocation RParenLoc) {
2103 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
2104 RParenLoc);
2105 }
2106
Douglas Gregora16548e2009-08-11 05:31:07 +00002107 /// \brief Build a new C++ "this" expression.
2108 ///
2109 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00002110 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00002111 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002112 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00002113 QualType ThisType,
2114 bool isImplicit) {
Eli Friedman20139d32012-01-11 02:36:31 +00002115 getSema().CheckCXXThisCapture(ThisLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002116 return getSema().Owned(
Douglas Gregorb15af892010-01-07 23:12:05 +00002117 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
2118 isImplicit));
Douglas Gregora16548e2009-08-11 05:31:07 +00002119 }
2120
2121 /// \brief Build a new C++ throw expression.
2122 ///
2123 /// By default, performs semantic analysis to build the new expression.
2124 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor53e191ed2011-07-06 22:04:06 +00002125 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
2126 bool IsThrownVariableInScope) {
2127 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00002128 }
2129
2130 /// \brief Build a new C++ default-argument expression.
2131 ///
2132 /// By default, builds a new default-argument expression, which does not
2133 /// require any semantic analysis. Subclasses may override this routine to
2134 /// provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002135 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00002136 ParmVarDecl *Param) {
2137 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
2138 Param));
Douglas Gregora16548e2009-08-11 05:31:07 +00002139 }
2140
Richard Smith852c9db2013-04-20 22:23:05 +00002141 /// \brief Build a new C++11 default-initialization expression.
2142 ///
2143 /// By default, builds a new default field initialization expression, which
2144 /// does not require any semantic analysis. Subclasses may override this
2145 /// routine to provide different behavior.
2146 ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc,
2147 FieldDecl *Field) {
2148 return getSema().Owned(CXXDefaultInitExpr::Create(getSema().Context, Loc,
2149 Field));
2150 }
2151
Douglas Gregora16548e2009-08-11 05:31:07 +00002152 /// \brief Build a new C++ zero-initialization expression.
2153 ///
2154 /// By default, performs semantic analysis to build the new expression.
2155 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002156 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
2157 SourceLocation LParenLoc,
2158 SourceLocation RParenLoc) {
2159 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002160 None, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002161 }
Mike Stump11289f42009-09-09 15:08:12 +00002162
Douglas Gregora16548e2009-08-11 05:31:07 +00002163 /// \brief Build a new C++ "new" expression.
2164 ///
2165 /// By default, performs semantic analysis to build the new expression.
2166 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002167 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002168 bool UseGlobal,
2169 SourceLocation PlacementLParen,
2170 MultiExprArg PlacementArgs,
2171 SourceLocation PlacementRParen,
2172 SourceRange TypeIdParens,
2173 QualType AllocatedType,
2174 TypeSourceInfo *AllocatedTypeInfo,
2175 Expr *ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002176 SourceRange DirectInitRange,
2177 Expr *Initializer) {
Mike Stump11289f42009-09-09 15:08:12 +00002178 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00002179 PlacementLParen,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002180 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00002181 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00002182 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002183 AllocatedType,
2184 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00002185 ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002186 DirectInitRange,
2187 Initializer);
Douglas Gregora16548e2009-08-11 05:31:07 +00002188 }
Mike Stump11289f42009-09-09 15:08:12 +00002189
Douglas Gregora16548e2009-08-11 05:31:07 +00002190 /// \brief Build a new C++ "delete" expression.
2191 ///
2192 /// By default, performs semantic analysis to build the new expression.
2193 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002194 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002195 bool IsGlobalDelete,
2196 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002197 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002198 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002199 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00002200 }
Mike Stump11289f42009-09-09 15:08:12 +00002201
Douglas Gregor29c42f22012-02-24 07:38:34 +00002202 /// \brief Build a new type trait expression.
2203 ///
2204 /// By default, performs semantic analysis to build the new expression.
2205 /// Subclasses may override this routine to provide different behavior.
2206 ExprResult RebuildTypeTrait(TypeTrait Trait,
2207 SourceLocation StartLoc,
2208 ArrayRef<TypeSourceInfo *> Args,
2209 SourceLocation RParenLoc) {
2210 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2211 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002212
John Wiegley6242b6a2011-04-28 00:16:57 +00002213 /// \brief Build a new array type trait expression.
2214 ///
2215 /// By default, performs semantic analysis to build the new expression.
2216 /// Subclasses may override this routine to provide different behavior.
2217 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2218 SourceLocation StartLoc,
2219 TypeSourceInfo *TSInfo,
2220 Expr *DimExpr,
2221 SourceLocation RParenLoc) {
2222 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2223 }
2224
John Wiegleyf9f65842011-04-25 06:54:41 +00002225 /// \brief Build a new expression trait expression.
2226 ///
2227 /// By default, performs semantic analysis to build the new expression.
2228 /// Subclasses may override this routine to provide different behavior.
2229 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2230 SourceLocation StartLoc,
2231 Expr *Queried,
2232 SourceLocation RParenLoc) {
2233 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2234 }
2235
Mike Stump11289f42009-09-09 15:08:12 +00002236 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00002237 /// expression.
2238 ///
2239 /// By default, performs semantic analysis to build the new expression.
2240 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002241 ExprResult RebuildDependentScopeDeclRefExpr(
2242 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002243 SourceLocation TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002244 const DeclarationNameInfo &NameInfo,
Richard Smithdb2630f2012-10-21 03:28:35 +00002245 const TemplateArgumentListInfo *TemplateArgs,
2246 bool IsAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002247 CXXScopeSpec SS;
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002248 SS.Adopt(QualifierLoc);
John McCalle66edc12009-11-24 19:00:30 +00002249
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002250 if (TemplateArgs || TemplateKWLoc.isValid())
Abramo Bagnara7945c982012-01-27 09:46:47 +00002251 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002252 NameInfo, TemplateArgs);
John McCalle66edc12009-11-24 19:00:30 +00002253
Richard Smithdb2630f2012-10-21 03:28:35 +00002254 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo,
2255 IsAddressOfOperand);
Douglas Gregora16548e2009-08-11 05:31:07 +00002256 }
2257
2258 /// \brief Build a new template-id expression.
2259 ///
2260 /// By default, performs semantic analysis to build the new expression.
2261 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002262 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002263 SourceLocation TemplateKWLoc,
2264 LookupResult &R,
2265 bool RequiresADL,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002266 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnara7945c982012-01-27 09:46:47 +00002267 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2268 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002269 }
2270
2271 /// \brief Build a new object-construction expression.
2272 ///
2273 /// By default, performs semantic analysis to build the new expression.
2274 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002275 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002276 SourceLocation Loc,
2277 CXXConstructorDecl *Constructor,
2278 bool IsElidable,
2279 MultiExprArg Args,
2280 bool HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002281 bool ListInitialization,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002282 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00002283 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002284 SourceRange ParenRange) {
Benjamin Kramerf0623432012-08-23 22:51:59 +00002285 SmallVector<Expr*, 8> ConvertedArgs;
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002286 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00002287 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00002288 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002289
Douglas Gregordb121ba2009-12-14 16:27:04 +00002290 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002291 ConvertedArgs,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002292 HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002293 ListInitialization,
Chandler Carruth01718152010-10-25 08:47:36 +00002294 RequiresZeroInit, ConstructKind,
2295 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00002296 }
2297
2298 /// \brief Build a new object-construction expression.
2299 ///
2300 /// By default, performs semantic analysis to build the new expression.
2301 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002302 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2303 SourceLocation LParenLoc,
2304 MultiExprArg Args,
2305 SourceLocation RParenLoc) {
2306 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002307 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002308 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002309 RParenLoc);
2310 }
2311
2312 /// \brief Build a new object-construction expression.
2313 ///
2314 /// By default, performs semantic analysis to build the new expression.
2315 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002316 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2317 SourceLocation LParenLoc,
2318 MultiExprArg Args,
2319 SourceLocation RParenLoc) {
2320 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002321 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002322 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002323 RParenLoc);
2324 }
Mike Stump11289f42009-09-09 15:08:12 +00002325
Douglas Gregora16548e2009-08-11 05:31:07 +00002326 /// \brief Build a new member reference expression.
2327 ///
2328 /// By default, performs semantic analysis to build the new expression.
2329 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002330 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregore16af532011-02-28 18:50:33 +00002331 QualType BaseType,
2332 bool IsArrow,
2333 SourceLocation OperatorLoc,
2334 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002335 SourceLocation TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00002336 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002337 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00002338 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002339 CXXScopeSpec SS;
Douglas Gregore16af532011-02-28 18:50:33 +00002340 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002341
John McCallb268a282010-08-23 23:25:46 +00002342 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002343 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002344 SS, TemplateKWLoc,
2345 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002346 MemberNameInfo,
2347 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002348 }
2349
John McCall10eae182009-11-30 22:42:35 +00002350 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00002351 ///
2352 /// By default, performs semantic analysis to build the new expression.
2353 /// Subclasses may override this routine to provide different behavior.
Richard Smithcab9a7d2011-10-26 19:06:56 +00002354 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2355 SourceLocation OperatorLoc,
2356 bool IsArrow,
2357 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002358 SourceLocation TemplateKWLoc,
Richard Smithcab9a7d2011-10-26 19:06:56 +00002359 NamedDecl *FirstQualifierInScope,
2360 LookupResult &R,
John McCall10eae182009-11-30 22:42:35 +00002361 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00002362 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00002363 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002364
John McCallb268a282010-08-23 23:25:46 +00002365 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002366 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002367 SS, TemplateKWLoc,
2368 FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00002369 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00002370 }
Mike Stump11289f42009-09-09 15:08:12 +00002371
Sebastian Redl4202c0f2010-09-10 20:55:43 +00002372 /// \brief Build a new noexcept expression.
2373 ///
2374 /// By default, performs semantic analysis to build the new expression.
2375 /// Subclasses may override this routine to provide different behavior.
2376 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2377 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2378 }
2379
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002380 /// \brief Build a new expression to compute the length of a parameter pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00002381 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2382 SourceLocation PackLoc,
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002383 SourceLocation RParenLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002384 Optional<unsigned> Length) {
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002385 if (Length)
Chad Rosier1dcde962012-08-08 18:46:20 +00002386 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2387 OperatorLoc, Pack, PackLoc,
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002388 RParenLoc, *Length);
Chad Rosier1dcde962012-08-08 18:46:20 +00002389
2390 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2391 OperatorLoc, Pack, PackLoc,
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002392 RParenLoc);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002393 }
Ted Kremeneke65b0862012-03-06 20:05:56 +00002394
Patrick Beard0caa3942012-04-19 00:25:12 +00002395 /// \brief Build a new Objective-C boxed expression.
2396 ///
2397 /// By default, performs semantic analysis to build the new expression.
2398 /// Subclasses may override this routine to provide different behavior.
2399 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2400 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2401 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002402
Ted Kremeneke65b0862012-03-06 20:05:56 +00002403 /// \brief Build a new Objective-C array literal.
2404 ///
2405 /// By default, performs semantic analysis to build the new expression.
2406 /// Subclasses may override this routine to provide different behavior.
2407 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2408 Expr **Elements, unsigned NumElements) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002409 return getSema().BuildObjCArrayLiteral(Range,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002410 MultiExprArg(Elements, NumElements));
2411 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002412
2413 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002414 Expr *Base, Expr *Key,
2415 ObjCMethodDecl *getterMethod,
2416 ObjCMethodDecl *setterMethod) {
2417 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2418 getterMethod, setterMethod);
2419 }
2420
2421 /// \brief Build a new Objective-C dictionary literal.
2422 ///
2423 /// By default, performs semantic analysis to build the new expression.
2424 /// Subclasses may override this routine to provide different behavior.
2425 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
2426 ObjCDictionaryElement *Elements,
2427 unsigned NumElements) {
2428 return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements);
2429 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002430
James Dennett2a4d13c2012-06-15 07:13:21 +00002431 /// \brief Build a new Objective-C \@encode expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002432 ///
2433 /// By default, performs semantic analysis to build the new expression.
2434 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002435 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00002436 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002437 SourceLocation RParenLoc) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00002438 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002439 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00002440 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002441
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002442 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00002443 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002444 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002445 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002446 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002447 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002448 MultiExprArg Args,
2449 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002450 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2451 ReceiverTypeInfo->getType(),
2452 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002453 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002454 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002455 }
2456
2457 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00002458 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002459 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002460 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002461 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002462 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002463 MultiExprArg Args,
2464 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00002465 return SemaRef.BuildInstanceMessage(Receiver,
2466 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002467 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002468 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002469 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002470 }
2471
Douglas Gregord51d90d2010-04-26 20:11:03 +00002472 /// \brief Build a new Objective-C ivar reference expression.
2473 ///
2474 /// By default, performs semantic analysis to build the new expression.
2475 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002476 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002477 SourceLocation IvarLoc,
2478 bool IsArrow, bool IsFreeIvar) {
2479 // FIXME: We lose track of the IsFreeIvar bit.
2480 CXXScopeSpec SS;
John Wiegley01296292011-04-08 18:41:53 +00002481 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002482 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2483 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00002484 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002485 /*FIME:*/IvarLoc,
John McCall48871652010-08-21 09:40:31 +00002486 SS, 0,
John McCalle9cccd82010-06-16 08:42:20 +00002487 false);
John Wiegley01296292011-04-08 18:41:53 +00002488 if (Result.isInvalid() || Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002489 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002490
Douglas Gregord51d90d2010-04-26 20:11:03 +00002491 if (Result.get())
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002492 return Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00002493
John Wiegley01296292011-04-08 18:41:53 +00002494 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Abramo Bagnara7945c982012-01-27 09:46:47 +00002495 /*FIXME:*/IvarLoc, IsArrow,
2496 SS, SourceLocation(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00002497 /*FirstQualifierInScope=*/0,
Chad Rosier1dcde962012-08-08 18:46:20 +00002498 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002499 /*TemplateArgs=*/0);
2500 }
Douglas Gregor9faee212010-04-26 20:47:02 +00002501
2502 /// \brief Build a new Objective-C property reference expression.
2503 ///
2504 /// By default, performs semantic analysis to build the new expression.
2505 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002506 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall526ab472011-10-25 17:37:35 +00002507 ObjCPropertyDecl *Property,
2508 SourceLocation PropertyLoc) {
Douglas Gregor9faee212010-04-26 20:47:02 +00002509 CXXScopeSpec SS;
John Wiegley01296292011-04-08 18:41:53 +00002510 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregor9faee212010-04-26 20:47:02 +00002511 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2512 Sema::LookupMemberName);
2513 bool IsArrow = false;
John McCalldadc5752010-08-24 06:29:42 +00002514 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregor9faee212010-04-26 20:47:02 +00002515 /*FIME:*/PropertyLoc,
John McCall48871652010-08-21 09:40:31 +00002516 SS, 0, false);
John Wiegley01296292011-04-08 18:41:53 +00002517 if (Result.isInvalid() || Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002518 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002519
Douglas Gregor9faee212010-04-26 20:47:02 +00002520 if (Result.get())
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002521 return Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00002522
John Wiegley01296292011-04-08 18:41:53 +00002523 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Chad Rosier1dcde962012-08-08 18:46:20 +00002524 /*FIXME:*/PropertyLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002525 SS, SourceLocation(),
Douglas Gregor9faee212010-04-26 20:47:02 +00002526 /*FirstQualifierInScope=*/0,
Chad Rosier1dcde962012-08-08 18:46:20 +00002527 R,
Douglas Gregor9faee212010-04-26 20:47:02 +00002528 /*TemplateArgs=*/0);
2529 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002530
John McCallb7bd14f2010-12-02 01:19:52 +00002531 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002532 ///
2533 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00002534 /// Subclasses may override this routine to provide different behavior.
2535 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2536 ObjCMethodDecl *Getter,
2537 ObjCMethodDecl *Setter,
2538 SourceLocation PropertyLoc) {
2539 // Since these expressions can only be value-dependent, we do not
2540 // need to perform semantic analysis again.
2541 return Owned(
2542 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2543 VK_LValue, OK_ObjCProperty,
2544 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002545 }
2546
Douglas Gregord51d90d2010-04-26 20:11:03 +00002547 /// \brief Build a new Objective-C "isa" expression.
2548 ///
2549 /// By default, performs semantic analysis to build the new expression.
2550 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002551 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00002552 SourceLocation OpLoc,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002553 bool IsArrow) {
2554 CXXScopeSpec SS;
John Wiegley01296292011-04-08 18:41:53 +00002555 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002556 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2557 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00002558 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00002559 OpLoc,
John McCall48871652010-08-21 09:40:31 +00002560 SS, 0, false);
John Wiegley01296292011-04-08 18:41:53 +00002561 if (Result.isInvalid() || Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002562 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002563
Douglas Gregord51d90d2010-04-26 20:11:03 +00002564 if (Result.get())
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002565 return Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00002566
John Wiegley01296292011-04-08 18:41:53 +00002567 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00002568 OpLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002569 SS, SourceLocation(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00002570 /*FirstQualifierInScope=*/0,
Chad Rosier1dcde962012-08-08 18:46:20 +00002571 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002572 /*TemplateArgs=*/0);
2573 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002574
Douglas Gregora16548e2009-08-11 05:31:07 +00002575 /// \brief Build a new shuffle vector expression.
2576 ///
2577 /// By default, performs semantic analysis to build the new expression.
2578 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002579 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002580 MultiExprArg SubExprs,
2581 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002582 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00002583 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00002584 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2585 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2586 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
David Blaikieff7d47a2012-12-19 00:45:41 +00002587 assert(!Lookup.empty() && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00002588
Douglas Gregora16548e2009-08-11 05:31:07 +00002589 // Build a reference to the __builtin_shufflevector builtin
David Blaikieff7d47a2012-12-19 00:45:41 +00002590 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
Eli Friedman34866c72012-08-31 00:14:07 +00002591 Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false,
2592 SemaRef.Context.BuiltinFnTy,
2593 VK_RValue, BuiltinLoc);
2594 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
2595 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
2596 CK_BuiltinFnToFnPtr).take();
Mike Stump11289f42009-09-09 15:08:12 +00002597
2598 // Build the CallExpr
Alp Toker314cc812014-01-25 16:55:45 +00002599 ExprResult TheCall = SemaRef.Owned(new (SemaRef.Context) CallExpr(
2600 SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(),
2601 Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00002602
Douglas Gregora16548e2009-08-11 05:31:07 +00002603 // Type-check the __builtin_shufflevector expression.
John Wiegley01296292011-04-08 18:41:53 +00002604 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.take()));
Douglas Gregora16548e2009-08-11 05:31:07 +00002605 }
John McCall31f82722010-11-12 08:19:04 +00002606
Hal Finkelc4d7c822013-09-18 03:29:45 +00002607 /// \brief Build a new convert vector expression.
2608 ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc,
2609 Expr *SrcExpr, TypeSourceInfo *DstTInfo,
2610 SourceLocation RParenLoc) {
2611 return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo,
2612 BuiltinLoc, RParenLoc);
2613 }
2614
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002615 /// \brief Build a new template argument pack expansion.
2616 ///
2617 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00002618 /// for a template argument. Subclasses may override this routine to provide
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002619 /// different behavior.
2620 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002621 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002622 Optional<unsigned> NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002623 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00002624 case TemplateArgument::Expression: {
2625 ExprResult Result
Douglas Gregorb8840002011-01-14 21:20:45 +00002626 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2627 EllipsisLoc, NumExpansions);
Douglas Gregor98318c22011-01-03 21:37:45 +00002628 if (Result.isInvalid())
2629 return TemplateArgumentLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00002630
Douglas Gregor98318c22011-01-03 21:37:45 +00002631 return TemplateArgumentLoc(Result.get(), Result.get());
2632 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002633
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002634 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002635 return TemplateArgumentLoc(TemplateArgument(
2636 Pattern.getArgument().getAsTemplate(),
Douglas Gregore1d60df2011-01-14 23:41:42 +00002637 NumExpansions),
Douglas Gregor9d802122011-03-02 17:09:35 +00002638 Pattern.getTemplateQualifierLoc(),
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002639 Pattern.getTemplateNameLoc(),
2640 EllipsisLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00002641
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002642 case TemplateArgument::Null:
2643 case TemplateArgument::Integral:
2644 case TemplateArgument::Declaration:
2645 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002646 case TemplateArgument::TemplateExpansion:
Eli Friedmanb826a002012-09-26 02:36:12 +00002647 case TemplateArgument::NullPtr:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002648 llvm_unreachable("Pack expansion pattern has no parameter packs");
Chad Rosier1dcde962012-08-08 18:46:20 +00002649
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002650 case TemplateArgument::Type:
Chad Rosier1dcde962012-08-08 18:46:20 +00002651 if (TypeSourceInfo *Expansion
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002652 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002653 EllipsisLoc,
2654 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002655 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2656 Expansion);
2657 break;
2658 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002659
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002660 return TemplateArgumentLoc();
2661 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002662
Douglas Gregor968f23a2011-01-03 19:31:53 +00002663 /// \brief Build a new expression pack expansion.
2664 ///
2665 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00002666 /// for an expression. Subclasses may override this routine to provide
Douglas Gregor968f23a2011-01-03 19:31:53 +00002667 /// different behavior.
Douglas Gregorb8840002011-01-14 21:20:45 +00002668 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002669 Optional<unsigned> NumExpansions) {
Douglas Gregorb8840002011-01-14 21:20:45 +00002670 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002671 }
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002672
2673 /// \brief Build a new atomic operation expression.
2674 ///
2675 /// By default, performs semantic analysis to build the new expression.
2676 /// Subclasses may override this routine to provide different behavior.
2677 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2678 MultiExprArg SubExprs,
2679 QualType RetTy,
2680 AtomicExpr::AtomicOp Op,
2681 SourceLocation RParenLoc) {
2682 // Just create the expression; there is not any interesting semantic
2683 // analysis here because we can't actually build an AtomicExpr until
2684 // we are sure it is semantically sound.
Benjamin Kramerc215e762012-08-24 11:54:20 +00002685 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002686 RParenLoc);
2687 }
2688
John McCall31f82722010-11-12 08:19:04 +00002689private:
Douglas Gregor14454802011-02-25 02:25:35 +00002690 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2691 QualType ObjectType,
2692 NamedDecl *FirstQualifierInScope,
2693 CXXScopeSpec &SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00002694
2695 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2696 QualType ObjectType,
2697 NamedDecl *FirstQualifierInScope,
2698 CXXScopeSpec &SS);
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00002699
2700 TypeSourceInfo *TransformTSIInObjectScope(TypeLoc TL, QualType ObjectType,
2701 NamedDecl *FirstQualifierInScope,
2702 CXXScopeSpec &SS);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002703};
Douglas Gregora16548e2009-08-11 05:31:07 +00002704
Douglas Gregorebe10102009-08-20 07:17:43 +00002705template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002706StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002707 if (!S)
2708 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00002709
Douglas Gregorebe10102009-08-20 07:17:43 +00002710 switch (S->getStmtClass()) {
2711 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00002712
Douglas Gregorebe10102009-08-20 07:17:43 +00002713 // Transform individual statement nodes
2714#define STMT(Node, Parent) \
2715 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCallbd066782011-02-09 08:16:59 +00002716#define ABSTRACT_STMT(Node)
Douglas Gregorebe10102009-08-20 07:17:43 +00002717#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00002718#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002719
Douglas Gregorebe10102009-08-20 07:17:43 +00002720 // Transform expressions by calling TransformExpr.
2721#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00002722#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00002723#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00002724#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00002725 {
John McCalldadc5752010-08-24 06:29:42 +00002726 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00002727 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002728 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002729
Richard Smith945f8d32013-01-14 22:39:08 +00002730 return getSema().ActOnExprStmt(E);
Douglas Gregorebe10102009-08-20 07:17:43 +00002731 }
Mike Stump11289f42009-09-09 15:08:12 +00002732 }
2733
John McCallc3007a22010-10-26 07:05:15 +00002734 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00002735}
Mike Stump11289f42009-09-09 15:08:12 +00002736
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00002737template<typename Derived>
2738OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) {
2739 if (!S)
2740 return S;
2741
2742 switch (S->getClauseKind()) {
2743 default: break;
2744 // Transform individual clause nodes
2745#define OPENMP_CLAUSE(Name, Class) \
2746 case OMPC_ ## Name : \
2747 return getDerived().Transform ## Class(cast<Class>(S));
2748#include "clang/Basic/OpenMPKinds.def"
2749 }
2750
2751 return S;
2752}
2753
Mike Stump11289f42009-09-09 15:08:12 +00002754
Douglas Gregore922c772009-08-04 22:27:00 +00002755template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002756ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002757 if (!E)
2758 return SemaRef.Owned(E);
2759
2760 switch (E->getStmtClass()) {
2761 case Stmt::NoStmtClass: break;
2762#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00002763#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00002764#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00002765 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00002766#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002767 }
2768
John McCallc3007a22010-10-26 07:05:15 +00002769 return SemaRef.Owned(E);
Douglas Gregor766b0bb2009-08-06 22:17:10 +00002770}
2771
2772template<typename Derived>
Richard Smithd59b8322012-12-19 01:39:02 +00002773ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
2774 bool CXXDirectInit) {
2775 // Initializers are instantiated like expressions, except that various outer
2776 // layers are stripped.
2777 if (!Init)
2778 return SemaRef.Owned(Init);
2779
2780 if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init))
2781 Init = ExprTemp->getSubExpr();
2782
Richard Smithe6ca4752013-05-30 22:40:16 +00002783 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
2784 Init = MTE->GetTemporaryExpr();
2785
Richard Smithd59b8322012-12-19 01:39:02 +00002786 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
2787 Init = Binder->getSubExpr();
2788
2789 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
2790 Init = ICE->getSubExprAsWritten();
2791
Richard Smithcc1b96d2013-06-12 22:31:48 +00002792 if (CXXStdInitializerListExpr *ILE =
2793 dyn_cast<CXXStdInitializerListExpr>(Init))
2794 return TransformInitializer(ILE->getSubExpr(), CXXDirectInit);
2795
Richard Smith38a549b2012-12-21 08:13:35 +00002796 // If this is not a direct-initializer, we only need to reconstruct
2797 // InitListExprs. Other forms of copy-initialization will be a no-op if
2798 // the initializer is already the right type.
2799 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
2800 if (!CXXDirectInit && !(Construct && Construct->isListInitialization()))
2801 return getDerived().TransformExpr(Init);
2802
2803 // Revert value-initialization back to empty parens.
2804 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
2805 SourceRange Parens = VIE->getSourceRange();
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002806 return getDerived().RebuildParenListExpr(Parens.getBegin(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00002807 Parens.getEnd());
2808 }
2809
2810 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
2811 if (isa<ImplicitValueInitExpr>(Init))
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002812 return getDerived().RebuildParenListExpr(SourceLocation(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00002813 SourceLocation());
2814
2815 // Revert initialization by constructor back to a parenthesized or braced list
2816 // of expressions. Any other form of initializer can just be reused directly.
2817 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
Richard Smithd59b8322012-12-19 01:39:02 +00002818 return getDerived().TransformExpr(Init);
2819
2820 SmallVector<Expr*, 8> NewArgs;
2821 bool ArgChanged = false;
2822 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
2823 /*IsCall*/true, NewArgs, &ArgChanged))
2824 return ExprError();
2825
2826 // If this was list initialization, revert to list form.
2827 if (Construct->isListInitialization())
2828 return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs,
2829 Construct->getLocEnd(),
2830 Construct->getType());
2831
Richard Smithd59b8322012-12-19 01:39:02 +00002832 // Build a ParenListExpr to represent anything else.
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00002833 SourceRange Parens = Construct->getParenOrBraceRange();
Richard Smithd59b8322012-12-19 01:39:02 +00002834 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
2835 Parens.getEnd());
2836}
2837
2838template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00002839bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2840 unsigned NumInputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00002841 bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +00002842 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00002843 bool *ArgChanged) {
2844 for (unsigned I = 0; I != NumInputs; ++I) {
2845 // If requested, drop call arguments that need to be dropped.
2846 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2847 if (ArgChanged)
2848 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002849
Douglas Gregora3efea12011-01-03 19:04:46 +00002850 break;
2851 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002852
Douglas Gregor968f23a2011-01-03 19:31:53 +00002853 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2854 Expr *Pattern = Expansion->getPattern();
Chad Rosier1dcde962012-08-08 18:46:20 +00002855
Chris Lattner01cf8db2011-07-20 06:58:45 +00002856 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor968f23a2011-01-03 19:31:53 +00002857 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2858 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00002859
Douglas Gregor968f23a2011-01-03 19:31:53 +00002860 // Determine whether the set of unexpanded parameter packs can and should
2861 // be expanded.
2862 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002863 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00002864 Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
2865 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor968f23a2011-01-03 19:31:53 +00002866 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2867 Pattern->getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00002868 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002869 Expand, RetainExpansion,
2870 NumExpansions))
Douglas Gregor968f23a2011-01-03 19:31:53 +00002871 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002872
Douglas Gregor968f23a2011-01-03 19:31:53 +00002873 if (!Expand) {
2874 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00002875 // transformation on the pack expansion, producing another pack
Douglas Gregor968f23a2011-01-03 19:31:53 +00002876 // expansion.
2877 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2878 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2879 if (OutPattern.isInvalid())
2880 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002881
2882 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregorb8840002011-01-14 21:20:45 +00002883 Expansion->getEllipsisLoc(),
2884 NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002885 if (Out.isInvalid())
2886 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002887
Douglas Gregor968f23a2011-01-03 19:31:53 +00002888 if (ArgChanged)
2889 *ArgChanged = true;
2890 Outputs.push_back(Out.get());
2891 continue;
2892 }
John McCall542e7c62011-07-06 07:30:07 +00002893
2894 // Record right away that the argument was changed. This needs
2895 // to happen even if the array expands to nothing.
2896 if (ArgChanged) *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002897
Douglas Gregor968f23a2011-01-03 19:31:53 +00002898 // The transform has determined that we should perform an elementwise
2899 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002900 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor968f23a2011-01-03 19:31:53 +00002901 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2902 ExprResult Out = getDerived().TransformExpr(Pattern);
2903 if (Out.isInvalid())
2904 return true;
2905
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002906 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregorb8840002011-01-14 21:20:45 +00002907 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2908 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002909 if (Out.isInvalid())
2910 return true;
2911 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002912
Douglas Gregor968f23a2011-01-03 19:31:53 +00002913 Outputs.push_back(Out.get());
2914 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002915
Douglas Gregor968f23a2011-01-03 19:31:53 +00002916 continue;
2917 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002918
Richard Smithd59b8322012-12-19 01:39:02 +00002919 ExprResult Result =
2920 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
2921 : getDerived().TransformExpr(Inputs[I]);
Douglas Gregora3efea12011-01-03 19:04:46 +00002922 if (Result.isInvalid())
2923 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002924
Douglas Gregora3efea12011-01-03 19:04:46 +00002925 if (Result.get() != Inputs[I] && ArgChanged)
2926 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002927
2928 Outputs.push_back(Result.get());
Douglas Gregora3efea12011-01-03 19:04:46 +00002929 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002930
Douglas Gregora3efea12011-01-03 19:04:46 +00002931 return false;
2932}
2933
2934template<typename Derived>
Douglas Gregor14454802011-02-25 02:25:35 +00002935NestedNameSpecifierLoc
2936TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2937 NestedNameSpecifierLoc NNS,
2938 QualType ObjectType,
2939 NamedDecl *FirstQualifierInScope) {
Chris Lattner01cf8db2011-07-20 06:58:45 +00002940 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier1dcde962012-08-08 18:46:20 +00002941 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregor14454802011-02-25 02:25:35 +00002942 Qualifier = Qualifier.getPrefix())
2943 Qualifiers.push_back(Qualifier);
2944
2945 CXXScopeSpec SS;
2946 while (!Qualifiers.empty()) {
2947 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2948 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier1dcde962012-08-08 18:46:20 +00002949
Douglas Gregor14454802011-02-25 02:25:35 +00002950 switch (QNNS->getKind()) {
2951 case NestedNameSpecifier::Identifier:
Chad Rosier1dcde962012-08-08 18:46:20 +00002952 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
Douglas Gregor14454802011-02-25 02:25:35 +00002953 *QNNS->getAsIdentifier(),
Chad Rosier1dcde962012-08-08 18:46:20 +00002954 Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00002955 Q.getLocalEndLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00002956 ObjectType, false, SS,
Douglas Gregor14454802011-02-25 02:25:35 +00002957 FirstQualifierInScope, false))
2958 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00002959
Douglas Gregor14454802011-02-25 02:25:35 +00002960 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00002961
Douglas Gregor14454802011-02-25 02:25:35 +00002962 case NestedNameSpecifier::Namespace: {
2963 NamespaceDecl *NS
2964 = cast_or_null<NamespaceDecl>(
2965 getDerived().TransformDecl(
2966 Q.getLocalBeginLoc(),
2967 QNNS->getAsNamespace()));
2968 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2969 break;
2970 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002971
Douglas Gregor14454802011-02-25 02:25:35 +00002972 case NestedNameSpecifier::NamespaceAlias: {
2973 NamespaceAliasDecl *Alias
2974 = cast_or_null<NamespaceAliasDecl>(
2975 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2976 QNNS->getAsNamespaceAlias()));
Chad Rosier1dcde962012-08-08 18:46:20 +00002977 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00002978 Q.getLocalEndLoc());
2979 break;
2980 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002981
Douglas Gregor14454802011-02-25 02:25:35 +00002982 case NestedNameSpecifier::Global:
2983 // There is no meaningful transformation that one could perform on the
2984 // global scope.
2985 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2986 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00002987
Douglas Gregor14454802011-02-25 02:25:35 +00002988 case NestedNameSpecifier::TypeSpecWithTemplate:
2989 case NestedNameSpecifier::TypeSpec: {
2990 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2991 FirstQualifierInScope, SS);
Chad Rosier1dcde962012-08-08 18:46:20 +00002992
Douglas Gregor14454802011-02-25 02:25:35 +00002993 if (!TL)
2994 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00002995
Douglas Gregor14454802011-02-25 02:25:35 +00002996 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Richard Smith2bf7fdb2013-01-02 11:42:31 +00002997 (SemaRef.getLangOpts().CPlusPlus11 &&
Douglas Gregor14454802011-02-25 02:25:35 +00002998 TL.getType()->isEnumeralType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002999 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003000 "Can't get cv-qualifiers here");
Richard Smith91c7bbd2011-10-20 03:28:47 +00003001 if (TL.getType()->isEnumeralType())
3002 SemaRef.Diag(TL.getBeginLoc(),
3003 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregor14454802011-02-25 02:25:35 +00003004 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
3005 Q.getLocalEndLoc());
3006 break;
3007 }
Richard Trieude756fb2011-05-07 01:36:37 +00003008 // If the nested-name-specifier is an invalid type def, don't emit an
3009 // error because a previous error should have already been emitted.
David Blaikie6adc78e2013-02-18 22:06:02 +00003010 TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
3011 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003012 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieude756fb2011-05-07 01:36:37 +00003013 << TL.getType() << SS.getRange();
3014 }
Douglas Gregor14454802011-02-25 02:25:35 +00003015 return NestedNameSpecifierLoc();
3016 }
Douglas Gregore16af532011-02-28 18:50:33 +00003017 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003018
Douglas Gregore16af532011-02-28 18:50:33 +00003019 // The qualifier-in-scope and object type only apply to the leftmost entity.
Douglas Gregor14454802011-02-25 02:25:35 +00003020 FirstQualifierInScope = 0;
Douglas Gregore16af532011-02-28 18:50:33 +00003021 ObjectType = QualType();
Douglas Gregor14454802011-02-25 02:25:35 +00003022 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003023
Douglas Gregor14454802011-02-25 02:25:35 +00003024 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier1dcde962012-08-08 18:46:20 +00003025 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003026 !getDerived().AlwaysRebuild())
3027 return NNS;
Chad Rosier1dcde962012-08-08 18:46:20 +00003028
3029 // If we can re-use the source-location data from the original
Douglas Gregor14454802011-02-25 02:25:35 +00003030 // nested-name-specifier, do so.
3031 if (SS.location_size() == NNS.getDataLength() &&
3032 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
3033 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
3034
3035 // Allocate new nested-name-specifier location information.
3036 return SS.getWithLocInContext(SemaRef.Context);
3037}
3038
3039template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003040DeclarationNameInfo
3041TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00003042::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003043 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003044 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003045 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003046
3047 switch (Name.getNameKind()) {
3048 case DeclarationName::Identifier:
3049 case DeclarationName::ObjCZeroArgSelector:
3050 case DeclarationName::ObjCOneArgSelector:
3051 case DeclarationName::ObjCMultiArgSelector:
3052 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00003053 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00003054 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003055 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00003056
Douglas Gregorf816bd72009-09-03 22:13:48 +00003057 case DeclarationName::CXXConstructorName:
3058 case DeclarationName::CXXDestructorName:
3059 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003060 TypeSourceInfo *NewTInfo;
3061 CanQualType NewCanTy;
3062 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00003063 NewTInfo = getDerived().TransformType(OldTInfo);
3064 if (!NewTInfo)
3065 return DeclarationNameInfo();
3066 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003067 }
3068 else {
3069 NewTInfo = 0;
3070 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00003071 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003072 if (NewT.isNull())
3073 return DeclarationNameInfo();
3074 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
3075 }
Mike Stump11289f42009-09-09 15:08:12 +00003076
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003077 DeclarationName NewName
3078 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
3079 NewCanTy);
3080 DeclarationNameInfo NewNameInfo(NameInfo);
3081 NewNameInfo.setName(NewName);
3082 NewNameInfo.setNamedTypeInfo(NewTInfo);
3083 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00003084 }
Mike Stump11289f42009-09-09 15:08:12 +00003085 }
3086
David Blaikie83d382b2011-09-23 05:06:16 +00003087 llvm_unreachable("Unknown name kind.");
Douglas Gregorf816bd72009-09-03 22:13:48 +00003088}
3089
3090template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003091TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00003092TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
3093 TemplateName Name,
3094 SourceLocation NameLoc,
3095 QualType ObjectType,
3096 NamedDecl *FirstQualifierInScope) {
3097 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
3098 TemplateDecl *Template = QTN->getTemplateDecl();
3099 assert(Template && "qualified template name must refer to a template");
Chad Rosier1dcde962012-08-08 18:46:20 +00003100
Douglas Gregor9db53502011-03-02 18:07:45 +00003101 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003102 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003103 Template));
3104 if (!TransTemplate)
3105 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003106
Douglas Gregor9db53502011-03-02 18:07:45 +00003107 if (!getDerived().AlwaysRebuild() &&
3108 SS.getScopeRep() == QTN->getQualifier() &&
3109 TransTemplate == Template)
3110 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003111
Douglas Gregor9db53502011-03-02 18:07:45 +00003112 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
3113 TransTemplate);
3114 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003115
Douglas Gregor9db53502011-03-02 18:07:45 +00003116 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
3117 if (SS.getScopeRep()) {
3118 // These apply to the scope specifier, not the template.
3119 ObjectType = QualType();
3120 FirstQualifierInScope = 0;
Chad Rosier1dcde962012-08-08 18:46:20 +00003121 }
3122
Douglas Gregor9db53502011-03-02 18:07:45 +00003123 if (!getDerived().AlwaysRebuild() &&
3124 SS.getScopeRep() == DTN->getQualifier() &&
3125 ObjectType.isNull())
3126 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003127
Douglas Gregor9db53502011-03-02 18:07:45 +00003128 if (DTN->isIdentifier()) {
3129 return getDerived().RebuildTemplateName(SS,
Chad Rosier1dcde962012-08-08 18:46:20 +00003130 *DTN->getIdentifier(),
Douglas Gregor9db53502011-03-02 18:07:45 +00003131 NameLoc,
3132 ObjectType,
3133 FirstQualifierInScope);
3134 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003135
Douglas Gregor9db53502011-03-02 18:07:45 +00003136 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
3137 ObjectType);
3138 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003139
Douglas Gregor9db53502011-03-02 18:07:45 +00003140 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
3141 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003142 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003143 Template));
3144 if (!TransTemplate)
3145 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003146
Douglas Gregor9db53502011-03-02 18:07:45 +00003147 if (!getDerived().AlwaysRebuild() &&
3148 TransTemplate == Template)
3149 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003150
Douglas Gregor9db53502011-03-02 18:07:45 +00003151 return TemplateName(TransTemplate);
3152 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003153
Douglas Gregor9db53502011-03-02 18:07:45 +00003154 if (SubstTemplateTemplateParmPackStorage *SubstPack
3155 = Name.getAsSubstTemplateTemplateParmPack()) {
3156 TemplateTemplateParmDecl *TransParam
3157 = cast_or_null<TemplateTemplateParmDecl>(
3158 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
3159 if (!TransParam)
3160 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003161
Douglas Gregor9db53502011-03-02 18:07:45 +00003162 if (!getDerived().AlwaysRebuild() &&
3163 TransParam == SubstPack->getParameterPack())
3164 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003165
3166 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregor9db53502011-03-02 18:07:45 +00003167 SubstPack->getArgumentPack());
3168 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003169
Douglas Gregor9db53502011-03-02 18:07:45 +00003170 // These should be getting filtered out before they reach the AST.
3171 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregor9db53502011-03-02 18:07:45 +00003172}
3173
3174template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003175void TreeTransform<Derived>::InventTemplateArgumentLoc(
3176 const TemplateArgument &Arg,
3177 TemplateArgumentLoc &Output) {
3178 SourceLocation Loc = getDerived().getBaseLocation();
3179 switch (Arg.getKind()) {
3180 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003181 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00003182 break;
3183
3184 case TemplateArgument::Type:
3185 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00003186 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier1dcde962012-08-08 18:46:20 +00003187
John McCall0ad16662009-10-29 08:12:44 +00003188 break;
3189
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003190 case TemplateArgument::Template:
Douglas Gregor9d802122011-03-02 17:09:35 +00003191 case TemplateArgument::TemplateExpansion: {
3192 NestedNameSpecifierLocBuilder Builder;
3193 TemplateName Template = Arg.getAsTemplate();
3194 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3195 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3196 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3197 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003198
Douglas Gregor9d802122011-03-02 17:09:35 +00003199 if (Arg.getKind() == TemplateArgument::Template)
Chad Rosier1dcde962012-08-08 18:46:20 +00003200 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003201 Builder.getWithLocInContext(SemaRef.Context),
3202 Loc);
3203 else
Chad Rosier1dcde962012-08-08 18:46:20 +00003204 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003205 Builder.getWithLocInContext(SemaRef.Context),
3206 Loc, Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003207
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003208 break;
Douglas Gregor9d802122011-03-02 17:09:35 +00003209 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003210
John McCall0ad16662009-10-29 08:12:44 +00003211 case TemplateArgument::Expression:
3212 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3213 break;
3214
3215 case TemplateArgument::Declaration:
3216 case TemplateArgument::Integral:
3217 case TemplateArgument::Pack:
Eli Friedmanb826a002012-09-26 02:36:12 +00003218 case TemplateArgument::NullPtr:
John McCall0d07eb32009-10-29 18:45:58 +00003219 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00003220 break;
3221 }
3222}
3223
3224template<typename Derived>
3225bool TreeTransform<Derived>::TransformTemplateArgument(
3226 const TemplateArgumentLoc &Input,
3227 TemplateArgumentLoc &Output) {
3228 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00003229 switch (Arg.getKind()) {
3230 case TemplateArgument::Null:
3231 case TemplateArgument::Integral:
Eli Friedmancda3db82012-09-25 01:02:42 +00003232 case TemplateArgument::Pack:
3233 case TemplateArgument::Declaration:
Eli Friedmanb826a002012-09-26 02:36:12 +00003234 case TemplateArgument::NullPtr:
3235 llvm_unreachable("Unexpected TemplateArgument");
Mike Stump11289f42009-09-09 15:08:12 +00003236
Douglas Gregore922c772009-08-04 22:27:00 +00003237 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00003238 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall0ad16662009-10-29 08:12:44 +00003239 if (DI == NULL)
John McCallbcd03502009-12-07 02:54:59 +00003240 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00003241
3242 DI = getDerived().TransformType(DI);
3243 if (!DI) return true;
3244
3245 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3246 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003247 }
Mike Stump11289f42009-09-09 15:08:12 +00003248
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003249 case TemplateArgument::Template: {
Douglas Gregor9d802122011-03-02 17:09:35 +00003250 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3251 if (QualifierLoc) {
3252 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3253 if (!QualifierLoc)
3254 return true;
3255 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003256
Douglas Gregordf846d12011-03-02 18:46:51 +00003257 CXXScopeSpec SS;
3258 SS.Adopt(QualifierLoc);
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003259 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00003260 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3261 Input.getTemplateNameLoc());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003262 if (Template.isNull())
3263 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003264
Douglas Gregor9d802122011-03-02 17:09:35 +00003265 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003266 Input.getTemplateNameLoc());
3267 return false;
3268 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003269
3270 case TemplateArgument::TemplateExpansion:
3271 llvm_unreachable("Caller should expand pack expansions");
3272
Douglas Gregore922c772009-08-04 22:27:00 +00003273 case TemplateArgument::Expression: {
Richard Smith764d2fe2011-12-20 02:08:33 +00003274 // Template argument expressions are constant expressions.
Mike Stump11289f42009-09-09 15:08:12 +00003275 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smith764d2fe2011-12-20 02:08:33 +00003276 Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003277
John McCall0ad16662009-10-29 08:12:44 +00003278 Expr *InputExpr = Input.getSourceExpression();
3279 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3280
Chris Lattnercdb591a2011-04-25 20:37:58 +00003281 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanc6237c62012-02-29 03:16:56 +00003282 E = SemaRef.ActOnConstantExpression(E);
John McCall0ad16662009-10-29 08:12:44 +00003283 if (E.isInvalid()) return true;
John McCallb268a282010-08-23 23:25:46 +00003284 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall0ad16662009-10-29 08:12:44 +00003285 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003286 }
Douglas Gregore922c772009-08-04 22:27:00 +00003287 }
Mike Stump11289f42009-09-09 15:08:12 +00003288
Douglas Gregore922c772009-08-04 22:27:00 +00003289 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00003290 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00003291}
3292
Douglas Gregorfe921a72010-12-20 23:36:19 +00003293/// \brief Iterator adaptor that invents template argument location information
3294/// for each of the template arguments in its underlying iterator.
3295template<typename Derived, typename InputIterator>
3296class TemplateArgumentLocInventIterator {
3297 TreeTransform<Derived> &Self;
3298 InputIterator Iter;
Chad Rosier1dcde962012-08-08 18:46:20 +00003299
Douglas Gregorfe921a72010-12-20 23:36:19 +00003300public:
3301 typedef TemplateArgumentLoc value_type;
3302 typedef TemplateArgumentLoc reference;
3303 typedef typename std::iterator_traits<InputIterator>::difference_type
3304 difference_type;
3305 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00003306
Douglas Gregorfe921a72010-12-20 23:36:19 +00003307 class pointer {
3308 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00003309
Douglas Gregorfe921a72010-12-20 23:36:19 +00003310 public:
3311 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003312
Douglas Gregorfe921a72010-12-20 23:36:19 +00003313 const TemplateArgumentLoc *operator->() const { return &Arg; }
3314 };
Chad Rosier1dcde962012-08-08 18:46:20 +00003315
Douglas Gregorfe921a72010-12-20 23:36:19 +00003316 TemplateArgumentLocInventIterator() { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003317
Douglas Gregorfe921a72010-12-20 23:36:19 +00003318 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3319 InputIterator Iter)
3320 : Self(Self), Iter(Iter) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003321
Douglas Gregorfe921a72010-12-20 23:36:19 +00003322 TemplateArgumentLocInventIterator &operator++() {
3323 ++Iter;
3324 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00003325 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003326
Douglas Gregorfe921a72010-12-20 23:36:19 +00003327 TemplateArgumentLocInventIterator operator++(int) {
3328 TemplateArgumentLocInventIterator Old(*this);
3329 ++(*this);
3330 return Old;
3331 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003332
Douglas Gregorfe921a72010-12-20 23:36:19 +00003333 reference operator*() const {
3334 TemplateArgumentLoc Result;
3335 Self.InventTemplateArgumentLoc(*Iter, Result);
3336 return Result;
3337 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003338
Douglas Gregorfe921a72010-12-20 23:36:19 +00003339 pointer operator->() const { return pointer(**this); }
Chad Rosier1dcde962012-08-08 18:46:20 +00003340
Douglas Gregorfe921a72010-12-20 23:36:19 +00003341 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3342 const TemplateArgumentLocInventIterator &Y) {
3343 return X.Iter == Y.Iter;
3344 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00003345
Douglas Gregorfe921a72010-12-20 23:36:19 +00003346 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3347 const TemplateArgumentLocInventIterator &Y) {
3348 return X.Iter != Y.Iter;
3349 }
3350};
Chad Rosier1dcde962012-08-08 18:46:20 +00003351
Douglas Gregor42cafa82010-12-20 17:42:22 +00003352template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00003353template<typename InputIterator>
3354bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3355 InputIterator Last,
Douglas Gregor42cafa82010-12-20 17:42:22 +00003356 TemplateArgumentListInfo &Outputs) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00003357 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00003358 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00003359 TemplateArgumentLoc In = *First;
Chad Rosier1dcde962012-08-08 18:46:20 +00003360
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003361 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3362 // Unpack argument packs, which we translate them into separate
3363 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00003364 // FIXME: We could do much better if we could guarantee that the
3365 // TemplateArgumentLocInfo for the pack expansion would be usable for
3366 // all of the template arguments in the argument pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00003367 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003368 TemplateArgument::pack_iterator>
3369 PackLocIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00003370 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003371 In.getArgument().pack_begin()),
3372 PackLocIterator(*this,
3373 In.getArgument().pack_end()),
3374 Outputs))
3375 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003376
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003377 continue;
3378 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003379
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003380 if (In.getArgument().isPackExpansion()) {
3381 // We have a pack expansion, for which we will be substituting into
3382 // the pattern.
3383 SourceLocation Ellipsis;
David Blaikie05785d12013-02-20 22:23:23 +00003384 Optional<unsigned> OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003385 TemplateArgumentLoc Pattern
Eli Friedman94e9eaa2013-06-20 04:11:21 +00003386 = getSema().getTemplateArgumentPackExpansionPattern(
3387 In, Ellipsis, OrigNumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00003388
Chris Lattner01cf8db2011-07-20 06:58:45 +00003389 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003390 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3391 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00003392
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003393 // Determine whether the set of unexpanded parameter packs can and should
3394 // be expanded.
3395 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003396 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00003397 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003398 if (getDerived().TryExpandParameterPacks(Ellipsis,
3399 Pattern.getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003400 Unexpanded,
Chad Rosier1dcde962012-08-08 18:46:20 +00003401 Expand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003402 RetainExpansion,
3403 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003404 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003405
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003406 if (!Expand) {
3407 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00003408 // transformation on the pack expansion, producing another pack
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003409 // expansion.
3410 TemplateArgumentLoc OutPattern;
3411 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3412 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3413 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003414
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003415 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3416 NumExpansions);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003417 if (Out.getArgument().isNull())
3418 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003419
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003420 Outputs.addArgument(Out);
3421 continue;
3422 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003423
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003424 // The transform has determined that we should perform an elementwise
3425 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003426 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003427 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3428
3429 if (getDerived().TransformTemplateArgument(Pattern, Out))
3430 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003431
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003432 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003433 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3434 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003435 if (Out.getArgument().isNull())
3436 return true;
3437 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003438
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003439 Outputs.addArgument(Out);
3440 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003441
Douglas Gregor48d24112011-01-10 20:53:55 +00003442 // If we're supposed to retain a pack expansion, do so by temporarily
3443 // forgetting the partially-substituted parameter pack.
3444 if (RetainExpansion) {
3445 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00003446
Douglas Gregor48d24112011-01-10 20:53:55 +00003447 if (getDerived().TransformTemplateArgument(Pattern, Out))
3448 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003449
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003450 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3451 OrigNumExpansions);
Douglas Gregor48d24112011-01-10 20:53:55 +00003452 if (Out.getArgument().isNull())
3453 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003454
Douglas Gregor48d24112011-01-10 20:53:55 +00003455 Outputs.addArgument(Out);
3456 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003457
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003458 continue;
3459 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003460
3461 // The simple case:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003462 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor42cafa82010-12-20 17:42:22 +00003463 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003464
Douglas Gregor42cafa82010-12-20 17:42:22 +00003465 Outputs.addArgument(Out);
3466 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003467
Douglas Gregor42cafa82010-12-20 17:42:22 +00003468 return false;
3469
3470}
3471
Douglas Gregord6ff3322009-08-04 16:50:30 +00003472//===----------------------------------------------------------------------===//
3473// Type transformation
3474//===----------------------------------------------------------------------===//
3475
3476template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003477QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00003478 if (getDerived().AlreadyTransformed(T))
3479 return T;
Mike Stump11289f42009-09-09 15:08:12 +00003480
John McCall550e0c22009-10-21 00:40:46 +00003481 // Temporary workaround. All of these transformations should
3482 // eventually turn into transformations on TypeLocs.
Douglas Gregor2d525f02011-01-25 19:13:18 +00003483 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3484 getDerived().getBaseLocation());
Chad Rosier1dcde962012-08-08 18:46:20 +00003485
John McCall31f82722010-11-12 08:19:04 +00003486 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00003487
John McCall550e0c22009-10-21 00:40:46 +00003488 if (!NewDI)
3489 return QualType();
3490
3491 return NewDI->getType();
3492}
3493
3494template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003495TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smith764d2fe2011-12-20 02:08:33 +00003496 // Refine the base location to the type's location.
3497 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3498 getDerived().getBaseEntity());
John McCall550e0c22009-10-21 00:40:46 +00003499 if (getDerived().AlreadyTransformed(DI->getType()))
3500 return DI;
3501
3502 TypeLocBuilder TLB;
3503
3504 TypeLoc TL = DI->getTypeLoc();
3505 TLB.reserve(TL.getFullDataSize());
3506
John McCall31f82722010-11-12 08:19:04 +00003507 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00003508 if (Result.isNull())
3509 return 0;
3510
John McCallbcd03502009-12-07 02:54:59 +00003511 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00003512}
3513
3514template<typename Derived>
3515QualType
John McCall31f82722010-11-12 08:19:04 +00003516TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003517 switch (T.getTypeLocClass()) {
3518#define ABSTRACT_TYPELOC(CLASS, PARENT)
David Blaikie6adc78e2013-02-18 22:06:02 +00003519#define TYPELOC(CLASS, PARENT) \
3520 case TypeLoc::CLASS: \
3521 return getDerived().Transform##CLASS##Type(TLB, \
3522 T.castAs<CLASS##TypeLoc>());
John McCall550e0c22009-10-21 00:40:46 +00003523#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00003524 }
Mike Stump11289f42009-09-09 15:08:12 +00003525
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003526 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00003527}
3528
3529/// FIXME: By default, this routine adds type qualifiers only to types
3530/// that can have qualifiers, and silently suppresses those qualifiers
3531/// that are not permitted (e.g., qualifiers on reference or function
3532/// types). This is the right thing for template instantiation, but
3533/// probably not for other clients.
3534template<typename Derived>
3535QualType
3536TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003537 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00003538 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00003539
John McCall31f82722010-11-12 08:19:04 +00003540 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00003541 if (Result.isNull())
3542 return QualType();
3543
3544 // Silently suppress qualifiers if the result type can't be qualified.
3545 // FIXME: this is the right thing for template instantiation, but
3546 // probably not for other clients.
3547 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00003548 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00003549
John McCall31168b02011-06-15 23:02:42 +00003550 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore46db902011-06-17 22:11:49 +00003551 // resulting type.
3552 if (Quals.hasObjCLifetime()) {
3553 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3554 Quals.removeObjCLifetime();
Douglas Gregord7357a92011-06-17 23:16:24 +00003555 else if (Result.getObjCLifetime()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003556 // Objective-C ARC:
Douglas Gregore46db902011-06-17 22:11:49 +00003557 // A lifetime qualifier applied to a substituted template parameter
3558 // overrides the lifetime qualifier from the template argument.
Douglas Gregorf4e43312013-01-17 23:59:28 +00003559 const AutoType *AutoTy;
Chad Rosier1dcde962012-08-08 18:46:20 +00003560 if (const SubstTemplateTypeParmType *SubstTypeParam
Douglas Gregore46db902011-06-17 22:11:49 +00003561 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3562 QualType Replacement = SubstTypeParam->getReplacementType();
3563 Qualifiers Qs = Replacement.getQualifiers();
3564 Qs.removeObjCLifetime();
Chad Rosier1dcde962012-08-08 18:46:20 +00003565 Replacement
Douglas Gregore46db902011-06-17 22:11:49 +00003566 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3567 Qs);
3568 Result = SemaRef.Context.getSubstTemplateTypeParmType(
Chad Rosier1dcde962012-08-08 18:46:20 +00003569 SubstTypeParam->getReplacedParameter(),
Douglas Gregore46db902011-06-17 22:11:49 +00003570 Replacement);
3571 TLB.TypeWasModifiedSafely(Result);
Douglas Gregorf4e43312013-01-17 23:59:28 +00003572 } else if ((AutoTy = dyn_cast<AutoType>(Result)) && AutoTy->isDeduced()) {
3573 // 'auto' types behave the same way as template parameters.
3574 QualType Deduced = AutoTy->getDeducedType();
3575 Qualifiers Qs = Deduced.getQualifiers();
3576 Qs.removeObjCLifetime();
3577 Deduced = SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(),
3578 Qs);
Faisal Vali2b391ab2013-09-26 19:54:12 +00003579 Result = SemaRef.Context.getAutoType(Deduced, AutoTy->isDecltypeAuto(),
3580 AutoTy->isDependentType());
Douglas Gregorf4e43312013-01-17 23:59:28 +00003581 TLB.TypeWasModifiedSafely(Result);
Douglas Gregore46db902011-06-17 22:11:49 +00003582 } else {
Douglas Gregord7357a92011-06-17 23:16:24 +00003583 // Otherwise, complain about the addition of a qualifier to an
3584 // already-qualified type.
Eli Friedman7152fbe2013-06-07 20:31:48 +00003585 SourceRange R = T.getUnqualifiedLoc().getSourceRange();
Argyrios Kyrtzidiscff00d92011-06-24 00:08:59 +00003586 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregord7357a92011-06-17 23:16:24 +00003587 << Result << R;
Chad Rosier1dcde962012-08-08 18:46:20 +00003588
Douglas Gregore46db902011-06-17 22:11:49 +00003589 Quals.removeObjCLifetime();
3590 }
3591 }
3592 }
John McCallcb0f89a2010-06-05 06:41:15 +00003593 if (!Quals.empty()) {
3594 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
Richard Smithdeec0742013-03-27 23:36:39 +00003595 // BuildQualifiedType might not add qualifiers if they are invalid.
3596 if (Result.hasLocalQualifiers())
3597 TLB.push<QualifiedTypeLoc>(Result);
John McCallcb0f89a2010-06-05 06:41:15 +00003598 // No location information to preserve.
3599 }
John McCall550e0c22009-10-21 00:40:46 +00003600
3601 return Result;
3602}
3603
Douglas Gregor14454802011-02-25 02:25:35 +00003604template<typename Derived>
3605TypeLoc
3606TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3607 QualType ObjectType,
3608 NamedDecl *UnqualLookup,
3609 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003610 if (getDerived().AlreadyTransformed(TL.getType()))
Douglas Gregor14454802011-02-25 02:25:35 +00003611 return TL;
Chad Rosier1dcde962012-08-08 18:46:20 +00003612
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003613 TypeSourceInfo *TSI =
3614 TransformTSIInObjectScope(TL, ObjectType, UnqualLookup, SS);
3615 if (TSI)
3616 return TSI->getTypeLoc();
3617 return TypeLoc();
Douglas Gregor14454802011-02-25 02:25:35 +00003618}
3619
Douglas Gregor579c15f2011-03-02 18:32:08 +00003620template<typename Derived>
3621TypeSourceInfo *
3622TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3623 QualType ObjectType,
3624 NamedDecl *UnqualLookup,
3625 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003626 if (getDerived().AlreadyTransformed(TSInfo->getType()))
Douglas Gregor579c15f2011-03-02 18:32:08 +00003627 return TSInfo;
Chad Rosier1dcde962012-08-08 18:46:20 +00003628
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003629 return TransformTSIInObjectScope(TSInfo->getTypeLoc(), ObjectType,
3630 UnqualLookup, SS);
3631}
3632
3633template <typename Derived>
3634TypeSourceInfo *TreeTransform<Derived>::TransformTSIInObjectScope(
3635 TypeLoc TL, QualType ObjectType, NamedDecl *UnqualLookup,
3636 CXXScopeSpec &SS) {
3637 QualType T = TL.getType();
3638 assert(!getDerived().AlreadyTransformed(T));
3639
Douglas Gregor579c15f2011-03-02 18:32:08 +00003640 TypeLocBuilder TLB;
3641 QualType Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00003642
Douglas Gregor579c15f2011-03-02 18:32:08 +00003643 if (isa<TemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00003644 TemplateSpecializationTypeLoc SpecTL =
3645 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00003646
Douglas Gregor579c15f2011-03-02 18:32:08 +00003647 TemplateName Template
3648 = getDerived().TransformTemplateName(SS,
3649 SpecTL.getTypePtr()->getTemplateName(),
3650 SpecTL.getTemplateNameLoc(),
3651 ObjectType, UnqualLookup);
Chad Rosier1dcde962012-08-08 18:46:20 +00003652 if (Template.isNull())
Douglas Gregor579c15f2011-03-02 18:32:08 +00003653 return 0;
Chad Rosier1dcde962012-08-08 18:46:20 +00003654
3655 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregor579c15f2011-03-02 18:32:08 +00003656 Template);
3657 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00003658 DependentTemplateSpecializationTypeLoc SpecTL =
3659 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00003660
Douglas Gregor579c15f2011-03-02 18:32:08 +00003661 TemplateName Template
Chad Rosier1dcde962012-08-08 18:46:20 +00003662 = getDerived().RebuildTemplateName(SS,
3663 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00003664 SpecTL.getTemplateNameLoc(),
Douglas Gregor579c15f2011-03-02 18:32:08 +00003665 ObjectType, UnqualLookup);
3666 if (Template.isNull())
3667 return 0;
Chad Rosier1dcde962012-08-08 18:46:20 +00003668
3669 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregor579c15f2011-03-02 18:32:08 +00003670 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00003671 Template,
3672 SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00003673 } else {
3674 // Nothing special needs to be done for these.
3675 Result = getDerived().TransformType(TLB, TL);
3676 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003677
3678 if (Result.isNull())
Douglas Gregor579c15f2011-03-02 18:32:08 +00003679 return 0;
Chad Rosier1dcde962012-08-08 18:46:20 +00003680
Douglas Gregor579c15f2011-03-02 18:32:08 +00003681 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3682}
3683
John McCall550e0c22009-10-21 00:40:46 +00003684template <class TyLoc> static inline
3685QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3686 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3687 NewT.setNameLoc(T.getNameLoc());
3688 return T.getType();
3689}
3690
John McCall550e0c22009-10-21 00:40:46 +00003691template<typename Derived>
3692QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003693 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00003694 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3695 NewT.setBuiltinLoc(T.getBuiltinLoc());
3696 if (T.needsExtraLocalData())
3697 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3698 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003699}
Mike Stump11289f42009-09-09 15:08:12 +00003700
Douglas Gregord6ff3322009-08-04 16:50:30 +00003701template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003702QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003703 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003704 // FIXME: recurse?
3705 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003706}
Mike Stump11289f42009-09-09 15:08:12 +00003707
Reid Kleckner0503a872013-12-05 01:23:43 +00003708template <typename Derived>
3709QualType TreeTransform<Derived>::TransformAdjustedType(TypeLocBuilder &TLB,
3710 AdjustedTypeLoc TL) {
3711 // Adjustments applied during transformation are handled elsewhere.
3712 return getDerived().TransformType(TLB, TL.getOriginalLoc());
3713}
3714
Douglas Gregord6ff3322009-08-04 16:50:30 +00003715template<typename Derived>
Reid Kleckner8a365022013-06-24 17:51:48 +00003716QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
3717 DecayedTypeLoc TL) {
3718 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
3719 if (OriginalType.isNull())
3720 return QualType();
3721
3722 QualType Result = TL.getType();
3723 if (getDerived().AlwaysRebuild() ||
3724 OriginalType != TL.getOriginalLoc().getType())
3725 Result = SemaRef.Context.getDecayedType(OriginalType);
3726 TLB.push<DecayedTypeLoc>(Result);
3727 // Nothing to set for DecayedTypeLoc.
3728 return Result;
3729}
3730
3731template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003732QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003733 PointerTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003734 QualType PointeeType
3735 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003736 if (PointeeType.isNull())
3737 return QualType();
3738
3739 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00003740 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003741 // A dependent pointer type 'T *' has is being transformed such
3742 // that an Objective-C class type is being replaced for 'T'. The
3743 // resulting pointer type is an ObjCObjectPointerType, not a
3744 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00003745 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier1dcde962012-08-08 18:46:20 +00003746
John McCall8b07ec22010-05-15 11:32:37 +00003747 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3748 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003749 return Result;
3750 }
John McCall31f82722010-11-12 08:19:04 +00003751
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003752 if (getDerived().AlwaysRebuild() ||
3753 PointeeType != TL.getPointeeLoc().getType()) {
3754 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3755 if (Result.isNull())
3756 return QualType();
3757 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003758
John McCall31168b02011-06-15 23:02:42 +00003759 // Objective-C ARC can add lifetime qualifiers to the type that we're
3760 // pointing to.
3761 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier1dcde962012-08-08 18:46:20 +00003762
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003763 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3764 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00003765 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003766}
Mike Stump11289f42009-09-09 15:08:12 +00003767
3768template<typename Derived>
3769QualType
John McCall550e0c22009-10-21 00:40:46 +00003770TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003771 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00003772 QualType PointeeType
Chad Rosier1dcde962012-08-08 18:46:20 +00003773 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3774 if (PointeeType.isNull())
3775 return QualType();
3776
3777 QualType Result = TL.getType();
3778 if (getDerived().AlwaysRebuild() ||
3779 PointeeType != TL.getPointeeLoc().getType()) {
3780 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00003781 TL.getSigilLoc());
3782 if (Result.isNull())
3783 return QualType();
3784 }
3785
Douglas Gregor049211a2010-04-22 16:50:51 +00003786 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00003787 NewT.setSigilLoc(TL.getSigilLoc());
3788 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003789}
3790
John McCall70dd5f62009-10-30 00:06:24 +00003791/// Transforms a reference type. Note that somewhat paradoxically we
3792/// don't care whether the type itself is an l-value type or an r-value
3793/// type; we only care if the type was *written* as an l-value type
3794/// or an r-value type.
3795template<typename Derived>
3796QualType
3797TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003798 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00003799 const ReferenceType *T = TL.getTypePtr();
3800
3801 // Note that this works with the pointee-as-written.
3802 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3803 if (PointeeType.isNull())
3804 return QualType();
3805
3806 QualType Result = TL.getType();
3807 if (getDerived().AlwaysRebuild() ||
3808 PointeeType != T->getPointeeTypeAsWritten()) {
3809 Result = getDerived().RebuildReferenceType(PointeeType,
3810 T->isSpelledAsLValue(),
3811 TL.getSigilLoc());
3812 if (Result.isNull())
3813 return QualType();
3814 }
3815
John McCall31168b02011-06-15 23:02:42 +00003816 // Objective-C ARC can add lifetime qualifiers to the type that we're
3817 // referring to.
3818 TLB.TypeWasModifiedSafely(
3819 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3820
John McCall70dd5f62009-10-30 00:06:24 +00003821 // r-value references can be rebuilt as l-value references.
3822 ReferenceTypeLoc NewTL;
3823 if (isa<LValueReferenceType>(Result))
3824 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3825 else
3826 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3827 NewTL.setSigilLoc(TL.getSigilLoc());
3828
3829 return Result;
3830}
3831
Mike Stump11289f42009-09-09 15:08:12 +00003832template<typename Derived>
3833QualType
John McCall550e0c22009-10-21 00:40:46 +00003834TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003835 LValueReferenceTypeLoc TL) {
3836 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003837}
3838
Mike Stump11289f42009-09-09 15:08:12 +00003839template<typename Derived>
3840QualType
John McCall550e0c22009-10-21 00:40:46 +00003841TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003842 RValueReferenceTypeLoc TL) {
3843 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003844}
Mike Stump11289f42009-09-09 15:08:12 +00003845
Douglas Gregord6ff3322009-08-04 16:50:30 +00003846template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003847QualType
John McCall550e0c22009-10-21 00:40:46 +00003848TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003849 MemberPointerTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003850 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003851 if (PointeeType.isNull())
3852 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003853
Abramo Bagnara509357842011-03-05 14:42:21 +00003854 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
3855 TypeSourceInfo* NewClsTInfo = 0;
3856 if (OldClsTInfo) {
3857 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3858 if (!NewClsTInfo)
3859 return QualType();
3860 }
3861
3862 const MemberPointerType *T = TL.getTypePtr();
3863 QualType OldClsType = QualType(T->getClass(), 0);
3864 QualType NewClsType;
3865 if (NewClsTInfo)
3866 NewClsType = NewClsTInfo->getType();
3867 else {
3868 NewClsType = getDerived().TransformType(OldClsType);
3869 if (NewClsType.isNull())
3870 return QualType();
3871 }
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 PointeeType != T->getPointeeType() ||
Abramo Bagnara509357842011-03-05 14:42:21 +00003876 NewClsType != OldClsType) {
3877 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall70dd5f62009-10-30 00:06:24 +00003878 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00003879 if (Result.isNull())
3880 return QualType();
3881 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00003882
Reid Kleckner0503a872013-12-05 01:23:43 +00003883 // If we had to adjust the pointee type when building a member pointer, make
3884 // sure to push TypeLoc info for it.
3885 const MemberPointerType *MPT = Result->getAs<MemberPointerType>();
3886 if (MPT && PointeeType != MPT->getPointeeType()) {
3887 assert(isa<AdjustedType>(MPT->getPointeeType()));
3888 TLB.push<AdjustedTypeLoc>(MPT->getPointeeType());
3889 }
3890
John McCall550e0c22009-10-21 00:40:46 +00003891 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3892 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnara509357842011-03-05 14:42:21 +00003893 NewTL.setClassTInfo(NewClsTInfo);
John McCall550e0c22009-10-21 00:40:46 +00003894
3895 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003896}
3897
Mike Stump11289f42009-09-09 15:08:12 +00003898template<typename Derived>
3899QualType
John McCall550e0c22009-10-21 00:40:46 +00003900TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003901 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003902 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003903 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003904 if (ElementType.isNull())
3905 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003906
John McCall550e0c22009-10-21 00:40:46 +00003907 QualType Result = TL.getType();
3908 if (getDerived().AlwaysRebuild() ||
3909 ElementType != T->getElementType()) {
3910 Result = getDerived().RebuildConstantArrayType(ElementType,
3911 T->getSizeModifier(),
3912 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00003913 T->getIndexTypeCVRQualifiers(),
3914 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003915 if (Result.isNull())
3916 return QualType();
3917 }
Eli Friedmanf7f102f2012-01-25 22:19:07 +00003918
3919 // We might have either a ConstantArrayType or a VariableArrayType now:
3920 // a ConstantArrayType is allowed to have an element type which is a
3921 // VariableArrayType if the type is dependent. Fortunately, all array
3922 // types have the same location layout.
3923 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00003924 NewTL.setLBracketLoc(TL.getLBracketLoc());
3925 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00003926
John McCall550e0c22009-10-21 00:40:46 +00003927 Expr *Size = TL.getSizeExpr();
3928 if (Size) {
Richard Smith764d2fe2011-12-20 02:08:33 +00003929 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3930 Sema::ConstantEvaluated);
John McCall550e0c22009-10-21 00:40:46 +00003931 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
Eli Friedmanc6237c62012-02-29 03:16:56 +00003932 Size = SemaRef.ActOnConstantExpression(Size).take();
John McCall550e0c22009-10-21 00:40:46 +00003933 }
3934 NewTL.setSizeExpr(Size);
3935
3936 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003937}
Mike Stump11289f42009-09-09 15:08:12 +00003938
Douglas Gregord6ff3322009-08-04 16:50:30 +00003939template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003940QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00003941 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003942 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003943 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003944 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003945 if (ElementType.isNull())
3946 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003947
John McCall550e0c22009-10-21 00:40:46 +00003948 QualType Result = TL.getType();
3949 if (getDerived().AlwaysRebuild() ||
3950 ElementType != T->getElementType()) {
3951 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00003952 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00003953 T->getIndexTypeCVRQualifiers(),
3954 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003955 if (Result.isNull())
3956 return QualType();
3957 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003958
John McCall550e0c22009-10-21 00:40:46 +00003959 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3960 NewTL.setLBracketLoc(TL.getLBracketLoc());
3961 NewTL.setRBracketLoc(TL.getRBracketLoc());
3962 NewTL.setSizeExpr(0);
3963
3964 return Result;
3965}
3966
3967template<typename Derived>
3968QualType
3969TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003970 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003971 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003972 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3973 if (ElementType.isNull())
3974 return QualType();
3975
John McCalldadc5752010-08-24 06:29:42 +00003976 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00003977 = getDerived().TransformExpr(T->getSizeExpr());
3978 if (SizeResult.isInvalid())
3979 return QualType();
3980
John McCallb268a282010-08-23 23:25:46 +00003981 Expr *Size = SizeResult.take();
John McCall550e0c22009-10-21 00:40:46 +00003982
3983 QualType Result = TL.getType();
3984 if (getDerived().AlwaysRebuild() ||
3985 ElementType != T->getElementType() ||
3986 Size != T->getSizeExpr()) {
3987 Result = getDerived().RebuildVariableArrayType(ElementType,
3988 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00003989 Size,
John McCall550e0c22009-10-21 00:40:46 +00003990 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00003991 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003992 if (Result.isNull())
3993 return QualType();
3994 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003995
Serge Pavlov774c6d02014-02-06 03:49:11 +00003996 // We might have constant size array now, but fortunately it has the same
3997 // location layout.
3998 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00003999 NewTL.setLBracketLoc(TL.getLBracketLoc());
4000 NewTL.setRBracketLoc(TL.getRBracketLoc());
4001 NewTL.setSizeExpr(Size);
4002
4003 return Result;
4004}
4005
4006template<typename Derived>
4007QualType
4008TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004009 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004010 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004011 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4012 if (ElementType.isNull())
4013 return QualType();
4014
Richard Smith764d2fe2011-12-20 02:08:33 +00004015 // Array bounds are constant expressions.
4016 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4017 Sema::ConstantEvaluated);
John McCall550e0c22009-10-21 00:40:46 +00004018
John McCall33ddac02011-01-19 10:06:00 +00004019 // Prefer the expression from the TypeLoc; the other may have been uniqued.
4020 Expr *origSize = TL.getSizeExpr();
4021 if (!origSize) origSize = T->getSizeExpr();
4022
4023 ExprResult sizeResult
4024 = getDerived().TransformExpr(origSize);
Eli Friedmanc6237c62012-02-29 03:16:56 +00004025 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall33ddac02011-01-19 10:06:00 +00004026 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00004027 return QualType();
4028
John McCall33ddac02011-01-19 10:06:00 +00004029 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004030
4031 QualType Result = TL.getType();
4032 if (getDerived().AlwaysRebuild() ||
4033 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00004034 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00004035 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
4036 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00004037 size,
John McCall550e0c22009-10-21 00:40:46 +00004038 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004039 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004040 if (Result.isNull())
4041 return QualType();
4042 }
John McCall550e0c22009-10-21 00:40:46 +00004043
4044 // We might have any sort of array type now, but fortunately they
4045 // all have the same location layout.
4046 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4047 NewTL.setLBracketLoc(TL.getLBracketLoc());
4048 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00004049 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00004050
4051 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004052}
Mike Stump11289f42009-09-09 15:08:12 +00004053
4054template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004055QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00004056 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004057 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004058 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004059
4060 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00004061 QualType ElementType = getDerived().TransformType(T->getElementType());
4062 if (ElementType.isNull())
4063 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004064
Richard Smith764d2fe2011-12-20 02:08:33 +00004065 // Vector sizes are constant expressions.
4066 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4067 Sema::ConstantEvaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00004068
John McCalldadc5752010-08-24 06:29:42 +00004069 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanc6237c62012-02-29 03:16:56 +00004070 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004071 if (Size.isInvalid())
4072 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004073
John McCall550e0c22009-10-21 00:40:46 +00004074 QualType Result = TL.getType();
4075 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00004076 ElementType != T->getElementType() ||
4077 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00004078 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCallb268a282010-08-23 23:25:46 +00004079 Size.take(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00004080 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00004081 if (Result.isNull())
4082 return QualType();
4083 }
John McCall550e0c22009-10-21 00:40:46 +00004084
4085 // Result might be dependent or not.
4086 if (isa<DependentSizedExtVectorType>(Result)) {
4087 DependentSizedExtVectorTypeLoc NewTL
4088 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
4089 NewTL.setNameLoc(TL.getNameLoc());
4090 } else {
4091 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4092 NewTL.setNameLoc(TL.getNameLoc());
4093 }
4094
4095 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004096}
Mike Stump11289f42009-09-09 15:08:12 +00004097
4098template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004099QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004100 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004101 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004102 QualType ElementType = getDerived().TransformType(T->getElementType());
4103 if (ElementType.isNull())
4104 return QualType();
4105
John McCall550e0c22009-10-21 00:40:46 +00004106 QualType Result = TL.getType();
4107 if (getDerived().AlwaysRebuild() ||
4108 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00004109 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00004110 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00004111 if (Result.isNull())
4112 return QualType();
4113 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004114
John McCall550e0c22009-10-21 00:40:46 +00004115 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
4116 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004117
John McCall550e0c22009-10-21 00:40:46 +00004118 return Result;
4119}
4120
4121template<typename Derived>
4122QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004123 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004124 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004125 QualType ElementType = getDerived().TransformType(T->getElementType());
4126 if (ElementType.isNull())
4127 return QualType();
4128
4129 QualType Result = TL.getType();
4130 if (getDerived().AlwaysRebuild() ||
4131 ElementType != T->getElementType()) {
4132 Result = getDerived().RebuildExtVectorType(ElementType,
4133 T->getNumElements(),
4134 /*FIXME*/ SourceLocation());
4135 if (Result.isNull())
4136 return QualType();
4137 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004138
John McCall550e0c22009-10-21 00:40:46 +00004139 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4140 NewTL.setNameLoc(TL.getNameLoc());
4141
4142 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004143}
Mike Stump11289f42009-09-09 15:08:12 +00004144
David Blaikie05785d12013-02-20 22:23:23 +00004145template <typename Derived>
4146ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
4147 ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
4148 bool ExpectParameterPack) {
John McCall58f10c32010-03-11 09:03:00 +00004149 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor715e4612011-01-14 22:40:04 +00004150 TypeSourceInfo *NewDI = 0;
Chad Rosier1dcde962012-08-08 18:46:20 +00004151
Douglas Gregor715e4612011-01-14 22:40:04 +00004152 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004153 // If we're substituting into a pack expansion type and we know the
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004154 // length we want to expand to, just substitute for the pattern.
Douglas Gregor715e4612011-01-14 22:40:04 +00004155 TypeLoc OldTL = OldDI->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004156 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004157
Douglas Gregor715e4612011-01-14 22:40:04 +00004158 TypeLocBuilder TLB;
4159 TypeLoc NewTL = OldDI->getTypeLoc();
4160 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00004161
4162 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor715e4612011-01-14 22:40:04 +00004163 OldExpansionTL.getPatternLoc());
4164 if (Result.isNull())
4165 return 0;
Chad Rosier1dcde962012-08-08 18:46:20 +00004166
4167 Result = RebuildPackExpansionType(Result,
4168 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor715e4612011-01-14 22:40:04 +00004169 OldExpansionTL.getEllipsisLoc(),
4170 NumExpansions);
4171 if (Result.isNull())
4172 return 0;
Chad Rosier1dcde962012-08-08 18:46:20 +00004173
Douglas Gregor715e4612011-01-14 22:40:04 +00004174 PackExpansionTypeLoc NewExpansionTL
4175 = TLB.push<PackExpansionTypeLoc>(Result);
4176 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
4177 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
4178 } else
4179 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00004180 if (!NewDI)
4181 return 0;
4182
John McCall8fb0d9d2011-05-01 22:35:37 +00004183 if (NewDI == OldDI && indexAdjustment == 0)
John McCall58f10c32010-03-11 09:03:00 +00004184 return OldParm;
John McCall8fb0d9d2011-05-01 22:35:37 +00004185
4186 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
4187 OldParm->getDeclContext(),
4188 OldParm->getInnerLocStart(),
4189 OldParm->getLocation(),
4190 OldParm->getIdentifier(),
4191 NewDI->getType(),
4192 NewDI,
4193 OldParm->getStorageClass(),
John McCall8fb0d9d2011-05-01 22:35:37 +00004194 /* DefArg */ NULL);
4195 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
4196 OldParm->getFunctionScopeIndex() + indexAdjustment);
4197 return newParm;
John McCall58f10c32010-03-11 09:03:00 +00004198}
4199
4200template<typename Derived>
4201bool TreeTransform<Derived>::
Douglas Gregordd472162011-01-07 00:20:55 +00004202 TransformFunctionTypeParams(SourceLocation Loc,
4203 ParmVarDecl **Params, unsigned NumParams,
4204 const QualType *ParamTypes,
Chris Lattner01cf8db2011-07-20 06:58:45 +00004205 SmallVectorImpl<QualType> &OutParamTypes,
4206 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004207 int indexAdjustment = 0;
4208
Douglas Gregordd472162011-01-07 00:20:55 +00004209 for (unsigned i = 0; i != NumParams; ++i) {
4210 if (ParmVarDecl *OldParm = Params[i]) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004211 assert(OldParm->getFunctionScopeIndex() == i);
4212
David Blaikie05785d12013-02-20 22:23:23 +00004213 Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004214 ParmVarDecl *NewParm = 0;
Douglas Gregor5499af42011-01-05 23:12:31 +00004215 if (OldParm->isParameterPack()) {
4216 // We have a function parameter pack that may need to be expanded.
Chris Lattner01cf8db2011-07-20 06:58:45 +00004217 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00004218
Douglas Gregor5499af42011-01-05 23:12:31 +00004219 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004220 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004221 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004222 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4223 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004224 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4225
Douglas Gregor5499af42011-01-05 23:12:31 +00004226 // Determine whether we should expand the parameter packs.
4227 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004228 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004229 Optional<unsigned> OrigNumExpansions =
4230 ExpansionTL.getTypePtr()->getNumExpansions();
Douglas Gregor715e4612011-01-14 22:40:04 +00004231 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004232 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4233 Pattern.getSourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004234 Unexpanded,
4235 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004236 RetainExpansion,
4237 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004238 return true;
4239 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004240
Douglas Gregor5499af42011-01-05 23:12:31 +00004241 if (ShouldExpand) {
4242 // Expand the function parameter pack into multiple, separate
4243 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00004244 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004245 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004246 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier1dcde962012-08-08 18:46:20 +00004247 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004248 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004249 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004250 OrigNumExpansions,
4251 /*ExpectParameterPack=*/false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004252 if (!NewParm)
4253 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004254
Douglas Gregordd472162011-01-07 00:20:55 +00004255 OutParamTypes.push_back(NewParm->getType());
4256 if (PVars)
4257 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004258 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004259
4260 // If we're supposed to retain a pack expansion, do so by temporarily
4261 // forgetting the partially-substituted parameter pack.
4262 if (RetainExpansion) {
4263 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00004264 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004265 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004266 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004267 OrigNumExpansions,
4268 /*ExpectParameterPack=*/false);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004269 if (!NewParm)
4270 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004271
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004272 OutParamTypes.push_back(NewParm->getType());
4273 if (PVars)
4274 PVars->push_back(NewParm);
4275 }
4276
John McCall8fb0d9d2011-05-01 22:35:37 +00004277 // The next parameter should have the same adjustment as the
4278 // last thing we pushed, but we post-incremented indexAdjustment
4279 // on every push. Also, if we push nothing, the adjustment should
4280 // go down by one.
4281 indexAdjustment--;
4282
Douglas Gregor5499af42011-01-05 23:12:31 +00004283 // We're done with the pack expansion.
4284 continue;
4285 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004286
4287 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004288 // expansion.
Douglas Gregorc52264e2011-03-02 02:04:06 +00004289 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4290 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004291 indexAdjustment,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004292 NumExpansions,
4293 /*ExpectParameterPack=*/true);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004294 } else {
David Blaikie05785d12013-02-20 22:23:23 +00004295 NewParm = getDerived().TransformFunctionTypeParam(
David Blaikie7a30dc52013-02-21 01:47:18 +00004296 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004297 }
Douglas Gregorc52264e2011-03-02 02:04:06 +00004298
John McCall58f10c32010-03-11 09:03:00 +00004299 if (!NewParm)
4300 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004301
Douglas Gregordd472162011-01-07 00:20:55 +00004302 OutParamTypes.push_back(NewParm->getType());
4303 if (PVars)
4304 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004305 continue;
4306 }
John McCall58f10c32010-03-11 09:03:00 +00004307
4308 // Deal with the possibility that we don't have a parameter
4309 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00004310 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00004311 bool IsPackExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004312 Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004313 QualType NewType;
Chad Rosier1dcde962012-08-08 18:46:20 +00004314 if (const PackExpansionType *Expansion
Douglas Gregor5499af42011-01-05 23:12:31 +00004315 = dyn_cast<PackExpansionType>(OldType)) {
4316 // We have a function parameter pack that may need to be expanded.
4317 QualType Pattern = Expansion->getPattern();
Chris Lattner01cf8db2011-07-20 06:58:45 +00004318 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor5499af42011-01-05 23:12:31 +00004319 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00004320
Douglas Gregor5499af42011-01-05 23:12:31 +00004321 // Determine whether we should expand the parameter packs.
4322 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004323 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00004324 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004325 Unexpanded,
4326 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004327 RetainExpansion,
4328 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00004329 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00004330 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004331
Douglas Gregor5499af42011-01-05 23:12:31 +00004332 if (ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004333 // Expand the function parameter pack into multiple, separate
Douglas Gregor5499af42011-01-05 23:12:31 +00004334 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004335 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004336 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4337 QualType NewType = getDerived().TransformType(Pattern);
4338 if (NewType.isNull())
4339 return true;
John McCall58f10c32010-03-11 09:03:00 +00004340
Douglas Gregordd472162011-01-07 00:20:55 +00004341 OutParamTypes.push_back(NewType);
4342 if (PVars)
4343 PVars->push_back(0);
Douglas Gregor5499af42011-01-05 23:12:31 +00004344 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004345
Douglas Gregor5499af42011-01-05 23:12:31 +00004346 // We're done with the pack expansion.
4347 continue;
4348 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004349
Douglas Gregor48d24112011-01-10 20:53:55 +00004350 // If we're supposed to retain a pack expansion, do so by temporarily
4351 // forgetting the partially-substituted parameter pack.
4352 if (RetainExpansion) {
4353 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4354 QualType NewType = getDerived().TransformType(Pattern);
4355 if (NewType.isNull())
4356 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004357
Douglas Gregor48d24112011-01-10 20:53:55 +00004358 OutParamTypes.push_back(NewType);
4359 if (PVars)
4360 PVars->push_back(0);
4361 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004362
Chad Rosier1dcde962012-08-08 18:46:20 +00004363 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004364 // expansion.
4365 OldType = Expansion->getPattern();
4366 IsPackExpansion = true;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004367 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4368 NewType = getDerived().TransformType(OldType);
4369 } else {
4370 NewType = getDerived().TransformType(OldType);
Douglas Gregor5499af42011-01-05 23:12:31 +00004371 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004372
Douglas Gregor5499af42011-01-05 23:12:31 +00004373 if (NewType.isNull())
4374 return true;
4375
4376 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004377 NewType = getSema().Context.getPackExpansionType(NewType,
4378 NumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00004379
Douglas Gregordd472162011-01-07 00:20:55 +00004380 OutParamTypes.push_back(NewType);
4381 if (PVars)
4382 PVars->push_back(0);
John McCall58f10c32010-03-11 09:03:00 +00004383 }
4384
John McCall8fb0d9d2011-05-01 22:35:37 +00004385#ifndef NDEBUG
4386 if (PVars) {
4387 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4388 if (ParmVarDecl *parm = (*PVars)[i])
4389 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor5499af42011-01-05 23:12:31 +00004390 }
John McCall8fb0d9d2011-05-01 22:35:37 +00004391#endif
4392
4393 return false;
4394}
John McCall58f10c32010-03-11 09:03:00 +00004395
4396template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004397QualType
John McCall550e0c22009-10-21 00:40:46 +00004398TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004399 FunctionProtoTypeLoc TL) {
Douglas Gregor3024f072012-04-16 07:05:22 +00004400 return getDerived().TransformFunctionProtoType(TLB, TL, 0, 0);
4401}
4402
4403template<typename Derived>
4404QualType
4405TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
4406 FunctionProtoTypeLoc TL,
4407 CXXRecordDecl *ThisContext,
4408 unsigned ThisTypeQuals) {
Douglas Gregor4afc2362010-08-31 00:26:14 +00004409 // Transform the parameters and return type.
4410 //
Richard Smithf623c962012-04-17 00:58:00 +00004411 // We are required to instantiate the params and return type in source order.
Douglas Gregor7fb25412010-10-01 18:44:50 +00004412 // When the function has a trailing return type, we instantiate the
4413 // parameters before the return type, since the return type can then refer
4414 // to the parameters themselves (via decltype, sizeof, etc.).
4415 //
Chris Lattner01cf8db2011-07-20 06:58:45 +00004416 SmallVector<QualType, 4> ParamTypes;
4417 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall424cec92011-01-19 06:33:43 +00004418 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00004419
Douglas Gregor7fb25412010-10-01 18:44:50 +00004420 QualType ResultType;
4421
Richard Smith1226c602012-08-14 22:51:13 +00004422 if (T->hasTrailingReturn()) {
Alp Toker9cacbab2014-01-20 20:26:09 +00004423 if (getDerived().TransformFunctionTypeParams(
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004424 TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(),
Alp Toker9cacbab2014-01-20 20:26:09 +00004425 TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004426 return QualType();
4427
Douglas Gregor3024f072012-04-16 07:05:22 +00004428 {
4429 // C++11 [expr.prim.general]p3:
Chad Rosier1dcde962012-08-08 18:46:20 +00004430 // If a declaration declares a member function or member function
4431 // template of a class X, the expression this is a prvalue of type
Douglas Gregor3024f072012-04-16 07:05:22 +00004432 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier1dcde962012-08-08 18:46:20 +00004433 // and the end of the function-definition, member-declarator, or
Douglas Gregor3024f072012-04-16 07:05:22 +00004434 // declarator.
4435 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier1dcde962012-08-08 18:46:20 +00004436
Alp Toker42a16a62014-01-25 23:51:36 +00004437 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor3024f072012-04-16 07:05:22 +00004438 if (ResultType.isNull())
4439 return QualType();
4440 }
Douglas Gregor7fb25412010-10-01 18:44:50 +00004441 }
4442 else {
Alp Toker42a16a62014-01-25 23:51:36 +00004443 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00004444 if (ResultType.isNull())
4445 return QualType();
4446
Alp Toker9cacbab2014-01-20 20:26:09 +00004447 if (getDerived().TransformFunctionTypeParams(
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004448 TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(),
Alp Toker9cacbab2014-01-20 20:26:09 +00004449 TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004450 return QualType();
4451 }
4452
Richard Smithf623c962012-04-17 00:58:00 +00004453 // FIXME: Need to transform the exception-specification too.
4454
John McCall550e0c22009-10-21 00:40:46 +00004455 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00004456 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() ||
Alp Toker9cacbab2014-01-20 20:26:09 +00004457 T->getNumParams() != ParamTypes.size() ||
4458 !std::equal(T->param_type_begin(), T->param_type_end(),
4459 ParamTypes.begin())) {
Jordan Rose5c382722013-03-08 21:51:21 +00004460 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +00004461 T->getExtProtoInfo());
John McCall550e0c22009-10-21 00:40:46 +00004462 if (Result.isNull())
4463 return QualType();
4464 }
Mike Stump11289f42009-09-09 15:08:12 +00004465
John McCall550e0c22009-10-21 00:40:46 +00004466 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004467 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00004468 NewTL.setLParenLoc(TL.getLParenLoc());
4469 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004470 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004471 for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i)
4472 NewTL.setParam(i, ParamDecls[i]);
John McCall550e0c22009-10-21 00:40:46 +00004473
4474 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004475}
Mike Stump11289f42009-09-09 15:08:12 +00004476
Douglas Gregord6ff3322009-08-04 16:50:30 +00004477template<typename Derived>
4478QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00004479 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004480 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004481 const FunctionNoProtoType *T = TL.getTypePtr();
Alp Toker42a16a62014-01-25 23:51:36 +00004482 QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
John McCall550e0c22009-10-21 00:40:46 +00004483 if (ResultType.isNull())
4484 return QualType();
4485
4486 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00004487 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType())
John McCall550e0c22009-10-21 00:40:46 +00004488 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4489
4490 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004491 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00004492 NewTL.setLParenLoc(TL.getLParenLoc());
4493 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004494 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCall550e0c22009-10-21 00:40:46 +00004495
4496 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004497}
Mike Stump11289f42009-09-09 15:08:12 +00004498
John McCallb96ec562009-12-04 22:46:56 +00004499template<typename Derived> QualType
4500TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004501 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004502 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004503 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00004504 if (!D)
4505 return QualType();
4506
4507 QualType Result = TL.getType();
4508 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4509 Result = getDerived().RebuildUnresolvedUsingType(D);
4510 if (Result.isNull())
4511 return QualType();
4512 }
4513
4514 // We might get an arbitrary type spec type back. We should at
4515 // least always get a type spec type, though.
4516 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4517 NewTL.setNameLoc(TL.getNameLoc());
4518
4519 return Result;
4520}
4521
Douglas Gregord6ff3322009-08-04 16:50:30 +00004522template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004523QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004524 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004525 const TypedefType *T = TL.getTypePtr();
Richard Smithdda56e42011-04-15 14:24:37 +00004526 TypedefNameDecl *Typedef
4527 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4528 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004529 if (!Typedef)
4530 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004531
John McCall550e0c22009-10-21 00:40:46 +00004532 QualType Result = TL.getType();
4533 if (getDerived().AlwaysRebuild() ||
4534 Typedef != T->getDecl()) {
4535 Result = getDerived().RebuildTypedefType(Typedef);
4536 if (Result.isNull())
4537 return QualType();
4538 }
Mike Stump11289f42009-09-09 15:08:12 +00004539
John McCall550e0c22009-10-21 00:40:46 +00004540 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4541 NewTL.setNameLoc(TL.getNameLoc());
4542
4543 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004544}
Mike Stump11289f42009-09-09 15:08:12 +00004545
Douglas Gregord6ff3322009-08-04 16:50:30 +00004546template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004547QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004548 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00004549 // typeof expressions are not potentially evaluated contexts
Eli Friedman15681d62012-09-26 04:34:21 +00004550 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4551 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00004552
John McCalldadc5752010-08-24 06:29:42 +00004553 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004554 if (E.isInvalid())
4555 return QualType();
4556
Eli Friedmane4f22df2012-02-29 04:03:55 +00004557 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
4558 if (E.isInvalid())
4559 return QualType();
4560
John McCall550e0c22009-10-21 00:40:46 +00004561 QualType Result = TL.getType();
4562 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00004563 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004564 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00004565 if (Result.isNull())
4566 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004567 }
John McCall550e0c22009-10-21 00:40:46 +00004568 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00004569
John McCall550e0c22009-10-21 00:40:46 +00004570 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004571 NewTL.setTypeofLoc(TL.getTypeofLoc());
4572 NewTL.setLParenLoc(TL.getLParenLoc());
4573 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00004574
4575 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004576}
Mike Stump11289f42009-09-09 15:08:12 +00004577
4578template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004579QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004580 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00004581 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4582 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4583 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00004584 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004585
John McCall550e0c22009-10-21 00:40:46 +00004586 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00004587 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4588 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00004589 if (Result.isNull())
4590 return QualType();
4591 }
Mike Stump11289f42009-09-09 15:08:12 +00004592
John McCall550e0c22009-10-21 00:40:46 +00004593 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004594 NewTL.setTypeofLoc(TL.getTypeofLoc());
4595 NewTL.setLParenLoc(TL.getLParenLoc());
4596 NewTL.setRParenLoc(TL.getRParenLoc());
4597 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00004598
4599 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004600}
Mike Stump11289f42009-09-09 15:08:12 +00004601
4602template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004603QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004604 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004605 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004606
Douglas Gregore922c772009-08-04 22:27:00 +00004607 // decltype expressions are not potentially evaluated contexts
Richard Smithfd555f62012-02-22 02:04:18 +00004608 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, 0,
4609 /*IsDecltype=*/ true);
Mike Stump11289f42009-09-09 15:08:12 +00004610
John McCalldadc5752010-08-24 06:29:42 +00004611 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004612 if (E.isInvalid())
4613 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004614
Richard Smithfd555f62012-02-22 02:04:18 +00004615 E = getSema().ActOnDecltypeExpression(E.take());
4616 if (E.isInvalid())
4617 return QualType();
4618
John McCall550e0c22009-10-21 00:40:46 +00004619 QualType Result = TL.getType();
4620 if (getDerived().AlwaysRebuild() ||
4621 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004622 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004623 if (Result.isNull())
4624 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004625 }
John McCall550e0c22009-10-21 00:40:46 +00004626 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00004627
John McCall550e0c22009-10-21 00:40:46 +00004628 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4629 NewTL.setNameLoc(TL.getNameLoc());
4630
4631 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004632}
4633
4634template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00004635QualType TreeTransform<Derived>::TransformUnaryTransformType(
4636 TypeLocBuilder &TLB,
4637 UnaryTransformTypeLoc TL) {
4638 QualType Result = TL.getType();
4639 if (Result->isDependentType()) {
4640 const UnaryTransformType *T = TL.getTypePtr();
4641 QualType NewBase =
4642 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4643 Result = getDerived().RebuildUnaryTransformType(NewBase,
4644 T->getUTTKind(),
4645 TL.getKWLoc());
4646 if (Result.isNull())
4647 return QualType();
4648 }
4649
4650 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4651 NewTL.setKWLoc(TL.getKWLoc());
4652 NewTL.setParensRange(TL.getParensRange());
4653 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4654 return Result;
4655}
4656
4657template<typename Derived>
Richard Smith30482bc2011-02-20 03:19:35 +00004658QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4659 AutoTypeLoc TL) {
4660 const AutoType *T = TL.getTypePtr();
4661 QualType OldDeduced = T->getDeducedType();
4662 QualType NewDeduced;
4663 if (!OldDeduced.isNull()) {
4664 NewDeduced = getDerived().TransformType(OldDeduced);
4665 if (NewDeduced.isNull())
4666 return QualType();
4667 }
4668
4669 QualType Result = TL.getType();
Richard Smith27d807c2013-04-30 13:56:41 +00004670 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
4671 T->isDependentType()) {
Richard Smith74aeef52013-04-26 16:15:35 +00004672 Result = getDerived().RebuildAutoType(NewDeduced, T->isDecltypeAuto());
Richard Smith30482bc2011-02-20 03:19:35 +00004673 if (Result.isNull())
4674 return QualType();
4675 }
4676
4677 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4678 NewTL.setNameLoc(TL.getNameLoc());
4679
4680 return Result;
4681}
4682
4683template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004684QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004685 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004686 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004687 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004688 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4689 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004690 if (!Record)
4691 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004692
John McCall550e0c22009-10-21 00:40:46 +00004693 QualType Result = TL.getType();
4694 if (getDerived().AlwaysRebuild() ||
4695 Record != T->getDecl()) {
4696 Result = getDerived().RebuildRecordType(Record);
4697 if (Result.isNull())
4698 return QualType();
4699 }
Mike Stump11289f42009-09-09 15:08:12 +00004700
John McCall550e0c22009-10-21 00:40:46 +00004701 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4702 NewTL.setNameLoc(TL.getNameLoc());
4703
4704 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004705}
Mike Stump11289f42009-09-09 15:08:12 +00004706
4707template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004708QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004709 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004710 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004711 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004712 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4713 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004714 if (!Enum)
4715 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004716
John McCall550e0c22009-10-21 00:40:46 +00004717 QualType Result = TL.getType();
4718 if (getDerived().AlwaysRebuild() ||
4719 Enum != T->getDecl()) {
4720 Result = getDerived().RebuildEnumType(Enum);
4721 if (Result.isNull())
4722 return QualType();
4723 }
Mike Stump11289f42009-09-09 15:08:12 +00004724
John McCall550e0c22009-10-21 00:40:46 +00004725 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4726 NewTL.setNameLoc(TL.getNameLoc());
4727
4728 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004729}
John McCallfcc33b02009-09-05 00:15:47 +00004730
John McCalle78aac42010-03-10 03:28:59 +00004731template<typename Derived>
4732QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4733 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004734 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00004735 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4736 TL.getTypePtr()->getDecl());
4737 if (!D) return QualType();
4738
4739 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4740 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4741 return T;
4742}
4743
Douglas Gregord6ff3322009-08-04 16:50:30 +00004744template<typename Derived>
4745QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004746 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004747 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004748 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004749}
4750
Mike Stump11289f42009-09-09 15:08:12 +00004751template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00004752QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004753 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004754 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004755 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00004756
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004757 // Substitute into the replacement type, which itself might involve something
4758 // that needs to be transformed. This only tends to occur with default
4759 // template arguments of template template parameters.
4760 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4761 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4762 if (Replacement.isNull())
4763 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00004764
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004765 // Always canonicalize the replacement type.
4766 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4767 QualType Result
Chad Rosier1dcde962012-08-08 18:46:20 +00004768 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004769 Replacement);
Chad Rosier1dcde962012-08-08 18:46:20 +00004770
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004771 // Propagate type-source information.
4772 SubstTemplateTypeParmTypeLoc NewTL
4773 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4774 NewTL.setNameLoc(TL.getNameLoc());
4775 return Result;
4776
John McCallcebee162009-10-18 09:09:24 +00004777}
4778
4779template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00004780QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4781 TypeLocBuilder &TLB,
4782 SubstTemplateTypeParmPackTypeLoc TL) {
4783 return TransformTypeSpecType(TLB, TL);
4784}
4785
4786template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00004787QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00004788 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004789 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00004790 const TemplateSpecializationType *T = TL.getTypePtr();
4791
Douglas Gregordf846d12011-03-02 18:46:51 +00004792 // The nested-name-specifier never matters in a TemplateSpecializationType,
4793 // because we can't have a dependent nested-name-specifier anyway.
4794 CXXScopeSpec SS;
Mike Stump11289f42009-09-09 15:08:12 +00004795 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00004796 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4797 TL.getTemplateNameLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004798 if (Template.isNull())
4799 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004800
John McCall31f82722010-11-12 08:19:04 +00004801 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4802}
4803
Eli Friedman0dfb8892011-10-06 23:00:33 +00004804template<typename Derived>
4805QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
4806 AtomicTypeLoc TL) {
4807 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
4808 if (ValueType.isNull())
4809 return QualType();
4810
4811 QualType Result = TL.getType();
4812 if (getDerived().AlwaysRebuild() ||
4813 ValueType != TL.getValueLoc().getType()) {
4814 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
4815 if (Result.isNull())
4816 return QualType();
4817 }
4818
4819 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
4820 NewTL.setKWLoc(TL.getKWLoc());
4821 NewTL.setLParenLoc(TL.getLParenLoc());
4822 NewTL.setRParenLoc(TL.getRParenLoc());
4823
4824 return Result;
4825}
4826
Chad Rosier1dcde962012-08-08 18:46:20 +00004827 /// \brief Simple iterator that traverses the template arguments in a
Douglas Gregorfe921a72010-12-20 23:36:19 +00004828 /// container that provides a \c getArgLoc() member function.
4829 ///
4830 /// This iterator is intended to be used with the iterator form of
4831 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4832 template<typename ArgLocContainer>
4833 class TemplateArgumentLocContainerIterator {
4834 ArgLocContainer *Container;
4835 unsigned Index;
Chad Rosier1dcde962012-08-08 18:46:20 +00004836
Douglas Gregorfe921a72010-12-20 23:36:19 +00004837 public:
4838 typedef TemplateArgumentLoc value_type;
4839 typedef TemplateArgumentLoc reference;
4840 typedef int difference_type;
4841 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00004842
Douglas Gregorfe921a72010-12-20 23:36:19 +00004843 class pointer {
4844 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00004845
Douglas Gregorfe921a72010-12-20 23:36:19 +00004846 public:
4847 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00004848
Douglas Gregorfe921a72010-12-20 23:36:19 +00004849 const TemplateArgumentLoc *operator->() const {
4850 return &Arg;
4851 }
4852 };
Chad Rosier1dcde962012-08-08 18:46:20 +00004853
4854
Douglas Gregorfe921a72010-12-20 23:36:19 +00004855 TemplateArgumentLocContainerIterator() {}
Chad Rosier1dcde962012-08-08 18:46:20 +00004856
Douglas Gregorfe921a72010-12-20 23:36:19 +00004857 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4858 unsigned Index)
4859 : Container(&Container), Index(Index) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00004860
Douglas Gregorfe921a72010-12-20 23:36:19 +00004861 TemplateArgumentLocContainerIterator &operator++() {
4862 ++Index;
4863 return *this;
4864 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004865
Douglas Gregorfe921a72010-12-20 23:36:19 +00004866 TemplateArgumentLocContainerIterator operator++(int) {
4867 TemplateArgumentLocContainerIterator Old(*this);
4868 ++(*this);
4869 return Old;
4870 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004871
Douglas Gregorfe921a72010-12-20 23:36:19 +00004872 TemplateArgumentLoc operator*() const {
4873 return Container->getArgLoc(Index);
4874 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004875
Douglas Gregorfe921a72010-12-20 23:36:19 +00004876 pointer operator->() const {
4877 return pointer(Container->getArgLoc(Index));
4878 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004879
Douglas Gregorfe921a72010-12-20 23:36:19 +00004880 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004881 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004882 return X.Container == Y.Container && X.Index == Y.Index;
4883 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004884
Douglas Gregorfe921a72010-12-20 23:36:19 +00004885 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004886 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004887 return !(X == Y);
4888 }
4889 };
Chad Rosier1dcde962012-08-08 18:46:20 +00004890
4891
John McCall31f82722010-11-12 08:19:04 +00004892template <typename Derived>
4893QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4894 TypeLocBuilder &TLB,
4895 TemplateSpecializationTypeLoc TL,
4896 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00004897 TemplateArgumentListInfo NewTemplateArgs;
4898 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4899 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00004900 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4901 ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00004902 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregorfe921a72010-12-20 23:36:19 +00004903 ArgIterator(TL, TL.getNumArgs()),
4904 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00004905 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004906
John McCall0ad16662009-10-29 08:12:44 +00004907 // FIXME: maybe don't rebuild if all the template arguments are the same.
4908
4909 QualType Result =
4910 getDerived().RebuildTemplateSpecializationType(Template,
4911 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00004912 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00004913
4914 if (!Result.isNull()) {
Richard Smith3f1b5d02011-05-05 21:57:07 +00004915 // Specializations of template template parameters are represented as
4916 // TemplateSpecializationTypes, and substitution of type alias templates
4917 // within a dependent context can transform them into
4918 // DependentTemplateSpecializationTypes.
4919 if (isa<DependentTemplateSpecializationType>(Result)) {
4920 DependentTemplateSpecializationTypeLoc NewTL
4921 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004922 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3f1b5d02011-05-05 21:57:07 +00004923 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00004924 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004925 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3f1b5d02011-05-05 21:57:07 +00004926 NewTL.setLAngleLoc(TL.getLAngleLoc());
4927 NewTL.setRAngleLoc(TL.getRAngleLoc());
4928 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4929 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4930 return Result;
4931 }
4932
John McCall0ad16662009-10-29 08:12:44 +00004933 TemplateSpecializationTypeLoc NewTL
4934 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004935 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall0ad16662009-10-29 08:12:44 +00004936 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4937 NewTL.setLAngleLoc(TL.getLAngleLoc());
4938 NewTL.setRAngleLoc(TL.getRAngleLoc());
4939 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4940 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004941 }
Mike Stump11289f42009-09-09 15:08:12 +00004942
John McCall0ad16662009-10-29 08:12:44 +00004943 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004944}
Mike Stump11289f42009-09-09 15:08:12 +00004945
Douglas Gregor5a064722011-02-28 17:23:35 +00004946template <typename Derived>
4947QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4948 TypeLocBuilder &TLB,
4949 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +00004950 TemplateName Template,
4951 CXXScopeSpec &SS) {
Douglas Gregor5a064722011-02-28 17:23:35 +00004952 TemplateArgumentListInfo NewTemplateArgs;
4953 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4954 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4955 typedef TemplateArgumentLocContainerIterator<
4956 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00004957 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor5a064722011-02-28 17:23:35 +00004958 ArgIterator(TL, TL.getNumArgs()),
4959 NewTemplateArgs))
4960 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00004961
Douglas Gregor5a064722011-02-28 17:23:35 +00004962 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier1dcde962012-08-08 18:46:20 +00004963
Douglas Gregor5a064722011-02-28 17:23:35 +00004964 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4965 QualType Result
4966 = getSema().Context.getDependentTemplateSpecializationType(
4967 TL.getTypePtr()->getKeyword(),
4968 DTN->getQualifier(),
4969 DTN->getIdentifier(),
4970 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00004971
Douglas Gregor5a064722011-02-28 17:23:35 +00004972 DependentTemplateSpecializationTypeLoc NewTL
4973 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004974 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004975 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00004976 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004977 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00004978 NewTL.setLAngleLoc(TL.getLAngleLoc());
4979 NewTL.setRAngleLoc(TL.getRAngleLoc());
4980 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4981 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4982 return Result;
4983 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004984
4985 QualType Result
Douglas Gregor5a064722011-02-28 17:23:35 +00004986 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004987 TL.getTemplateNameLoc(),
Douglas Gregor5a064722011-02-28 17:23:35 +00004988 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00004989
Douglas Gregor5a064722011-02-28 17:23:35 +00004990 if (!Result.isNull()) {
4991 /// FIXME: Wrap this in an elaborated-type-specifier?
4992 TemplateSpecializationTypeLoc NewTL
4993 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00004994 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004995 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00004996 NewTL.setLAngleLoc(TL.getLAngleLoc());
4997 NewTL.setRAngleLoc(TL.getRAngleLoc());
4998 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4999 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5000 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005001
Douglas Gregor5a064722011-02-28 17:23:35 +00005002 return Result;
5003}
5004
Mike Stump11289f42009-09-09 15:08:12 +00005005template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005006QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00005007TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005008 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005009 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00005010
Douglas Gregor844cb502011-03-01 18:12:44 +00005011 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara6150c882010-05-11 21:36:43 +00005012 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor844cb502011-03-01 18:12:44 +00005013 if (TL.getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005014 QualifierLoc
Douglas Gregor844cb502011-03-01 18:12:44 +00005015 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5016 if (!QualifierLoc)
Abramo Bagnara6150c882010-05-11 21:36:43 +00005017 return QualType();
5018 }
Mike Stump11289f42009-09-09 15:08:12 +00005019
John McCall31f82722010-11-12 08:19:04 +00005020 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
5021 if (NamedT.isNull())
5022 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00005023
Richard Smith3f1b5d02011-05-05 21:57:07 +00005024 // C++0x [dcl.type.elab]p2:
5025 // If the identifier resolves to a typedef-name or the simple-template-id
5026 // resolves to an alias template specialization, the
5027 // elaborated-type-specifier is ill-formed.
Richard Smith0c4a34b2011-05-14 15:04:18 +00005028 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
5029 if (const TemplateSpecializationType *TST =
5030 NamedT->getAs<TemplateSpecializationType>()) {
5031 TemplateName Template = TST->getTemplateName();
5032 if (TypeAliasTemplateDecl *TAT =
5033 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
5034 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
5035 diag::err_tag_reference_non_tag) << 4;
5036 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
5037 }
Richard Smith3f1b5d02011-05-05 21:57:07 +00005038 }
5039 }
5040
John McCall550e0c22009-10-21 00:40:46 +00005041 QualType Result = TL.getType();
5042 if (getDerived().AlwaysRebuild() ||
Douglas Gregor844cb502011-03-01 18:12:44 +00005043 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00005044 NamedT != T->getNamedType()) {
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005045 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00005046 T->getKeyword(),
Douglas Gregor844cb502011-03-01 18:12:44 +00005047 QualifierLoc, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00005048 if (Result.isNull())
5049 return QualType();
5050 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00005051
Abramo Bagnara6150c882010-05-11 21:36:43 +00005052 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005053 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005054 NewTL.setQualifierLoc(QualifierLoc);
John McCall550e0c22009-10-21 00:40:46 +00005055 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005056}
Mike Stump11289f42009-09-09 15:08:12 +00005057
5058template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00005059QualType TreeTransform<Derived>::TransformAttributedType(
5060 TypeLocBuilder &TLB,
5061 AttributedTypeLoc TL) {
5062 const AttributedType *oldType = TL.getTypePtr();
5063 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
5064 if (modifiedType.isNull())
5065 return QualType();
5066
5067 QualType result = TL.getType();
5068
5069 // FIXME: dependent operand expressions?
5070 if (getDerived().AlwaysRebuild() ||
5071 modifiedType != oldType->getModifiedType()) {
5072 // TODO: this is really lame; we should really be rebuilding the
5073 // equivalent type from first principles.
5074 QualType equivalentType
5075 = getDerived().TransformType(oldType->getEquivalentType());
5076 if (equivalentType.isNull())
5077 return QualType();
5078 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
5079 modifiedType,
5080 equivalentType);
5081 }
5082
5083 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
5084 newTL.setAttrNameLoc(TL.getAttrNameLoc());
5085 if (TL.hasAttrOperand())
5086 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5087 if (TL.hasAttrExprOperand())
5088 newTL.setAttrExprOperand(TL.getAttrExprOperand());
5089 else if (TL.hasAttrEnumOperand())
5090 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
5091
5092 return result;
5093}
5094
5095template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00005096QualType
5097TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
5098 ParenTypeLoc TL) {
5099 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
5100 if (Inner.isNull())
5101 return QualType();
5102
5103 QualType Result = TL.getType();
5104 if (getDerived().AlwaysRebuild() ||
5105 Inner != TL.getInnerLoc().getType()) {
5106 Result = getDerived().RebuildParenType(Inner);
5107 if (Result.isNull())
5108 return QualType();
5109 }
5110
5111 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
5112 NewTL.setLParenLoc(TL.getLParenLoc());
5113 NewTL.setRParenLoc(TL.getRParenLoc());
5114 return Result;
5115}
5116
5117template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00005118QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005119 DependentNameTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005120 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00005121
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005122 NestedNameSpecifierLoc QualifierLoc
5123 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5124 if (!QualifierLoc)
Douglas Gregord6ff3322009-08-04 16:50:30 +00005125 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005126
John McCallc392f372010-06-11 00:33:02 +00005127 QualType Result
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005128 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005129 TL.getElaboratedKeywordLoc(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005130 QualifierLoc,
5131 T->getIdentifier(),
John McCallc392f372010-06-11 00:33:02 +00005132 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00005133 if (Result.isNull())
5134 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005135
Abramo Bagnarad7548482010-05-19 21:37:53 +00005136 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
5137 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00005138 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
5139
Abramo Bagnarad7548482010-05-19 21:37:53 +00005140 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005141 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005142 NewTL.setQualifierLoc(QualifierLoc);
John McCallc392f372010-06-11 00:33:02 +00005143 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00005144 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005145 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005146 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00005147 NewTL.setNameLoc(TL.getNameLoc());
5148 }
John McCall550e0c22009-10-21 00:40:46 +00005149 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005150}
Mike Stump11289f42009-09-09 15:08:12 +00005151
Douglas Gregord6ff3322009-08-04 16:50:30 +00005152template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00005153QualType TreeTransform<Derived>::
5154 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005155 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregora7a795b2011-03-01 20:11:18 +00005156 NestedNameSpecifierLoc QualifierLoc;
5157 if (TL.getQualifierLoc()) {
5158 QualifierLoc
5159 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5160 if (!QualifierLoc)
Douglas Gregor5a064722011-02-28 17:23:35 +00005161 return QualType();
5162 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005163
John McCall31f82722010-11-12 08:19:04 +00005164 return getDerived()
Douglas Gregora7a795b2011-03-01 20:11:18 +00005165 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall31f82722010-11-12 08:19:04 +00005166}
5167
5168template<typename Derived>
5169QualType TreeTransform<Derived>::
Douglas Gregora7a795b2011-03-01 20:11:18 +00005170TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
5171 DependentTemplateSpecializationTypeLoc TL,
5172 NestedNameSpecifierLoc QualifierLoc) {
5173 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00005174
Douglas Gregora7a795b2011-03-01 20:11:18 +00005175 TemplateArgumentListInfo NewTemplateArgs;
5176 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5177 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00005178
Douglas Gregora7a795b2011-03-01 20:11:18 +00005179 typedef TemplateArgumentLocContainerIterator<
5180 DependentTemplateSpecializationTypeLoc> ArgIterator;
5181 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5182 ArgIterator(TL, TL.getNumArgs()),
5183 NewTemplateArgs))
5184 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005185
Douglas Gregora7a795b2011-03-01 20:11:18 +00005186 QualType Result
5187 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
5188 QualifierLoc,
5189 T->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005190 TL.getTemplateNameLoc(),
Douglas Gregora7a795b2011-03-01 20:11:18 +00005191 NewTemplateArgs);
5192 if (Result.isNull())
5193 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005194
Douglas Gregora7a795b2011-03-01 20:11:18 +00005195 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
5196 QualType NamedT = ElabT->getNamedType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005197
Douglas Gregora7a795b2011-03-01 20:11:18 +00005198 // Copy information relevant to the template specialization.
5199 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor43f788f2011-03-07 02:33:33 +00005200 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005201 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005202 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005203 NamedTL.setLAngleLoc(TL.getLAngleLoc());
5204 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005205 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005206 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier1dcde962012-08-08 18:46:20 +00005207
Douglas Gregora7a795b2011-03-01 20:11:18 +00005208 // Copy information relevant to the elaborated type.
5209 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005210 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005211 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor43f788f2011-03-07 02:33:33 +00005212 } else if (isa<DependentTemplateSpecializationType>(Result)) {
5213 DependentTemplateSpecializationTypeLoc SpecTL
5214 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005215 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005216 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005217 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005218 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005219 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5220 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005221 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005222 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005223 } else {
Douglas Gregor43f788f2011-03-07 02:33:33 +00005224 TemplateSpecializationTypeLoc SpecTL
5225 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005226 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005227 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005228 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5229 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005230 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005231 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005232 }
5233 return Result;
5234}
5235
5236template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00005237QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5238 PackExpansionTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005239 QualType Pattern
5240 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor822d0302011-01-12 17:07:58 +00005241 if (Pattern.isNull())
5242 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005243
5244 QualType Result = TL.getType();
Douglas Gregor822d0302011-01-12 17:07:58 +00005245 if (getDerived().AlwaysRebuild() ||
5246 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005247 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00005248 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00005249 TL.getEllipsisLoc(),
5250 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00005251 if (Result.isNull())
5252 return QualType();
5253 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005254
Douglas Gregor822d0302011-01-12 17:07:58 +00005255 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5256 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5257 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00005258}
5259
5260template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005261QualType
5262TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005263 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005264 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00005265 TLB.pushFullCopy(TL);
5266 return TL.getType();
5267}
5268
5269template<typename Derived>
5270QualType
5271TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005272 ObjCObjectTypeLoc TL) {
John McCall8b07ec22010-05-15 11:32:37 +00005273 // ObjCObjectType is never dependent.
5274 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00005275 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005276}
Mike Stump11289f42009-09-09 15:08:12 +00005277
5278template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005279QualType
5280TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005281 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005282 // ObjCObjectPointerType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00005283 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00005284 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00005285}
5286
Douglas Gregord6ff3322009-08-04 16:50:30 +00005287//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00005288// Statement transformation
5289//===----------------------------------------------------------------------===//
5290template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005291StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005292TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00005293 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005294}
5295
5296template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005297StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005298TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
5299 return getDerived().TransformCompoundStmt(S, false);
5300}
5301
5302template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005303StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005304TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00005305 bool IsStmtExpr) {
Dmitri Gribenko800ddf32012-02-14 22:14:32 +00005306 Sema::CompoundScopeRAII CompoundScope(getSema());
5307
John McCall1ababa62010-08-27 19:56:05 +00005308 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00005309 bool SubStmtChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005310 SmallVector<Stmt*, 8> Statements;
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005311 for (auto *B : S->body()) {
5312 StmtResult Result = getDerived().TransformStmt(B);
John McCall1ababa62010-08-27 19:56:05 +00005313 if (Result.isInvalid()) {
5314 // Immediately fail if this was a DeclStmt, since it's very
5315 // likely that this will cause problems for future statements.
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005316 if (isa<DeclStmt>(B))
John McCall1ababa62010-08-27 19:56:05 +00005317 return StmtError();
5318
5319 // Otherwise, just keep processing substatements and fail later.
5320 SubStmtInvalid = true;
5321 continue;
5322 }
Mike Stump11289f42009-09-09 15:08:12 +00005323
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005324 SubStmtChanged = SubStmtChanged || Result.get() != B;
Douglas Gregorebe10102009-08-20 07:17:43 +00005325 Statements.push_back(Result.takeAs<Stmt>());
5326 }
Mike Stump11289f42009-09-09 15:08:12 +00005327
John McCall1ababa62010-08-27 19:56:05 +00005328 if (SubStmtInvalid)
5329 return StmtError();
5330
Douglas Gregorebe10102009-08-20 07:17:43 +00005331 if (!getDerived().AlwaysRebuild() &&
5332 !SubStmtChanged)
John McCallc3007a22010-10-26 07:05:15 +00005333 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005334
5335 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00005336 Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00005337 S->getRBracLoc(),
5338 IsStmtExpr);
5339}
Mike Stump11289f42009-09-09 15:08:12 +00005340
Douglas Gregorebe10102009-08-20 07:17:43 +00005341template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005342StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005343TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005344 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00005345 {
Eli Friedman1f4f9dd2012-01-18 02:54:10 +00005346 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5347 Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005348
Eli Friedman06577382009-11-19 03:14:00 +00005349 // Transform the left-hand case value.
5350 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00005351 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman06577382009-11-19 03:14:00 +00005352 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005353 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005354
Eli Friedman06577382009-11-19 03:14:00 +00005355 // Transform the right-hand case value (for the GNU case-range extension).
5356 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00005357 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman06577382009-11-19 03:14:00 +00005358 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005359 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00005360 }
Mike Stump11289f42009-09-09 15:08:12 +00005361
Douglas Gregorebe10102009-08-20 07:17:43 +00005362 // Build the case statement.
5363 // Case statements are always rebuilt so that they will attached to their
5364 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005365 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00005366 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005367 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00005368 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005369 S->getColonLoc());
5370 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005371 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005372
Douglas Gregorebe10102009-08-20 07:17:43 +00005373 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00005374 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005375 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005376 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005377
Douglas Gregorebe10102009-08-20 07:17:43 +00005378 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00005379 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005380}
5381
5382template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005383StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005384TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005385 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00005386 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005387 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005388 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005389
Douglas Gregorebe10102009-08-20 07:17:43 +00005390 // Default statements are always rebuilt
5391 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00005392 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005393}
Mike Stump11289f42009-09-09 15:08:12 +00005394
Douglas Gregorebe10102009-08-20 07:17:43 +00005395template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005396StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005397TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005398 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005399 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005400 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005401
Chris Lattnercab02a62011-02-17 20:34:02 +00005402 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5403 S->getDecl());
5404 if (!LD)
5405 return StmtError();
Richard Smithc202b282012-04-14 00:33:13 +00005406
5407
Douglas Gregorebe10102009-08-20 07:17:43 +00005408 // FIXME: Pass the real colon location in.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00005409 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005410 cast<LabelDecl>(LD), SourceLocation(),
5411 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005412}
Mike Stump11289f42009-09-09 15:08:12 +00005413
Douglas Gregorebe10102009-08-20 07:17:43 +00005414template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005415StmtResult
Richard Smithc202b282012-04-14 00:33:13 +00005416TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
5417 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5418 if (SubStmt.isInvalid())
5419 return StmtError();
5420
5421 // TODO: transform attributes
5422 if (SubStmt.get() == S->getSubStmt() /* && attrs are the same */)
5423 return S;
5424
5425 return getDerived().RebuildAttributedStmt(S->getAttrLoc(),
5426 S->getAttrs(),
5427 SubStmt.get());
5428}
5429
5430template<typename Derived>
5431StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005432TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005433 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005434 ExprResult Cond;
Douglas Gregor633caca2009-11-23 23:44:04 +00005435 VarDecl *ConditionVar = 0;
5436 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005437 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00005438 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005439 getDerived().TransformDefinition(
5440 S->getConditionVariable()->getLocation(),
5441 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00005442 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005443 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005444 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00005445 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005446
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005447 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005448 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005449
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005450 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00005451 if (S->getCond()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005452 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005453 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005454 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005455 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005456
John McCallb268a282010-08-23 23:25:46 +00005457 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005458 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005459 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005460
John McCallb268a282010-08-23 23:25:46 +00005461 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5462 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005463 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005464
Douglas Gregorebe10102009-08-20 07:17:43 +00005465 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00005466 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00005467 if (Then.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005468 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005469
Douglas Gregorebe10102009-08-20 07:17:43 +00005470 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00005471 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00005472 if (Else.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005473 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005474
Douglas Gregorebe10102009-08-20 07:17:43 +00005475 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00005476 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005477 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005478 Then.get() == S->getThen() &&
5479 Else.get() == S->getElse())
John McCallc3007a22010-10-26 07:05:15 +00005480 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005481
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005482 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00005483 Then.get(),
John McCallb268a282010-08-23 23:25:46 +00005484 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005485}
5486
5487template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005488StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005489TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005490 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00005491 ExprResult Cond;
Douglas Gregordcf19622009-11-24 17:07:59 +00005492 VarDecl *ConditionVar = 0;
5493 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005494 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00005495 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005496 getDerived().TransformDefinition(
5497 S->getConditionVariable()->getLocation(),
5498 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00005499 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005500 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005501 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00005502 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005503
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005504 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005505 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005506 }
Mike Stump11289f42009-09-09 15:08:12 +00005507
Douglas Gregorebe10102009-08-20 07:17:43 +00005508 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005509 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00005510 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00005511 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00005512 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005513 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005514
Douglas Gregorebe10102009-08-20 07:17:43 +00005515 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005516 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005517 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005518 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005519
Douglas Gregorebe10102009-08-20 07:17:43 +00005520 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00005521 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5522 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005523}
Mike Stump11289f42009-09-09 15:08:12 +00005524
Douglas Gregorebe10102009-08-20 07:17:43 +00005525template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005526StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005527TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005528 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005529 ExprResult Cond;
Douglas Gregor680f8612009-11-24 21:15:44 +00005530 VarDecl *ConditionVar = 0;
5531 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005532 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00005533 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005534 getDerived().TransformDefinition(
5535 S->getConditionVariable()->getLocation(),
5536 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00005537 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005538 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005539 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00005540 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005541
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005542 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005543 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005544
5545 if (S->getCond()) {
5546 // Convert the condition to a boolean value.
Chad Rosier1dcde962012-08-08 18:46:20 +00005547 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005548 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005549 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005550 return StmtError();
John McCallb268a282010-08-23 23:25:46 +00005551 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00005552 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005553 }
Mike Stump11289f42009-09-09 15:08:12 +00005554
John McCallb268a282010-08-23 23:25:46 +00005555 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5556 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005557 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005558
Douglas Gregorebe10102009-08-20 07:17:43 +00005559 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005560 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005561 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005562 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005563
Douglas Gregorebe10102009-08-20 07:17:43 +00005564 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00005565 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005566 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005567 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00005568 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005569
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005570 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00005571 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005572}
Mike Stump11289f42009-09-09 15:08:12 +00005573
Douglas Gregorebe10102009-08-20 07:17:43 +00005574template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005575StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005576TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005577 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005578 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005579 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005580 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005581
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005582 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005583 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005584 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005585 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005586
Douglas Gregorebe10102009-08-20 07:17:43 +00005587 if (!getDerived().AlwaysRebuild() &&
5588 Cond.get() == S->getCond() &&
5589 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005590 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005591
John McCallb268a282010-08-23 23:25:46 +00005592 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5593 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005594 S->getRParenLoc());
5595}
Mike Stump11289f42009-09-09 15:08:12 +00005596
Douglas Gregorebe10102009-08-20 07:17:43 +00005597template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005598StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005599TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005600 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00005601 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00005602 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005603 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005604
Douglas Gregorebe10102009-08-20 07:17:43 +00005605 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005606 ExprResult Cond;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005607 VarDecl *ConditionVar = 0;
5608 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005609 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005610 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005611 getDerived().TransformDefinition(
5612 S->getConditionVariable()->getLocation(),
5613 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005614 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005615 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005616 } else {
5617 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005618
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005619 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005620 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005621
5622 if (S->getCond()) {
5623 // Convert the condition to a boolean value.
Chad Rosier1dcde962012-08-08 18:46:20 +00005624 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005625 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005626 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005627 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005628
John McCallb268a282010-08-23 23:25:46 +00005629 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005630 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005631 }
Mike Stump11289f42009-09-09 15:08:12 +00005632
Chad Rosier1dcde962012-08-08 18:46:20 +00005633 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
John McCallb268a282010-08-23 23:25:46 +00005634 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005635 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005636
Douglas Gregorebe10102009-08-20 07:17:43 +00005637 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00005638 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005639 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005640 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005641
Richard Smith945f8d32013-01-14 22:39:08 +00005642 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
John McCallb268a282010-08-23 23:25:46 +00005643 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005644 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005645
Douglas Gregorebe10102009-08-20 07:17:43 +00005646 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005647 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005648 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005649 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005650
Douglas Gregorebe10102009-08-20 07:17:43 +00005651 if (!getDerived().AlwaysRebuild() &&
5652 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00005653 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005654 Inc.get() == S->getInc() &&
5655 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005656 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005657
Douglas Gregorebe10102009-08-20 07:17:43 +00005658 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005659 Init.get(), FullCond, ConditionVar,
5660 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005661}
5662
5663template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005664StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005665TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattnercab02a62011-02-17 20:34:02 +00005666 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5667 S->getLabel());
5668 if (!LD)
5669 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005670
Douglas Gregorebe10102009-08-20 07:17:43 +00005671 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00005672 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005673 cast<LabelDecl>(LD));
Douglas Gregorebe10102009-08-20 07:17:43 +00005674}
5675
5676template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005677StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005678TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005679 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00005680 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005681 return StmtError();
Eli Friedman9ccdb1d2012-01-31 22:47:07 +00005682 Target = SemaRef.MaybeCreateExprWithCleanups(Target.take());
Mike Stump11289f42009-09-09 15:08:12 +00005683
Douglas Gregorebe10102009-08-20 07:17:43 +00005684 if (!getDerived().AlwaysRebuild() &&
5685 Target.get() == S->getTarget())
John McCallc3007a22010-10-26 07:05:15 +00005686 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005687
5688 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00005689 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005690}
5691
5692template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005693StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005694TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00005695 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005696}
Mike Stump11289f42009-09-09 15:08:12 +00005697
Douglas Gregorebe10102009-08-20 07:17:43 +00005698template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005699StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005700TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00005701 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005702}
Mike Stump11289f42009-09-09 15:08:12 +00005703
Douglas Gregorebe10102009-08-20 07:17:43 +00005704template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005705StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005706TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005707 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregorebe10102009-08-20 07:17:43 +00005708 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005709 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00005710
Mike Stump11289f42009-09-09 15:08:12 +00005711 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00005712 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00005713 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005714}
Mike Stump11289f42009-09-09 15:08:12 +00005715
Douglas Gregorebe10102009-08-20 07:17:43 +00005716template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005717StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005718TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005719 bool DeclChanged = false;
Chris Lattner01cf8db2011-07-20 06:58:45 +00005720 SmallVector<Decl *, 4> Decls;
Aaron Ballman535bbcc2014-03-14 17:01:24 +00005721 for (auto *D : S->decls()) {
5722 Decl *Transformed = getDerived().TransformDefinition(D->getLocation(), D);
Douglas Gregorebe10102009-08-20 07:17:43 +00005723 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00005724 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005725
Aaron Ballman535bbcc2014-03-14 17:01:24 +00005726 if (Transformed != D)
Douglas Gregorebe10102009-08-20 07:17:43 +00005727 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00005728
Douglas Gregorebe10102009-08-20 07:17:43 +00005729 Decls.push_back(Transformed);
5730 }
Mike Stump11289f42009-09-09 15:08:12 +00005731
Douglas Gregorebe10102009-08-20 07:17:43 +00005732 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCallc3007a22010-10-26 07:05:15 +00005733 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005734
Rafael Espindolaab417692013-07-09 12:05:01 +00005735 return getDerived().RebuildDeclStmt(Decls, S->getStartLoc(), S->getEndLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005736}
Mike Stump11289f42009-09-09 15:08:12 +00005737
Douglas Gregorebe10102009-08-20 07:17:43 +00005738template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005739StmtResult
Chad Rosierde70e0e2012-08-25 00:11:56 +00005740TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005741
Benjamin Kramerf0623432012-08-23 22:51:59 +00005742 SmallVector<Expr*, 8> Constraints;
5743 SmallVector<Expr*, 8> Exprs;
Chris Lattner01cf8db2011-07-20 06:58:45 +00005744 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00005745
John McCalldadc5752010-08-24 06:29:42 +00005746 ExprResult AsmString;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005747 SmallVector<Expr*, 8> Clobbers;
Anders Carlssonaaeef072010-01-24 05:50:09 +00005748
5749 bool ExprsChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00005750
Anders Carlssonaaeef072010-01-24 05:50:09 +00005751 // Go through the outputs.
5752 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005753 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005754
Anders Carlssonaaeef072010-01-24 05:50:09 +00005755 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005756 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005757
Anders Carlssonaaeef072010-01-24 05:50:09 +00005758 // Transform the output expr.
5759 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005760 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005761 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005762 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005763
Anders Carlssonaaeef072010-01-24 05:50:09 +00005764 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00005765
John McCallb268a282010-08-23 23:25:46 +00005766 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005767 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005768
Anders Carlssonaaeef072010-01-24 05:50:09 +00005769 // Go through the inputs.
5770 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005771 Names.push_back(S->getInputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005772
Anders Carlssonaaeef072010-01-24 05:50:09 +00005773 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005774 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005775
Anders Carlssonaaeef072010-01-24 05:50:09 +00005776 // Transform the input expr.
5777 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005778 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005779 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005780 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005781
Anders Carlssonaaeef072010-01-24 05:50:09 +00005782 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00005783
John McCallb268a282010-08-23 23:25:46 +00005784 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005785 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005786
Anders Carlssonaaeef072010-01-24 05:50:09 +00005787 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCallc3007a22010-10-26 07:05:15 +00005788 return SemaRef.Owned(S);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005789
5790 // Go through the clobbers.
5791 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosierd9fb09a2012-08-27 23:28:41 +00005792 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00005793
5794 // No need to transform the asm string literal.
5795 AsmString = SemaRef.Owned(S->getAsmString());
Chad Rosierde70e0e2012-08-25 00:11:56 +00005796 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
5797 S->isVolatile(), S->getNumOutputs(),
5798 S->getNumInputs(), Names.data(),
5799 Constraints, Exprs, AsmString.get(),
5800 Clobbers, S->getRParenLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005801}
5802
Chad Rosier32503022012-06-11 20:47:18 +00005803template<typename Derived>
5804StmtResult
5805TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier99fc3812012-08-07 00:29:06 +00005806 ArrayRef<Token> AsmToks =
5807 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier3ed0bd92012-08-08 19:48:07 +00005808
John McCallf413f5e2013-05-03 00:10:13 +00005809 bool HadError = false, HadChange = false;
5810
5811 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
5812 SmallVector<Expr*, 8> TransformedExprs;
5813 TransformedExprs.reserve(SrcExprs.size());
5814 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
5815 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
5816 if (!Result.isUsable()) {
5817 HadError = true;
5818 } else {
5819 HadChange |= (Result.get() != SrcExprs[i]);
5820 TransformedExprs.push_back(Result.take());
5821 }
5822 }
5823
5824 if (HadError) return StmtError();
5825 if (!HadChange && !getDerived().AlwaysRebuild())
5826 return Owned(S);
5827
Chad Rosierb6f46c12012-08-15 16:53:30 +00005828 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
John McCallf413f5e2013-05-03 00:10:13 +00005829 AsmToks, S->getAsmString(),
5830 S->getNumOutputs(), S->getNumInputs(),
5831 S->getAllConstraints(), S->getClobbers(),
5832 TransformedExprs, S->getEndLoc());
Chad Rosier32503022012-06-11 20:47:18 +00005833}
Douglas Gregorebe10102009-08-20 07:17:43 +00005834
5835template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005836StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005837TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005838 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00005839 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005840 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005841 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005842
Douglas Gregor96c79492010-04-23 22:50:49 +00005843 // Transform the @catch statements (if present).
5844 bool AnyCatchChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005845 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor96c79492010-04-23 22:50:49 +00005846 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00005847 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00005848 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005849 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00005850 if (Catch.get() != S->getCatchStmt(I))
5851 AnyCatchChanged = true;
5852 CatchStmts.push_back(Catch.release());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005853 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005854
Douglas Gregor306de2f2010-04-22 23:59:56 +00005855 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00005856 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00005857 if (S->getFinallyStmt()) {
5858 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5859 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005860 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00005861 }
5862
5863 // If nothing changed, just retain this statement.
5864 if (!getDerived().AlwaysRebuild() &&
5865 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00005866 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00005867 Finally.get() == S->getFinallyStmt())
John McCallc3007a22010-10-26 07:05:15 +00005868 return SemaRef.Owned(S);
Chad Rosier1dcde962012-08-08 18:46:20 +00005869
Douglas Gregor306de2f2010-04-22 23:59:56 +00005870 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00005871 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00005872 CatchStmts, Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005873}
Mike Stump11289f42009-09-09 15:08:12 +00005874
Douglas Gregorebe10102009-08-20 07:17:43 +00005875template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005876StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005877TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005878 // Transform the @catch parameter, if there is one.
5879 VarDecl *Var = 0;
5880 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5881 TypeSourceInfo *TSInfo = 0;
5882 if (FromVar->getTypeSourceInfo()) {
5883 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5884 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005885 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005886 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005887
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005888 QualType T;
5889 if (TSInfo)
5890 T = TSInfo->getType();
5891 else {
5892 T = getDerived().TransformType(FromVar->getType());
5893 if (T.isNull())
Chad Rosier1dcde962012-08-08 18:46:20 +00005894 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005895 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005896
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005897 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5898 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00005899 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005900 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005901
John McCalldadc5752010-08-24 06:29:42 +00005902 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005903 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005904 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005905
5906 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005907 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005908 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005909}
Mike Stump11289f42009-09-09 15:08:12 +00005910
Douglas Gregorebe10102009-08-20 07:17:43 +00005911template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005912StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005913TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005914 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005915 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005916 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005917 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005918
Douglas Gregor306de2f2010-04-22 23:59:56 +00005919 // If nothing changed, just retain this statement.
5920 if (!getDerived().AlwaysRebuild() &&
5921 Body.get() == S->getFinallyBody())
John McCallc3007a22010-10-26 07:05:15 +00005922 return SemaRef.Owned(S);
Douglas Gregor306de2f2010-04-22 23:59:56 +00005923
5924 // Build a new statement.
5925 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00005926 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005927}
Mike Stump11289f42009-09-09 15:08:12 +00005928
Douglas Gregorebe10102009-08-20 07:17:43 +00005929template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005930StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005931TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005932 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00005933 if (S->getThrowExpr()) {
5934 Operand = getDerived().TransformExpr(S->getThrowExpr());
5935 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005936 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00005937 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005938
Douglas Gregor2900c162010-04-22 21:44:01 +00005939 if (!getDerived().AlwaysRebuild() &&
5940 Operand.get() == S->getThrowExpr())
John McCallc3007a22010-10-26 07:05:15 +00005941 return getSema().Owned(S);
Chad Rosier1dcde962012-08-08 18:46:20 +00005942
John McCallb268a282010-08-23 23:25:46 +00005943 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005944}
Mike Stump11289f42009-09-09 15:08:12 +00005945
Douglas Gregorebe10102009-08-20 07:17:43 +00005946template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005947StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005948TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00005949 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00005950 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00005951 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00005952 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005953 return StmtError();
John McCalld9bb7432011-07-27 21:50:02 +00005954 Object =
5955 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
5956 Object.get());
5957 if (Object.isInvalid())
5958 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005959
Douglas Gregor6148de72010-04-22 22:01:21 +00005960 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005961 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00005962 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005963 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005964
Douglas Gregor6148de72010-04-22 22:01:21 +00005965 // If nothing change, just retain the current statement.
5966 if (!getDerived().AlwaysRebuild() &&
5967 Object.get() == S->getSynchExpr() &&
5968 Body.get() == S->getSynchBody())
John McCallc3007a22010-10-26 07:05:15 +00005969 return SemaRef.Owned(S);
Douglas Gregor6148de72010-04-22 22:01:21 +00005970
5971 // Build a new statement.
5972 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00005973 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005974}
5975
5976template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005977StmtResult
John McCall31168b02011-06-15 23:02:42 +00005978TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
5979 ObjCAutoreleasePoolStmt *S) {
5980 // Transform the body.
5981 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
5982 if (Body.isInvalid())
5983 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005984
John McCall31168b02011-06-15 23:02:42 +00005985 // If nothing changed, just retain this statement.
5986 if (!getDerived().AlwaysRebuild() &&
5987 Body.get() == S->getSubStmt())
5988 return SemaRef.Owned(S);
5989
5990 // Build a new statement.
5991 return getDerived().RebuildObjCAutoreleasePoolStmt(
5992 S->getAtLoc(), Body.get());
5993}
5994
5995template<typename Derived>
5996StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005997TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00005998 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00005999 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00006000 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006001 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006002 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006003
Douglas Gregorf68a5082010-04-22 23:10:45 +00006004 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00006005 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006006 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006007 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006008
Douglas Gregorf68a5082010-04-22 23:10:45 +00006009 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006010 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006011 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006012 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006013
Douglas Gregorf68a5082010-04-22 23:10:45 +00006014 // If nothing changed, just retain this statement.
6015 if (!getDerived().AlwaysRebuild() &&
6016 Element.get() == S->getElement() &&
6017 Collection.get() == S->getCollection() &&
6018 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00006019 return SemaRef.Owned(S);
Chad Rosier1dcde962012-08-08 18:46:20 +00006020
Douglas Gregorf68a5082010-04-22 23:10:45 +00006021 // Build a new statement.
6022 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00006023 Element.get(),
6024 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00006025 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006026 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006027}
6028
David Majnemer5f7efef2013-10-15 09:50:08 +00006029template <typename Derived>
6030StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006031 // Transform the exception declaration, if any.
6032 VarDecl *Var = 0;
David Majnemer5f7efef2013-10-15 09:50:08 +00006033 if (VarDecl *ExceptionDecl = S->getExceptionDecl()) {
6034 TypeSourceInfo *T =
6035 getDerived().TransformType(ExceptionDecl->getTypeSourceInfo());
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00006036 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006037 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006038
David Majnemer5f7efef2013-10-15 09:50:08 +00006039 Var = getDerived().RebuildExceptionDecl(
6040 ExceptionDecl, T, ExceptionDecl->getInnerLocStart(),
6041 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
Douglas Gregorb412e172010-07-25 18:17:45 +00006042 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00006043 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00006044 }
Mike Stump11289f42009-09-09 15:08:12 +00006045
Douglas Gregorebe10102009-08-20 07:17:43 +00006046 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00006047 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00006048 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006049 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006050
David Majnemer5f7efef2013-10-15 09:50:08 +00006051 if (!getDerived().AlwaysRebuild() && !Var &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006052 Handler.get() == S->getHandlerBlock())
John McCallc3007a22010-10-26 07:05:15 +00006053 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00006054
David Majnemer5f7efef2013-10-15 09:50:08 +00006055 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006056}
Mike Stump11289f42009-09-09 15:08:12 +00006057
David Majnemer5f7efef2013-10-15 09:50:08 +00006058template <typename Derived>
6059StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006060 // Transform the try block itself.
David Majnemer5f7efef2013-10-15 09:50:08 +00006061 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
Douglas Gregorebe10102009-08-20 07:17:43 +00006062 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006063 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006064
Douglas Gregorebe10102009-08-20 07:17:43 +00006065 // Transform the handlers.
6066 bool HandlerChanged = false;
David Majnemer5f7efef2013-10-15 09:50:08 +00006067 SmallVector<Stmt *, 8> Handlers;
Douglas Gregorebe10102009-08-20 07:17:43 +00006068 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
David Majnemer5f7efef2013-10-15 09:50:08 +00006069 StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I));
Douglas Gregorebe10102009-08-20 07:17:43 +00006070 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006071 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006072
Douglas Gregorebe10102009-08-20 07:17:43 +00006073 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
6074 Handlers.push_back(Handler.takeAs<Stmt>());
6075 }
Mike Stump11289f42009-09-09 15:08:12 +00006076
David Majnemer5f7efef2013-10-15 09:50:08 +00006077 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006078 !HandlerChanged)
John McCallc3007a22010-10-26 07:05:15 +00006079 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00006080
John McCallb268a282010-08-23 23:25:46 +00006081 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006082 Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00006083}
Mike Stump11289f42009-09-09 15:08:12 +00006084
Richard Smith02e85f32011-04-14 22:09:26 +00006085template<typename Derived>
6086StmtResult
6087TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
6088 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
6089 if (Range.isInvalid())
6090 return StmtError();
6091
6092 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
6093 if (BeginEnd.isInvalid())
6094 return StmtError();
6095
6096 ExprResult Cond = getDerived().TransformExpr(S->getCond());
6097 if (Cond.isInvalid())
6098 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006099 if (Cond.get())
6100 Cond = SemaRef.CheckBooleanCondition(Cond.take(), S->getColonLoc());
6101 if (Cond.isInvalid())
6102 return StmtError();
6103 if (Cond.get())
6104 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.take());
Richard Smith02e85f32011-04-14 22:09:26 +00006105
6106 ExprResult Inc = getDerived().TransformExpr(S->getInc());
6107 if (Inc.isInvalid())
6108 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006109 if (Inc.get())
6110 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.take());
Richard Smith02e85f32011-04-14 22:09:26 +00006111
6112 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
6113 if (LoopVar.isInvalid())
6114 return StmtError();
6115
6116 StmtResult NewStmt = S;
6117 if (getDerived().AlwaysRebuild() ||
6118 Range.get() != S->getRangeStmt() ||
6119 BeginEnd.get() != S->getBeginEndStmt() ||
6120 Cond.get() != S->getCond() ||
6121 Inc.get() != S->getInc() ||
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006122 LoopVar.get() != S->getLoopVarStmt()) {
Richard Smith02e85f32011-04-14 22:09:26 +00006123 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6124 S->getColonLoc(), Range.get(),
6125 BeginEnd.get(), Cond.get(),
6126 Inc.get(), LoopVar.get(),
6127 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006128 if (NewStmt.isInvalid())
6129 return StmtError();
6130 }
Richard Smith02e85f32011-04-14 22:09:26 +00006131
6132 StmtResult Body = getDerived().TransformStmt(S->getBody());
6133 if (Body.isInvalid())
6134 return StmtError();
6135
6136 // Body has changed but we didn't rebuild the for-range statement. Rebuild
6137 // it now so we have a new statement to attach the body to.
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006138 if (Body.get() != S->getBody() && NewStmt.get() == S) {
Richard Smith02e85f32011-04-14 22:09:26 +00006139 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6140 S->getColonLoc(), Range.get(),
6141 BeginEnd.get(), Cond.get(),
6142 Inc.get(), LoopVar.get(),
6143 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006144 if (NewStmt.isInvalid())
6145 return StmtError();
6146 }
Richard Smith02e85f32011-04-14 22:09:26 +00006147
6148 if (NewStmt.get() == S)
6149 return SemaRef.Owned(S);
6150
6151 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
6152}
6153
John Wiegley1c0675e2011-04-28 01:08:34 +00006154template<typename Derived>
6155StmtResult
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006156TreeTransform<Derived>::TransformMSDependentExistsStmt(
6157 MSDependentExistsStmt *S) {
6158 // Transform the nested-name-specifier, if any.
6159 NestedNameSpecifierLoc QualifierLoc;
6160 if (S->getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006161 QualifierLoc
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006162 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
6163 if (!QualifierLoc)
6164 return StmtError();
6165 }
6166
6167 // Transform the declaration name.
6168 DeclarationNameInfo NameInfo = S->getNameInfo();
6169 if (NameInfo.getName()) {
6170 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6171 if (!NameInfo.getName())
6172 return StmtError();
6173 }
6174
6175 // Check whether anything changed.
6176 if (!getDerived().AlwaysRebuild() &&
6177 QualifierLoc == S->getQualifierLoc() &&
6178 NameInfo.getName() == S->getNameInfo().getName())
6179 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006180
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006181 // Determine whether this name exists, if we can.
6182 CXXScopeSpec SS;
6183 SS.Adopt(QualifierLoc);
6184 bool Dependent = false;
6185 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/0, SS, NameInfo)) {
6186 case Sema::IER_Exists:
6187 if (S->isIfExists())
6188 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006189
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006190 return new (getSema().Context) NullStmt(S->getKeywordLoc());
6191
6192 case Sema::IER_DoesNotExist:
6193 if (S->isIfNotExists())
6194 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006195
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006196 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00006197
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006198 case Sema::IER_Dependent:
6199 Dependent = true;
6200 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006201
Douglas Gregor4a2a8f72011-10-25 03:44:56 +00006202 case Sema::IER_Error:
6203 return StmtError();
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006204 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006205
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006206 // We need to continue with the instantiation, so do so now.
6207 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
6208 if (SubStmt.isInvalid())
6209 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006210
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006211 // If we have resolved the name, just transform to the substatement.
6212 if (!Dependent)
6213 return SubStmt;
Chad Rosier1dcde962012-08-08 18:46:20 +00006214
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006215 // The name is still dependent, so build a dependent expression again.
6216 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
6217 S->isIfExists(),
6218 QualifierLoc,
6219 NameInfo,
6220 SubStmt.get());
6221}
6222
6223template<typename Derived>
John McCall5e77d762013-04-16 07:28:30 +00006224ExprResult
6225TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
6226 NestedNameSpecifierLoc QualifierLoc;
6227 if (E->getQualifierLoc()) {
6228 QualifierLoc
6229 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6230 if (!QualifierLoc)
6231 return ExprError();
6232 }
6233
6234 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
6235 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
6236 if (!PD)
6237 return ExprError();
6238
6239 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
6240 if (Base.isInvalid())
6241 return ExprError();
6242
6243 return new (SemaRef.getASTContext())
6244 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
6245 SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
6246 QualifierLoc, E->getMemberLoc());
6247}
6248
David Majnemerfad8f482013-10-15 09:33:02 +00006249template <typename Derived>
6250StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00006251 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006252 if (TryBlock.isInvalid())
6253 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006254
6255 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
David Majnemer7e755502013-10-15 09:30:14 +00006256 if (Handler.isInvalid())
6257 return StmtError();
6258
David Majnemerfad8f482013-10-15 09:33:02 +00006259 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
6260 Handler.get() == S->getHandler())
John Wiegley1c0675e2011-04-28 01:08:34 +00006261 return SemaRef.Owned(S);
6262
David Majnemerfad8f482013-10-15 09:33:02 +00006263 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(),
6264 TryBlock.take(), Handler.take());
John Wiegley1c0675e2011-04-28 01:08:34 +00006265}
6266
David Majnemerfad8f482013-10-15 09:33:02 +00006267template <typename Derived>
6268StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00006269 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006270 if (Block.isInvalid())
6271 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006272
David Majnemerfad8f482013-10-15 09:33:02 +00006273 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.take());
John Wiegley1c0675e2011-04-28 01:08:34 +00006274}
6275
David Majnemerfad8f482013-10-15 09:33:02 +00006276template <typename Derived>
6277StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
John Wiegley1c0675e2011-04-28 01:08:34 +00006278 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
David Majnemerfad8f482013-10-15 09:33:02 +00006279 if (FilterExpr.isInvalid())
6280 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006281
David Majnemer7e755502013-10-15 09:30:14 +00006282 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006283 if (Block.isInvalid())
6284 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006285
David Majnemerfad8f482013-10-15 09:33:02 +00006286 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.take(),
John Wiegley1c0675e2011-04-28 01:08:34 +00006287 Block.take());
6288}
6289
David Majnemerfad8f482013-10-15 09:33:02 +00006290template <typename Derived>
6291StmtResult TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
6292 if (isa<SEHFinallyStmt>(Handler))
John Wiegley1c0675e2011-04-28 01:08:34 +00006293 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
6294 else
6295 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
6296}
6297
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006298template<typename Derived>
6299StmtResult
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006300TreeTransform<Derived>::TransformOMPExecutableDirective(
6301 OMPExecutableDirective *D) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00006302
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006303 // Transform the clauses
Alexey Bataev758e55e2013-09-06 18:03:48 +00006304 llvm::SmallVector<OMPClause *, 16> TClauses;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006305 ArrayRef<OMPClause *> Clauses = D->clauses();
6306 TClauses.reserve(Clauses.size());
6307 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
6308 I != E; ++I) {
6309 if (*I) {
6310 OMPClause *Clause = getDerived().TransformOMPClause(*I);
Alexey Bataev758e55e2013-09-06 18:03:48 +00006311 if (!Clause) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006312 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00006313 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006314 TClauses.push_back(Clause);
6315 }
6316 else {
6317 TClauses.push_back(0);
6318 }
6319 }
Alexey Bataev758e55e2013-09-06 18:03:48 +00006320 if (!D->getAssociatedStmt()) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006321 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00006322 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006323 StmtResult AssociatedStmt =
6324 getDerived().TransformStmt(D->getAssociatedStmt());
Alexey Bataev758e55e2013-09-06 18:03:48 +00006325 if (AssociatedStmt.isInvalid()) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006326 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00006327 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006328
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006329 return getDerived().RebuildOMPExecutableDirective(D->getDirectiveKind(),
6330 TClauses,
6331 AssociatedStmt.take(),
6332 D->getLocStart(),
6333 D->getLocEnd());
6334}
6335
6336template<typename Derived>
6337StmtResult
6338TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
6339 DeclarationNameInfo DirName;
Alexey Bataev3d76e772014-03-07 04:01:56 +00006340 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, 0);
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006341 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6342 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6343 return Res;
6344}
6345
6346template<typename Derived>
6347StmtResult
6348TreeTransform<Derived>::TransformOMPSimdDirective(OMPSimdDirective *D) {
6349 DeclarationNameInfo DirName;
Alexey Bataev96d15102014-03-07 04:16:48 +00006350 getDerived().getSema().StartOpenMPDSABlock(OMPD_simd, DirName, 0);
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006351 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6352 getDerived().getSema().EndOpenMPDSABlock(Res.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00006353 return Res;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006354}
6355
6356template<typename Derived>
6357OMPClause *
Alexey Bataevaadd52e2014-02-13 05:29:23 +00006358TreeTransform<Derived>::TransformOMPIfClause(OMPIfClause *C) {
Alexey Bataevaf7849e2014-03-05 06:45:14 +00006359 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
6360 if (Cond.isInvalid())
6361 return 0;
6362 return getDerived().RebuildOMPIfClause(Cond.take(), C->getLocStart(),
Alexey Bataevaadd52e2014-02-13 05:29:23 +00006363 C->getLParenLoc(), C->getLocEnd());
6364}
6365
6366template<typename Derived>
6367OMPClause *
Alexey Bataev568a8332014-03-06 06:15:19 +00006368TreeTransform<Derived>::TransformOMPNumThreadsClause(OMPNumThreadsClause *C) {
6369 ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads());
6370 if (NumThreads.isInvalid())
6371 return 0;
6372 return getDerived().RebuildOMPNumThreadsClause(NumThreads.take(),
6373 C->getLocStart(),
6374 C->getLParenLoc(),
6375 C->getLocEnd());
6376}
6377
Alexey Bataev62c87d22014-03-21 04:51:18 +00006378template <typename Derived>
6379OMPClause *
6380TreeTransform<Derived>::TransformOMPSafelenClause(OMPSafelenClause *C) {
6381 ExprResult E = getDerived().TransformExpr(C->getSafelen());
6382 if (E.isInvalid())
6383 return 0;
6384 return getDerived().RebuildOMPSafelenClause(
6385 E.take(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
6386}
6387
Alexey Bataev568a8332014-03-06 06:15:19 +00006388template<typename Derived>
6389OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006390TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
6391 return getDerived().RebuildOMPDefaultClause(C->getDefaultKind(),
6392 C->getDefaultKindKwLoc(),
6393 C->getLocStart(),
6394 C->getLParenLoc(),
6395 C->getLocEnd());
6396}
6397
6398template<typename Derived>
6399OMPClause *
6400TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00006401 llvm::SmallVector<Expr *, 16> Vars;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006402 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00006403 for (auto *VE : C->varlists()) {
6404 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006405 if (EVar.isInvalid())
6406 return 0;
6407 Vars.push_back(EVar.take());
6408 }
6409 return getDerived().RebuildOMPPrivateClause(Vars,
6410 C->getLocStart(),
6411 C->getLParenLoc(),
6412 C->getLocEnd());
6413}
6414
Alexey Bataev758e55e2013-09-06 18:03:48 +00006415template<typename Derived>
6416OMPClause *
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006417TreeTransform<Derived>::TransformOMPFirstprivateClause(
6418 OMPFirstprivateClause *C) {
6419 llvm::SmallVector<Expr *, 16> Vars;
6420 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00006421 for (auto *VE : C->varlists()) {
6422 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006423 if (EVar.isInvalid())
6424 return 0;
6425 Vars.push_back(EVar.take());
6426 }
6427 return getDerived().RebuildOMPFirstprivateClause(Vars,
6428 C->getLocStart(),
6429 C->getLParenLoc(),
6430 C->getLocEnd());
6431}
6432
6433template<typename Derived>
6434OMPClause *
Alexey Bataev758e55e2013-09-06 18:03:48 +00006435TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
6436 llvm::SmallVector<Expr *, 16> Vars;
6437 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00006438 for (auto *VE : C->varlists()) {
6439 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev758e55e2013-09-06 18:03:48 +00006440 if (EVar.isInvalid())
6441 return 0;
6442 Vars.push_back(EVar.take());
6443 }
6444 return getDerived().RebuildOMPSharedClause(Vars,
6445 C->getLocStart(),
6446 C->getLParenLoc(),
6447 C->getLocEnd());
6448}
6449
Alexey Bataevd48bcd82014-03-31 03:36:38 +00006450template<typename Derived>
6451OMPClause *
Alexander Musman8dba6642014-04-22 13:09:42 +00006452TreeTransform<Derived>::TransformOMPLinearClause(OMPLinearClause *C) {
6453 llvm::SmallVector<Expr *, 16> Vars;
6454 Vars.reserve(C->varlist_size());
6455 for (auto *VE : C->varlists()) {
6456 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
6457 if (EVar.isInvalid())
6458 return 0;
6459 Vars.push_back(EVar.take());
6460 }
6461 ExprResult Step = getDerived().TransformExpr(C->getStep());
6462 if (Step.isInvalid())
6463 return 0;
6464 return getDerived().RebuildOMPLinearClause(
6465 Vars, Step.take(), C->getLocStart(), C->getLParenLoc(), C->getColonLoc(),
6466 C->getLocEnd());
6467}
6468
6469template<typename Derived>
6470OMPClause *
Alexey Bataevd48bcd82014-03-31 03:36:38 +00006471TreeTransform<Derived>::TransformOMPCopyinClause(OMPCopyinClause *C) {
6472 llvm::SmallVector<Expr *, 16> Vars;
6473 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00006474 for (auto *VE : C->varlists()) {
6475 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd48bcd82014-03-31 03:36:38 +00006476 if (EVar.isInvalid())
6477 return 0;
6478 Vars.push_back(EVar.take());
6479 }
6480 return getDerived().RebuildOMPCopyinClause(Vars,
6481 C->getLocStart(),
6482 C->getLParenLoc(),
6483 C->getLocEnd());
6484}
6485
Douglas Gregorebe10102009-08-20 07:17:43 +00006486//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00006487// Expression transformation
6488//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00006489template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006490ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006491TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006492 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006493}
Mike Stump11289f42009-09-09 15:08:12 +00006494
6495template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006496ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006497TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregorea972d32011-02-28 21:54:11 +00006498 NestedNameSpecifierLoc QualifierLoc;
6499 if (E->getQualifierLoc()) {
6500 QualifierLoc
6501 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6502 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00006503 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00006504 }
John McCallce546572009-12-08 09:08:17 +00006505
6506 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006507 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6508 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006509 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00006510 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006511
John McCall815039a2010-08-17 21:27:17 +00006512 DeclarationNameInfo NameInfo = E->getNameInfo();
6513 if (NameInfo.getName()) {
6514 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6515 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00006516 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00006517 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006518
6519 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00006520 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00006521 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006522 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00006523 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00006524
6525 // Mark it referenced in the new context regardless.
6526 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00006527 SemaRef.MarkDeclRefReferenced(E);
John McCallce546572009-12-08 09:08:17 +00006528
John McCallc3007a22010-10-26 07:05:15 +00006529 return SemaRef.Owned(E);
Douglas Gregor4bd90e52009-10-23 18:54:35 +00006530 }
John McCallce546572009-12-08 09:08:17 +00006531
6532 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCallb3774b52010-08-19 23:49:38 +00006533 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00006534 TemplateArgs = &TransArgs;
6535 TransArgs.setLAngleLoc(E->getLAngleLoc());
6536 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006537 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6538 E->getNumTemplateArgs(),
6539 TransArgs))
6540 return ExprError();
John McCallce546572009-12-08 09:08:17 +00006541 }
6542
Chad Rosier1dcde962012-08-08 18:46:20 +00006543 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregorea972d32011-02-28 21:54:11 +00006544 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00006545}
Mike Stump11289f42009-09-09 15:08:12 +00006546
Douglas Gregora16548e2009-08-11 05:31:07 +00006547template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006548ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006549TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00006550 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006551}
Mike Stump11289f42009-09-09 15:08:12 +00006552
Douglas Gregora16548e2009-08-11 05:31:07 +00006553template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006554ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006555TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00006556 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006557}
Mike Stump11289f42009-09-09 15:08:12 +00006558
Douglas Gregora16548e2009-08-11 05:31:07 +00006559template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006560ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006561TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00006562 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006563}
Mike Stump11289f42009-09-09 15:08:12 +00006564
Douglas Gregora16548e2009-08-11 05:31:07 +00006565template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006566ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006567TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00006568 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006569}
Mike Stump11289f42009-09-09 15:08:12 +00006570
Douglas Gregora16548e2009-08-11 05:31:07 +00006571template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006572ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006573TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00006574 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006575}
6576
6577template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006578ExprResult
Richard Smithc67fdd42012-03-07 08:35:16 +00006579TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
Argyrios Kyrtzidis25049092013-04-09 01:17:02 +00006580 if (FunctionDecl *FD = E->getDirectCallee())
6581 SemaRef.MarkFunctionReferenced(E->getLocStart(), FD);
Richard Smithc67fdd42012-03-07 08:35:16 +00006582 return SemaRef.MaybeBindToTemporary(E);
6583}
6584
6585template<typename Derived>
6586ExprResult
Peter Collingbourne91147592011-04-15 00:35:48 +00006587TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
6588 ExprResult ControllingExpr =
6589 getDerived().TransformExpr(E->getControllingExpr());
6590 if (ControllingExpr.isInvalid())
6591 return ExprError();
6592
Chris Lattner01cf8db2011-07-20 06:58:45 +00006593 SmallVector<Expr *, 4> AssocExprs;
6594 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbourne91147592011-04-15 00:35:48 +00006595 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
6596 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
6597 if (TS) {
6598 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
6599 if (!AssocType)
6600 return ExprError();
6601 AssocTypes.push_back(AssocType);
6602 } else {
6603 AssocTypes.push_back(0);
6604 }
6605
6606 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
6607 if (AssocExpr.isInvalid())
6608 return ExprError();
6609 AssocExprs.push_back(AssocExpr.release());
6610 }
6611
6612 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
6613 E->getDefaultLoc(),
6614 E->getRParenLoc(),
6615 ControllingExpr.release(),
Dmitri Gribenko82360372013-05-10 13:06:58 +00006616 AssocTypes,
6617 AssocExprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00006618}
6619
6620template<typename Derived>
6621ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006622TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006623 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006624 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006625 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006626
Douglas Gregora16548e2009-08-11 05:31:07 +00006627 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006628 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006629
John McCallb268a282010-08-23 23:25:46 +00006630 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006631 E->getRParen());
6632}
6633
Richard Smithdb2630f2012-10-21 03:28:35 +00006634/// \brief The operand of a unary address-of operator has special rules: it's
6635/// allowed to refer to a non-static member of a class even if there's no 'this'
6636/// object available.
6637template<typename Derived>
6638ExprResult
6639TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
6640 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
6641 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true);
6642 else
6643 return getDerived().TransformExpr(E);
6644}
6645
Mike Stump11289f42009-09-09 15:08:12 +00006646template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006647ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006648TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smitheebe125f2013-05-21 23:29:46 +00006649 ExprResult SubExpr;
6650 if (E->getOpcode() == UO_AddrOf)
6651 SubExpr = TransformAddressOfOperand(E->getSubExpr());
6652 else
6653 SubExpr = TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006654 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006655 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006656
Douglas Gregora16548e2009-08-11 05:31:07 +00006657 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006658 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006659
Douglas Gregora16548e2009-08-11 05:31:07 +00006660 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
6661 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00006662 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006663}
Mike Stump11289f42009-09-09 15:08:12 +00006664
Douglas Gregora16548e2009-08-11 05:31:07 +00006665template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006666ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00006667TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
6668 // Transform the type.
6669 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
6670 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00006671 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006672
Douglas Gregor882211c2010-04-28 22:16:22 +00006673 // Transform all of the components into components similar to what the
6674 // parser uses.
Chad Rosier1dcde962012-08-08 18:46:20 +00006675 // FIXME: It would be slightly more efficient in the non-dependent case to
6676 // just map FieldDecls, rather than requiring the rebuilder to look for
6677 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00006678 // template code that we don't care.
6679 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00006680 typedef Sema::OffsetOfComponent Component;
Douglas Gregor882211c2010-04-28 22:16:22 +00006681 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner01cf8db2011-07-20 06:58:45 +00006682 SmallVector<Component, 4> Components;
Douglas Gregor882211c2010-04-28 22:16:22 +00006683 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
6684 const Node &ON = E->getComponent(I);
6685 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00006686 Comp.isBrackets = true;
Abramo Bagnara6b6f0512011-03-12 09:45:03 +00006687 Comp.LocStart = ON.getSourceRange().getBegin();
6688 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor882211c2010-04-28 22:16:22 +00006689 switch (ON.getKind()) {
6690 case Node::Array: {
6691 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00006692 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00006693 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006694 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006695
Douglas Gregor882211c2010-04-28 22:16:22 +00006696 ExprChanged = ExprChanged || Index.get() != FromIndex;
6697 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00006698 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00006699 break;
6700 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006701
Douglas Gregor882211c2010-04-28 22:16:22 +00006702 case Node::Field:
6703 case Node::Identifier:
6704 Comp.isBrackets = false;
6705 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00006706 if (!Comp.U.IdentInfo)
6707 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00006708
Douglas Gregor882211c2010-04-28 22:16:22 +00006709 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006710
Douglas Gregord1702062010-04-29 00:18:15 +00006711 case Node::Base:
6712 // Will be recomputed during the rebuild.
6713 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00006714 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006715
Douglas Gregor882211c2010-04-28 22:16:22 +00006716 Components.push_back(Comp);
6717 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006718
Douglas Gregor882211c2010-04-28 22:16:22 +00006719 // If nothing changed, retain the existing expression.
6720 if (!getDerived().AlwaysRebuild() &&
6721 Type == E->getTypeSourceInfo() &&
6722 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00006723 return SemaRef.Owned(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00006724
Douglas Gregor882211c2010-04-28 22:16:22 +00006725 // Build a new offsetof expression.
6726 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
6727 Components.data(), Components.size(),
6728 E->getRParenLoc());
6729}
6730
6731template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006732ExprResult
John McCall8d69a212010-11-15 23:31:06 +00006733TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
6734 assert(getDerived().AlreadyTransformed(E->getType()) &&
6735 "opaque value expression requires transformation");
6736 return SemaRef.Owned(E);
6737}
6738
6739template<typename Derived>
6740ExprResult
John McCallfe96e0b2011-11-06 09:01:30 +00006741TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCalle9290822011-11-30 04:42:31 +00006742 // Rebuild the syntactic form. The original syntactic form has
6743 // opaque-value expressions in it, so strip those away and rebuild
6744 // the result. This is a really awful way of doing this, but the
6745 // better solution (rebuilding the semantic expressions and
6746 // rebinding OVEs as necessary) doesn't work; we'd need
6747 // TreeTransform to not strip away implicit conversions.
6748 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
6749 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCallfe96e0b2011-11-06 09:01:30 +00006750 if (result.isInvalid()) return ExprError();
6751
6752 // If that gives us a pseudo-object result back, the pseudo-object
6753 // expression must have been an lvalue-to-rvalue conversion which we
6754 // should reapply.
6755 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
6756 result = SemaRef.checkPseudoObjectRValue(result.take());
6757
6758 return result;
6759}
6760
6761template<typename Derived>
6762ExprResult
Peter Collingbournee190dee2011-03-11 19:24:49 +00006763TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
6764 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006765 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00006766 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00006767
John McCallbcd03502009-12-07 02:54:59 +00006768 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00006769 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00006770 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006771
John McCall4c98fd82009-11-04 07:28:41 +00006772 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCallc3007a22010-10-26 07:05:15 +00006773 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006774
Peter Collingbournee190dee2011-03-11 19:24:49 +00006775 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
6776 E->getKind(),
6777 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00006778 }
Mike Stump11289f42009-09-09 15:08:12 +00006779
Eli Friedmane4f22df2012-02-29 04:03:55 +00006780 // C++0x [expr.sizeof]p1:
6781 // The operand is either an expression, which is an unevaluated operand
6782 // [...]
Eli Friedman15681d62012-09-26 04:34:21 +00006783 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
6784 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00006785
Eli Friedmane4f22df2012-02-29 04:03:55 +00006786 ExprResult SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
6787 if (SubExpr.isInvalid())
6788 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006789
Eli Friedmane4f22df2012-02-29 04:03:55 +00006790 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
6791 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006792
Peter Collingbournee190dee2011-03-11 19:24:49 +00006793 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
6794 E->getOperatorLoc(),
6795 E->getKind(),
6796 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00006797}
Mike Stump11289f42009-09-09 15:08:12 +00006798
Douglas Gregora16548e2009-08-11 05:31:07 +00006799template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006800ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006801TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006802 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006803 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006804 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006805
John McCalldadc5752010-08-24 06:29:42 +00006806 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006807 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006808 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006809
6810
Douglas Gregora16548e2009-08-11 05:31:07 +00006811 if (!getDerived().AlwaysRebuild() &&
6812 LHS.get() == E->getLHS() &&
6813 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00006814 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006815
John McCallb268a282010-08-23 23:25:46 +00006816 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006817 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00006818 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006819 E->getRBracketLoc());
6820}
Mike Stump11289f42009-09-09 15:08:12 +00006821
6822template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006823ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006824TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006825 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00006826 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00006827 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006828 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006829
6830 // Transform arguments.
6831 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006832 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00006833 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00006834 &ArgChanged))
6835 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006836
Douglas Gregora16548e2009-08-11 05:31:07 +00006837 if (!getDerived().AlwaysRebuild() &&
6838 Callee.get() == E->getCallee() &&
6839 !ArgChanged)
Dmitri Gribenko76bb5cabfa2012-09-10 21:20:09 +00006840 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00006841
Douglas Gregora16548e2009-08-11 05:31:07 +00006842 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00006843 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00006844 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00006845 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006846 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00006847 E->getRParenLoc());
6848}
Mike Stump11289f42009-09-09 15:08:12 +00006849
6850template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006851ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006852TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006853 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00006854 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006855 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006856
Douglas Gregorea972d32011-02-28 21:54:11 +00006857 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorf405d7e2009-08-31 23:41:50 +00006858 if (E->hasQualifier()) {
Douglas Gregorea972d32011-02-28 21:54:11 +00006859 QualifierLoc
6860 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00006861
Douglas Gregorea972d32011-02-28 21:54:11 +00006862 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00006863 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00006864 }
Abramo Bagnara7945c982012-01-27 09:46:47 +00006865 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00006866
Eli Friedman2cfcef62009-12-04 06:40:45 +00006867 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006868 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
6869 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006870 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00006871 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006872
John McCall16df1e52010-03-30 21:47:33 +00006873 NamedDecl *FoundDecl = E->getFoundDecl();
6874 if (FoundDecl == E->getMemberDecl()) {
6875 FoundDecl = Member;
6876 } else {
6877 FoundDecl = cast_or_null<NamedDecl>(
6878 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
6879 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00006880 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00006881 }
6882
Douglas Gregora16548e2009-08-11 05:31:07 +00006883 if (!getDerived().AlwaysRebuild() &&
6884 Base.get() == E->getBase() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00006885 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00006886 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00006887 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00006888 !E->hasExplicitTemplateArgs()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006889
Anders Carlsson9c45ad72009-12-22 05:24:09 +00006890 // Mark it referenced in the new context regardless.
6891 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00006892 SemaRef.MarkMemberReferenced(E);
6893
John McCallc3007a22010-10-26 07:05:15 +00006894 return SemaRef.Owned(E);
Anders Carlsson9c45ad72009-12-22 05:24:09 +00006895 }
Douglas Gregora16548e2009-08-11 05:31:07 +00006896
John McCall6b51f282009-11-23 01:53:49 +00006897 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00006898 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00006899 TransArgs.setLAngleLoc(E->getLAngleLoc());
6900 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006901 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6902 E->getNumTemplateArgs(),
6903 TransArgs))
6904 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00006905 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006906
Douglas Gregora16548e2009-08-11 05:31:07 +00006907 // FIXME: Bogus source location for the operator
6908 SourceLocation FakeOperatorLoc
6909 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
6910
John McCall38836f02010-01-15 08:34:02 +00006911 // FIXME: to do this check properly, we will need to preserve the
6912 // first-qualifier-in-scope here, just in case we had a dependent
6913 // base (and therefore couldn't do the check) and a
6914 // nested-name-qualifier (and therefore could do the lookup).
6915 NamedDecl *FirstQualifierInScope = 0;
6916
John McCallb268a282010-08-23 23:25:46 +00006917 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00006918 E->isArrow(),
Douglas Gregorea972d32011-02-28 21:54:11 +00006919 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00006920 TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006921 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00006922 Member,
John McCall16df1e52010-03-30 21:47:33 +00006923 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00006924 (E->hasExplicitTemplateArgs()
John McCall6b51f282009-11-23 01:53:49 +00006925 ? &TransArgs : 0),
John McCall38836f02010-01-15 08:34:02 +00006926 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00006927}
Mike Stump11289f42009-09-09 15:08:12 +00006928
Douglas Gregora16548e2009-08-11 05:31:07 +00006929template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006930ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006931TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00006932 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006933 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006934 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006935
John McCalldadc5752010-08-24 06:29:42 +00006936 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006937 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006938 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006939
Douglas Gregora16548e2009-08-11 05:31:07 +00006940 if (!getDerived().AlwaysRebuild() &&
6941 LHS.get() == E->getLHS() &&
6942 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00006943 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006944
Lang Hames5de91cc2012-10-02 04:45:10 +00006945 Sema::FPContractStateRAII FPContractState(getSema());
6946 getSema().FPFeatures.fp_contract = E->isFPContractable();
6947
Douglas Gregora16548e2009-08-11 05:31:07 +00006948 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00006949 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006950}
6951
Mike Stump11289f42009-09-09 15:08:12 +00006952template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006953ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006954TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00006955 CompoundAssignOperator *E) {
6956 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006957}
Mike Stump11289f42009-09-09 15:08:12 +00006958
Douglas Gregora16548e2009-08-11 05:31:07 +00006959template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00006960ExprResult TreeTransform<Derived>::
6961TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
6962 // Just rebuild the common and RHS expressions and see whether we
6963 // get any changes.
6964
6965 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
6966 if (commonExpr.isInvalid())
6967 return ExprError();
6968
6969 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
6970 if (rhs.isInvalid())
6971 return ExprError();
6972
6973 if (!getDerived().AlwaysRebuild() &&
6974 commonExpr.get() == e->getCommon() &&
6975 rhs.get() == e->getFalseExpr())
6976 return SemaRef.Owned(e);
6977
6978 return getDerived().RebuildConditionalOperator(commonExpr.take(),
6979 e->getQuestionLoc(),
6980 0,
6981 e->getColonLoc(),
6982 rhs.get());
6983}
6984
6985template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006986ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006987TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00006988 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00006989 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006990 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006991
John McCalldadc5752010-08-24 06:29:42 +00006992 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006993 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006994 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006995
John McCalldadc5752010-08-24 06:29:42 +00006996 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006997 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006998 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006999
Douglas Gregora16548e2009-08-11 05:31:07 +00007000 if (!getDerived().AlwaysRebuild() &&
7001 Cond.get() == E->getCond() &&
7002 LHS.get() == E->getLHS() &&
7003 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00007004 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007005
John McCallb268a282010-08-23 23:25:46 +00007006 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00007007 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00007008 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00007009 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00007010 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007011}
Mike Stump11289f42009-09-09 15:08:12 +00007012
7013template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007014ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007015TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00007016 // Implicit casts are eliminated during transformation, since they
7017 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00007018 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007019}
Mike Stump11289f42009-09-09 15:08:12 +00007020
Douglas Gregora16548e2009-08-11 05:31:07 +00007021template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007022ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007023TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007024 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7025 if (!Type)
7026 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007027
John McCalldadc5752010-08-24 06:29:42 +00007028 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00007029 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007030 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007031 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007032
Douglas Gregora16548e2009-08-11 05:31:07 +00007033 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007034 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007035 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00007036 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007037
John McCall97513962010-01-15 18:39:57 +00007038 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007039 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00007040 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007041 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007042}
Mike Stump11289f42009-09-09 15:08:12 +00007043
Douglas Gregora16548e2009-08-11 05:31:07 +00007044template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007045ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007046TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00007047 TypeSourceInfo *OldT = E->getTypeSourceInfo();
7048 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
7049 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00007050 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007051
John McCalldadc5752010-08-24 06:29:42 +00007052 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00007053 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007054 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007055
Douglas Gregora16548e2009-08-11 05:31:07 +00007056 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00007057 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007058 Init.get() == E->getInitializer())
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007059 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007060
John McCall5d7aa7f2010-01-19 22:33:45 +00007061 // Note: the expression type doesn't necessarily match the
7062 // type-as-written, but that's okay, because it should always be
7063 // derivable from the initializer.
7064
John McCalle15bbff2010-01-18 19:35:47 +00007065 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00007066 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00007067 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007068}
Mike Stump11289f42009-09-09 15:08:12 +00007069
Douglas Gregora16548e2009-08-11 05:31:07 +00007070template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007071ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007072TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007073 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00007074 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007075 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007076
Douglas Gregora16548e2009-08-11 05:31:07 +00007077 if (!getDerived().AlwaysRebuild() &&
7078 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007079 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007080
Douglas Gregora16548e2009-08-11 05:31:07 +00007081 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00007082 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00007083 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00007084 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00007085 E->getAccessorLoc(),
7086 E->getAccessor());
7087}
Mike Stump11289f42009-09-09 15:08:12 +00007088
Douglas Gregora16548e2009-08-11 05:31:07 +00007089template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007090ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007091TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007092 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00007093
Benjamin Kramerf0623432012-08-23 22:51:59 +00007094 SmallVector<Expr*, 4> Inits;
Chad Rosier1dcde962012-08-08 18:46:20 +00007095 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00007096 Inits, &InitChanged))
7097 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007098
Douglas Gregora16548e2009-08-11 05:31:07 +00007099 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCallc3007a22010-10-26 07:05:15 +00007100 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007101
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007102 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00007103 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00007104}
Mike Stump11289f42009-09-09 15:08:12 +00007105
Douglas Gregora16548e2009-08-11 05:31:07 +00007106template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007107ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007108TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007109 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00007110
Douglas Gregorebe10102009-08-20 07:17:43 +00007111 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00007112 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00007113 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007114 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007115
Douglas Gregorebe10102009-08-20 07:17:43 +00007116 // transform the designators.
Benjamin Kramerf0623432012-08-23 22:51:59 +00007117 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregora16548e2009-08-11 05:31:07 +00007118 bool ExprChanged = false;
7119 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
7120 DEnd = E->designators_end();
7121 D != DEnd; ++D) {
7122 if (D->isFieldDesignator()) {
7123 Desig.AddDesignator(Designator::getField(D->getFieldName(),
7124 D->getDotLoc(),
7125 D->getFieldLoc()));
7126 continue;
7127 }
Mike Stump11289f42009-09-09 15:08:12 +00007128
Douglas Gregora16548e2009-08-11 05:31:07 +00007129 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00007130 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00007131 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007132 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007133
7134 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007135 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00007136
Douglas Gregora16548e2009-08-11 05:31:07 +00007137 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
7138 ArrayExprs.push_back(Index.release());
7139 continue;
7140 }
Mike Stump11289f42009-09-09 15:08:12 +00007141
Douglas Gregora16548e2009-08-11 05:31:07 +00007142 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00007143 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00007144 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
7145 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007146 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007147
John McCalldadc5752010-08-24 06:29:42 +00007148 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00007149 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007150 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007151
7152 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007153 End.get(),
7154 D->getLBracketLoc(),
7155 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00007156
Douglas Gregora16548e2009-08-11 05:31:07 +00007157 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
7158 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00007159
Douglas Gregora16548e2009-08-11 05:31:07 +00007160 ArrayExprs.push_back(Start.release());
7161 ArrayExprs.push_back(End.release());
7162 }
Mike Stump11289f42009-09-09 15:08:12 +00007163
Douglas Gregora16548e2009-08-11 05:31:07 +00007164 if (!getDerived().AlwaysRebuild() &&
7165 Init.get() == E->getInit() &&
7166 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00007167 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007168
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007169 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00007170 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00007171 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007172}
Mike Stump11289f42009-09-09 15:08:12 +00007173
Douglas Gregora16548e2009-08-11 05:31:07 +00007174template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007175ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007176TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007177 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00007178 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier1dcde962012-08-08 18:46:20 +00007179
Douglas Gregor3da3c062009-10-28 00:29:27 +00007180 // FIXME: Will we ever have proper type location here? Will we actually
7181 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00007182 QualType T = getDerived().TransformType(E->getType());
7183 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00007184 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007185
Douglas Gregora16548e2009-08-11 05:31:07 +00007186 if (!getDerived().AlwaysRebuild() &&
7187 T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00007188 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007189
Douglas Gregora16548e2009-08-11 05:31:07 +00007190 return getDerived().RebuildImplicitValueInitExpr(T);
7191}
Mike Stump11289f42009-09-09 15:08:12 +00007192
Douglas Gregora16548e2009-08-11 05:31:07 +00007193template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007194ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007195TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00007196 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
7197 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007198 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007199
John McCalldadc5752010-08-24 06:29:42 +00007200 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007201 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007202 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007203
Douglas Gregora16548e2009-08-11 05:31:07 +00007204 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00007205 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007206 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00007207 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007208
John McCallb268a282010-08-23 23:25:46 +00007209 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00007210 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007211}
7212
7213template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007214ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007215TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007216 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007217 SmallVector<Expr*, 4> Inits;
Douglas Gregora3efea12011-01-03 19:04:46 +00007218 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
7219 &ArgumentChanged))
7220 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007221
Douglas Gregora16548e2009-08-11 05:31:07 +00007222 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007223 Inits,
Douglas Gregora16548e2009-08-11 05:31:07 +00007224 E->getRParenLoc());
7225}
Mike Stump11289f42009-09-09 15:08:12 +00007226
Douglas Gregora16548e2009-08-11 05:31:07 +00007227/// \brief Transform an address-of-label expression.
7228///
7229/// By default, the transformation of an address-of-label expression always
7230/// rebuilds the expression, so that the label identifier can be resolved to
7231/// the corresponding label statement by semantic analysis.
7232template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007233ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007234TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +00007235 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
7236 E->getLabel());
7237 if (!LD)
7238 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007239
Douglas Gregora16548e2009-08-11 05:31:07 +00007240 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00007241 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +00007242}
Mike Stump11289f42009-09-09 15:08:12 +00007243
7244template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00007245ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007246TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalled7b2782012-04-06 18:20:53 +00007247 SemaRef.ActOnStartStmtExpr();
John McCalldadc5752010-08-24 06:29:42 +00007248 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00007249 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCalled7b2782012-04-06 18:20:53 +00007250 if (SubStmt.isInvalid()) {
7251 SemaRef.ActOnStmtExprError();
John McCallfaf5fb42010-08-26 23:41:50 +00007252 return ExprError();
John McCalled7b2782012-04-06 18:20:53 +00007253 }
Mike Stump11289f42009-09-09 15:08:12 +00007254
Douglas Gregora16548e2009-08-11 05:31:07 +00007255 if (!getDerived().AlwaysRebuild() &&
John McCalled7b2782012-04-06 18:20:53 +00007256 SubStmt.get() == E->getSubStmt()) {
7257 // Calling this an 'error' is unintuitive, but it does the right thing.
7258 SemaRef.ActOnStmtExprError();
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007259 return SemaRef.MaybeBindToTemporary(E);
John McCalled7b2782012-04-06 18:20:53 +00007260 }
Mike Stump11289f42009-09-09 15:08:12 +00007261
7262 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007263 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007264 E->getRParenLoc());
7265}
Mike Stump11289f42009-09-09 15:08:12 +00007266
Douglas Gregora16548e2009-08-11 05:31:07 +00007267template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007268ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007269TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007270 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00007271 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007272 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007273
John McCalldadc5752010-08-24 06:29:42 +00007274 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007275 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007276 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007277
John McCalldadc5752010-08-24 06:29:42 +00007278 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007279 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007280 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007281
Douglas Gregora16548e2009-08-11 05:31:07 +00007282 if (!getDerived().AlwaysRebuild() &&
7283 Cond.get() == E->getCond() &&
7284 LHS.get() == E->getLHS() &&
7285 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00007286 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007287
Douglas Gregora16548e2009-08-11 05:31:07 +00007288 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00007289 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007290 E->getRParenLoc());
7291}
Mike Stump11289f42009-09-09 15:08:12 +00007292
Douglas Gregora16548e2009-08-11 05:31:07 +00007293template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007294ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007295TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007296 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007297}
7298
7299template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007300ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007301TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007302 switch (E->getOperator()) {
7303 case OO_New:
7304 case OO_Delete:
7305 case OO_Array_New:
7306 case OO_Array_Delete:
7307 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier1dcde962012-08-08 18:46:20 +00007308
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007309 case OO_Call: {
7310 // This is a call to an object's operator().
7311 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
7312
7313 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00007314 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007315 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007316 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007317
7318 // FIXME: Poor location information
7319 SourceLocation FakeLParenLoc
7320 = SemaRef.PP.getLocForEndOfToken(
7321 static_cast<Expr *>(Object.get())->getLocEnd());
7322
7323 // Transform the call arguments.
Benjamin Kramerf0623432012-08-23 22:51:59 +00007324 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00007325 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregora3efea12011-01-03 19:04:46 +00007326 Args))
7327 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007328
John McCallb268a282010-08-23 23:25:46 +00007329 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007330 Args,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007331 E->getLocEnd());
7332 }
7333
7334#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
7335 case OO_##Name:
7336#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
7337#include "clang/Basic/OperatorKinds.def"
7338 case OO_Subscript:
7339 // Handled below.
7340 break;
7341
7342 case OO_Conditional:
7343 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007344
7345 case OO_None:
7346 case NUM_OVERLOADED_OPERATORS:
7347 llvm_unreachable("not an overloaded operator?");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007348 }
7349
John McCalldadc5752010-08-24 06:29:42 +00007350 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00007351 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007352 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007353
Richard Smithdb2630f2012-10-21 03:28:35 +00007354 ExprResult First;
7355 if (E->getOperator() == OO_Amp)
7356 First = getDerived().TransformAddressOfOperand(E->getArg(0));
7357 else
7358 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00007359 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007360 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007361
John McCalldadc5752010-08-24 06:29:42 +00007362 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00007363 if (E->getNumArgs() == 2) {
7364 Second = getDerived().TransformExpr(E->getArg(1));
7365 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007366 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007367 }
Mike Stump11289f42009-09-09 15:08:12 +00007368
Douglas Gregora16548e2009-08-11 05:31:07 +00007369 if (!getDerived().AlwaysRebuild() &&
7370 Callee.get() == E->getCallee() &&
7371 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00007372 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007373 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00007374
Lang Hames5de91cc2012-10-02 04:45:10 +00007375 Sema::FPContractStateRAII FPContractState(getSema());
7376 getSema().FPFeatures.fp_contract = E->isFPContractable();
7377
Douglas Gregora16548e2009-08-11 05:31:07 +00007378 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
7379 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00007380 Callee.get(),
7381 First.get(),
7382 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007383}
Mike Stump11289f42009-09-09 15:08:12 +00007384
Douglas Gregora16548e2009-08-11 05:31:07 +00007385template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007386ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007387TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
7388 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007389}
Mike Stump11289f42009-09-09 15:08:12 +00007390
Douglas Gregora16548e2009-08-11 05:31:07 +00007391template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007392ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +00007393TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
7394 // Transform the callee.
7395 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
7396 if (Callee.isInvalid())
7397 return ExprError();
7398
7399 // Transform exec config.
7400 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
7401 if (EC.isInvalid())
7402 return ExprError();
7403
7404 // Transform arguments.
7405 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007406 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00007407 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00007408 &ArgChanged))
7409 return ExprError();
7410
7411 if (!getDerived().AlwaysRebuild() &&
7412 Callee.get() == E->getCallee() &&
7413 !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007414 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbourne41f85462011-02-09 21:07:24 +00007415
7416 // FIXME: Wrong source location information for the '('.
7417 SourceLocation FakeLParenLoc
7418 = ((Expr *)Callee.get())->getSourceRange().getBegin();
7419 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007420 Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00007421 E->getRParenLoc(), EC.get());
7422}
7423
7424template<typename Derived>
7425ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007426TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007427 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7428 if (!Type)
7429 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007430
John McCalldadc5752010-08-24 06:29:42 +00007431 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00007432 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007433 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007434 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007435
Douglas Gregora16548e2009-08-11 05:31:07 +00007436 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007437 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007438 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00007439 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007440 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00007441 E->getStmtClass(),
Fariborz Jahanianf0738712013-02-22 22:02:53 +00007442 E->getAngleBrackets().getBegin(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007443 Type,
Fariborz Jahanianf0738712013-02-22 22:02:53 +00007444 E->getAngleBrackets().getEnd(),
7445 // FIXME. this should be '(' location
7446 E->getAngleBrackets().getEnd(),
John McCallb268a282010-08-23 23:25:46 +00007447 SubExpr.get(),
Abramo Bagnara9fb43862012-10-15 21:08:58 +00007448 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007449}
Mike Stump11289f42009-09-09 15:08:12 +00007450
Douglas Gregora16548e2009-08-11 05:31:07 +00007451template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007452ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007453TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
7454 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007455}
Mike Stump11289f42009-09-09 15:08:12 +00007456
7457template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007458ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007459TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
7460 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00007461}
7462
Douglas Gregora16548e2009-08-11 05:31:07 +00007463template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007464ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007465TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007466 CXXReinterpretCastExpr *E) {
7467 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007468}
Mike Stump11289f42009-09-09 15:08:12 +00007469
Douglas Gregora16548e2009-08-11 05:31:07 +00007470template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007471ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007472TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
7473 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007474}
Mike Stump11289f42009-09-09 15:08:12 +00007475
Douglas Gregora16548e2009-08-11 05:31:07 +00007476template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007477ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007478TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007479 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007480 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7481 if (!Type)
7482 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007483
John McCalldadc5752010-08-24 06:29:42 +00007484 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00007485 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007486 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007487 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007488
Douglas Gregora16548e2009-08-11 05:31:07 +00007489 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007490 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007491 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00007492 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007493
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007494 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Eli Friedman89fe0d52013-08-15 22:02:56 +00007495 E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007496 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007497 E->getRParenLoc());
7498}
Mike Stump11289f42009-09-09 15:08:12 +00007499
Douglas Gregora16548e2009-08-11 05:31:07 +00007500template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007501ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007502TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007503 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00007504 TypeSourceInfo *TInfo
7505 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7506 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007507 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007508
Douglas Gregora16548e2009-08-11 05:31:07 +00007509 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00007510 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00007511 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007512
Douglas Gregor9da64192010-04-26 22:37:10 +00007513 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7514 E->getLocStart(),
7515 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00007516 E->getLocEnd());
7517 }
Mike Stump11289f42009-09-09 15:08:12 +00007518
Eli Friedman456f0182012-01-20 01:26:23 +00007519 // We don't know whether the subexpression is potentially evaluated until
7520 // after we perform semantic analysis. We speculatively assume it is
7521 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregora16548e2009-08-11 05:31:07 +00007522 // potentially evaluated.
Eli Friedman15681d62012-09-26 04:34:21 +00007523 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
7524 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00007525
John McCalldadc5752010-08-24 06:29:42 +00007526 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00007527 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007528 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007529
Douglas Gregora16548e2009-08-11 05:31:07 +00007530 if (!getDerived().AlwaysRebuild() &&
7531 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00007532 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007533
Douglas Gregor9da64192010-04-26 22:37:10 +00007534 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7535 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00007536 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007537 E->getLocEnd());
7538}
7539
7540template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007541ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00007542TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
7543 if (E->isTypeOperand()) {
7544 TypeSourceInfo *TInfo
7545 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7546 if (!TInfo)
7547 return ExprError();
7548
7549 if (!getDerived().AlwaysRebuild() &&
7550 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00007551 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00007552
Douglas Gregor69735112011-03-06 17:40:41 +00007553 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet9f4f2072010-09-08 12:20:18 +00007554 E->getLocStart(),
7555 TInfo,
7556 E->getLocEnd());
7557 }
7558
Francois Pichet9f4f2072010-09-08 12:20:18 +00007559 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7560
7561 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
7562 if (SubExpr.isInvalid())
7563 return ExprError();
7564
7565 if (!getDerived().AlwaysRebuild() &&
7566 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00007567 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00007568
7569 return getDerived().RebuildCXXUuidofExpr(E->getType(),
7570 E->getLocStart(),
7571 SubExpr.get(),
7572 E->getLocEnd());
7573}
7574
7575template<typename Derived>
7576ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007577TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007578 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007579}
Mike Stump11289f42009-09-09 15:08:12 +00007580
Douglas Gregora16548e2009-08-11 05:31:07 +00007581template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007582ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007583TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007584 CXXNullPtrLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007585 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007586}
Mike Stump11289f42009-09-09 15:08:12 +00007587
Douglas Gregora16548e2009-08-11 05:31:07 +00007588template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007589ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007590TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Richard Smithc3d2ebb2013-06-07 02:33:37 +00007591 QualType T = getSema().getCurrentThisType();
Mike Stump11289f42009-09-09 15:08:12 +00007592
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00007593 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
7594 // Make sure that we capture 'this'.
7595 getSema().CheckCXXThisCapture(E->getLocStart());
John McCallc3007a22010-10-26 07:05:15 +00007596 return SemaRef.Owned(E);
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00007597 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007598
Douglas Gregorb15af892010-01-07 23:12:05 +00007599 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00007600}
Mike Stump11289f42009-09-09 15:08:12 +00007601
Douglas Gregora16548e2009-08-11 05:31:07 +00007602template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007603ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007604TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007605 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007606 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007607 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007608
Douglas Gregora16548e2009-08-11 05:31:07 +00007609 if (!getDerived().AlwaysRebuild() &&
7610 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00007611 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007612
Douglas Gregor53e191ed2011-07-06 22:04:06 +00007613 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
7614 E->isThrownVariableInScope());
Douglas Gregora16548e2009-08-11 05:31:07 +00007615}
Mike Stump11289f42009-09-09 15:08:12 +00007616
Douglas Gregora16548e2009-08-11 05:31:07 +00007617template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007618ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007619TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00007620 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007621 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
7622 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007623 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00007624 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007625
Chandler Carruth794da4c2010-02-08 06:42:49 +00007626 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007627 Param == E->getParam())
John McCallc3007a22010-10-26 07:05:15 +00007628 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007629
Douglas Gregor033f6752009-12-23 23:03:06 +00007630 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00007631}
Mike Stump11289f42009-09-09 15:08:12 +00007632
Douglas Gregora16548e2009-08-11 05:31:07 +00007633template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007634ExprResult
Richard Smith852c9db2013-04-20 22:23:05 +00007635TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
7636 FieldDecl *Field
7637 = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(),
7638 E->getField()));
7639 if (!Field)
7640 return ExprError();
7641
7642 if (!getDerived().AlwaysRebuild() && Field == E->getField())
7643 return SemaRef.Owned(E);
7644
7645 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
7646}
7647
7648template<typename Derived>
7649ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00007650TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
7651 CXXScalarValueInitExpr *E) {
7652 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7653 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007654 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007655
Douglas Gregora16548e2009-08-11 05:31:07 +00007656 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00007657 T == E->getTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00007658 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007659
Chad Rosier1dcde962012-08-08 18:46:20 +00007660 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregor2b88c112010-09-08 00:15:04 +00007661 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00007662 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007663}
Mike Stump11289f42009-09-09 15:08:12 +00007664
Douglas Gregora16548e2009-08-11 05:31:07 +00007665template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007666ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007667TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007668 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00007669 TypeSourceInfo *AllocTypeInfo
7670 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
7671 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007672 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007673
Douglas Gregora16548e2009-08-11 05:31:07 +00007674 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00007675 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00007676 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007677 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007678
Douglas Gregora16548e2009-08-11 05:31:07 +00007679 // Transform the placement arguments (if any).
7680 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007681 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier1dcde962012-08-08 18:46:20 +00007682 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregora3efea12011-01-03 19:04:46 +00007683 E->getNumPlacementArgs(), true,
7684 PlacementArgs, &ArgumentChanged))
Sebastian Redl6047f072012-02-16 12:22:20 +00007685 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007686
Sebastian Redl6047f072012-02-16 12:22:20 +00007687 // Transform the initializer (if any).
7688 Expr *OldInit = E->getInitializer();
7689 ExprResult NewInit;
7690 if (OldInit)
7691 NewInit = getDerived().TransformExpr(OldInit);
7692 if (NewInit.isInvalid())
7693 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007694
Sebastian Redl6047f072012-02-16 12:22:20 +00007695 // Transform new operator and delete operator.
Douglas Gregord2d9da02010-02-26 00:38:10 +00007696 FunctionDecl *OperatorNew = 0;
7697 if (E->getOperatorNew()) {
7698 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007699 getDerived().TransformDecl(E->getLocStart(),
7700 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00007701 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00007702 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00007703 }
7704
7705 FunctionDecl *OperatorDelete = 0;
7706 if (E->getOperatorDelete()) {
7707 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007708 getDerived().TransformDecl(E->getLocStart(),
7709 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00007710 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00007711 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00007712 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007713
Douglas Gregora16548e2009-08-11 05:31:07 +00007714 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00007715 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007716 ArraySize.get() == E->getArraySize() &&
Sebastian Redl6047f072012-02-16 12:22:20 +00007717 NewInit.get() == OldInit &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00007718 OperatorNew == E->getOperatorNew() &&
7719 OperatorDelete == E->getOperatorDelete() &&
7720 !ArgumentChanged) {
7721 // Mark any declarations we need as referenced.
7722 // FIXME: instantiation-specific.
Douglas Gregord2d9da02010-02-26 00:38:10 +00007723 if (OperatorNew)
Eli Friedmanfa0df832012-02-02 03:46:19 +00007724 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregord2d9da02010-02-26 00:38:10 +00007725 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00007726 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00007727
Sebastian Redl6047f072012-02-16 12:22:20 +00007728 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor72912fb2011-07-26 15:11:03 +00007729 QualType ElementType
7730 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
7731 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
7732 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
7733 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedmanfa0df832012-02-02 03:46:19 +00007734 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor72912fb2011-07-26 15:11:03 +00007735 }
7736 }
7737 }
Sebastian Redl6047f072012-02-16 12:22:20 +00007738
John McCallc3007a22010-10-26 07:05:15 +00007739 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00007740 }
Mike Stump11289f42009-09-09 15:08:12 +00007741
Douglas Gregor0744ef62010-09-07 21:49:58 +00007742 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00007743 if (!ArraySize.get()) {
7744 // If no array size was specified, but the new expression was
7745 // instantiated with an array type (e.g., "new T" where T is
7746 // instantiated with "int[4]"), extract the outer bound from the
7747 // array type as our array size. We do this with constant and
7748 // dependently-sized array types.
7749 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
7750 if (!ArrayT) {
7751 // Do nothing
7752 } else if (const ConstantArrayType *ConsArrayT
7753 = dyn_cast<ConstantArrayType>(ArrayT)) {
Chad Rosier1dcde962012-08-08 18:46:20 +00007754 ArraySize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00007755 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
Chad Rosier1dcde962012-08-08 18:46:20 +00007756 ConsArrayT->getSize(),
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00007757 SemaRef.Context.getSizeType(),
7758 /*FIXME:*/E->getLocStart()));
Douglas Gregor2e9c7952009-12-22 17:13:37 +00007759 AllocType = ConsArrayT->getElementType();
7760 } else if (const DependentSizedArrayType *DepArrayT
7761 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
7762 if (DepArrayT->getSizeExpr()) {
John McCallc3007a22010-10-26 07:05:15 +00007763 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00007764 AllocType = DepArrayT->getElementType();
7765 }
7766 }
7767 }
Sebastian Redl6047f072012-02-16 12:22:20 +00007768
Douglas Gregora16548e2009-08-11 05:31:07 +00007769 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
7770 E->isGlobalNew(),
7771 /*FIXME:*/E->getLocStart(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007772 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00007773 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00007774 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007775 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00007776 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00007777 ArraySize.get(),
Sebastian Redl6047f072012-02-16 12:22:20 +00007778 E->getDirectInitRange(),
7779 NewInit.take());
Douglas Gregora16548e2009-08-11 05:31:07 +00007780}
Mike Stump11289f42009-09-09 15:08:12 +00007781
Douglas Gregora16548e2009-08-11 05:31:07 +00007782template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007783ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007784TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007785 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00007786 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007787 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007788
Douglas Gregord2d9da02010-02-26 00:38:10 +00007789 // Transform the delete operator, if known.
7790 FunctionDecl *OperatorDelete = 0;
7791 if (E->getOperatorDelete()) {
7792 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007793 getDerived().TransformDecl(E->getLocStart(),
7794 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00007795 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00007796 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00007797 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007798
Douglas Gregora16548e2009-08-11 05:31:07 +00007799 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00007800 Operand.get() == E->getArgument() &&
7801 OperatorDelete == E->getOperatorDelete()) {
7802 // Mark any declarations we need as referenced.
7803 // FIXME: instantiation-specific.
7804 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00007805 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00007806
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00007807 if (!E->getArgument()->isTypeDependent()) {
7808 QualType Destroyed = SemaRef.Context.getBaseElementType(
7809 E->getDestroyedType());
7810 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
7811 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +00007812 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedmanfa0df832012-02-02 03:46:19 +00007813 SemaRef.LookupDestructor(Record));
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00007814 }
7815 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007816
John McCallc3007a22010-10-26 07:05:15 +00007817 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00007818 }
Mike Stump11289f42009-09-09 15:08:12 +00007819
Douglas Gregora16548e2009-08-11 05:31:07 +00007820 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
7821 E->isGlobalDelete(),
7822 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00007823 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007824}
Mike Stump11289f42009-09-09 15:08:12 +00007825
Douglas Gregora16548e2009-08-11 05:31:07 +00007826template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007827ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00007828TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007829 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007830 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00007831 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007832 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007833
John McCallba7bf592010-08-24 05:47:05 +00007834 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00007835 bool MayBePseudoDestructor = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00007836 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00007837 E->getOperatorLoc(),
7838 E->isArrow()? tok::arrow : tok::period,
7839 ObjectTypePtr,
7840 MayBePseudoDestructor);
7841 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007842 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007843
John McCallba7bf592010-08-24 05:47:05 +00007844 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +00007845 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
7846 if (QualifierLoc) {
7847 QualifierLoc
7848 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
7849 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +00007850 return ExprError();
7851 }
Douglas Gregora6ce6082011-02-25 18:19:59 +00007852 CXXScopeSpec SS;
7853 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00007854
Douglas Gregor678f90d2010-02-25 01:56:36 +00007855 PseudoDestructorTypeStorage Destroyed;
7856 if (E->getDestroyedTypeInfo()) {
7857 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00007858 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregor579c15f2011-03-02 18:32:08 +00007859 ObjectType, 0, SS);
Douglas Gregor678f90d2010-02-25 01:56:36 +00007860 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007861 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00007862 Destroyed = DestroyedTypeInfo;
Douglas Gregorf39a8dd2011-11-09 02:19:47 +00007863 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregor678f90d2010-02-25 01:56:36 +00007864 // We aren't likely to be able to resolve the identifier down to a type
7865 // now anyway, so just retain the identifier.
7866 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
7867 E->getDestroyedTypeLoc());
7868 } else {
7869 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +00007870 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00007871 *E->getDestroyedTypeIdentifier(),
7872 E->getDestroyedTypeLoc(),
7873 /*Scope=*/0,
7874 SS, ObjectTypePtr,
7875 false);
7876 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007877 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007878
Douglas Gregor678f90d2010-02-25 01:56:36 +00007879 Destroyed
7880 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
7881 E->getDestroyedTypeLoc());
7882 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007883
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007884 TypeSourceInfo *ScopeTypeInfo = 0;
7885 if (E->getScopeTypeInfo()) {
Douglas Gregora88c55b2013-03-08 21:25:01 +00007886 CXXScopeSpec EmptySS;
7887 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
7888 E->getScopeTypeInfo(), ObjectType, 0, EmptySS);
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007889 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007890 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00007891 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007892
John McCallb268a282010-08-23 23:25:46 +00007893 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00007894 E->getOperatorLoc(),
7895 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +00007896 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007897 ScopeTypeInfo,
7898 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00007899 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00007900 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00007901}
Mike Stump11289f42009-09-09 15:08:12 +00007902
Douglas Gregorad8a3362009-09-04 17:36:40 +00007903template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007904ExprResult
John McCalld14a8642009-11-21 08:51:07 +00007905TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007906 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00007907 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
7908 Sema::LookupOrdinaryName);
7909
7910 // Transform all the decls.
7911 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
7912 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007913 NamedDecl *InstD = static_cast<NamedDecl*>(
7914 getDerived().TransformDecl(Old->getNameLoc(),
7915 *I));
John McCall84d87672009-12-10 09:41:52 +00007916 if (!InstD) {
7917 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7918 // This can happen because of dependent hiding.
7919 if (isa<UsingShadowDecl>(*I))
7920 continue;
Serge Pavlov82605302013-09-04 04:50:29 +00007921 else {
7922 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00007923 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00007924 }
John McCall84d87672009-12-10 09:41:52 +00007925 }
John McCalle66edc12009-11-24 19:00:30 +00007926
7927 // Expand using declarations.
7928 if (isa<UsingDecl>(InstD)) {
7929 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +00007930 for (auto *I : UD->shadows())
7931 R.addDecl(I);
John McCalle66edc12009-11-24 19:00:30 +00007932 continue;
7933 }
7934
7935 R.addDecl(InstD);
7936 }
7937
7938 // Resolve a kind, but don't do any further analysis. If it's
7939 // ambiguous, the callee needs to deal with it.
7940 R.resolveKind();
7941
7942 // Rebuild the nested-name qualifier, if present.
7943 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00007944 if (Old->getQualifierLoc()) {
7945 NestedNameSpecifierLoc QualifierLoc
7946 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7947 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007948 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007949
Douglas Gregor0da1d432011-02-28 20:01:57 +00007950 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00007951 }
7952
Douglas Gregor9262f472010-04-27 18:19:34 +00007953 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00007954 CXXRecordDecl *NamingClass
7955 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
7956 Old->getNameLoc(),
7957 Old->getNamingClass()));
Serge Pavlov82605302013-09-04 04:50:29 +00007958 if (!NamingClass) {
7959 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00007960 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00007961 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007962
Douglas Gregorda7be082010-04-27 16:10:10 +00007963 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00007964 }
7965
Abramo Bagnara7945c982012-01-27 09:46:47 +00007966 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
7967
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00007968 // If we have neither explicit template arguments, nor the template keyword,
7969 // it's a normal declaration name.
7970 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
John McCalle66edc12009-11-24 19:00:30 +00007971 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
7972
7973 // If we have template arguments, rebuild them, then rebuild the
7974 // templateid expression.
7975 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola3dd531d2012-08-28 04:13:54 +00007976 if (Old->hasExplicitTemplateArgs() &&
7977 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregor62e06f22010-12-20 17:31:10 +00007978 Old->getNumTemplateArgs(),
Serge Pavlov82605302013-09-04 04:50:29 +00007979 TransArgs)) {
7980 R.clear();
Douglas Gregor62e06f22010-12-20 17:31:10 +00007981 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00007982 }
John McCalle66edc12009-11-24 19:00:30 +00007983
Abramo Bagnara7945c982012-01-27 09:46:47 +00007984 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00007985 Old->requiresADL(), &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00007986}
Mike Stump11289f42009-09-09 15:08:12 +00007987
Douglas Gregora16548e2009-08-11 05:31:07 +00007988template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007989ExprResult
Douglas Gregor29c42f22012-02-24 07:38:34 +00007990TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
7991 bool ArgChanged = false;
Dmitri Gribenkof8579502013-01-12 19:30:44 +00007992 SmallVector<TypeSourceInfo *, 4> Args;
Douglas Gregor29c42f22012-02-24 07:38:34 +00007993 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
7994 TypeSourceInfo *From = E->getArg(I);
7995 TypeLoc FromTL = From->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00007996 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
Douglas Gregor29c42f22012-02-24 07:38:34 +00007997 TypeLocBuilder TLB;
7998 TLB.reserve(FromTL.getFullDataSize());
7999 QualType To = getDerived().TransformType(TLB, FromTL);
8000 if (To.isNull())
8001 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008002
Douglas Gregor29c42f22012-02-24 07:38:34 +00008003 if (To == From->getType())
8004 Args.push_back(From);
8005 else {
8006 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8007 ArgChanged = true;
8008 }
8009 continue;
8010 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008011
Douglas Gregor29c42f22012-02-24 07:38:34 +00008012 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00008013
Douglas Gregor29c42f22012-02-24 07:38:34 +00008014 // We have a pack expansion. Instantiate it.
David Blaikie6adc78e2013-02-18 22:06:02 +00008015 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
Douglas Gregor29c42f22012-02-24 07:38:34 +00008016 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
8017 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
8018 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00008019
Douglas Gregor29c42f22012-02-24 07:38:34 +00008020 // Determine whether the set of unexpanded parameter packs can and should
8021 // be expanded.
8022 bool Expand = true;
8023 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00008024 Optional<unsigned> OrigNumExpansions =
8025 ExpansionTL.getTypePtr()->getNumExpansions();
8026 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor29c42f22012-02-24 07:38:34 +00008027 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
8028 PatternTL.getSourceRange(),
8029 Unexpanded,
8030 Expand, RetainExpansion,
8031 NumExpansions))
8032 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008033
Douglas Gregor29c42f22012-02-24 07:38:34 +00008034 if (!Expand) {
8035 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00008036 // transformation on the pack expansion, producing another pack
Douglas Gregor29c42f22012-02-24 07:38:34 +00008037 // expansion.
8038 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier1dcde962012-08-08 18:46:20 +00008039
Douglas Gregor29c42f22012-02-24 07:38:34 +00008040 TypeLocBuilder TLB;
8041 TLB.reserve(From->getTypeLoc().getFullDataSize());
8042
8043 QualType To = getDerived().TransformType(TLB, PatternTL);
8044 if (To.isNull())
8045 return ExprError();
8046
Chad Rosier1dcde962012-08-08 18:46:20 +00008047 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00008048 PatternTL.getSourceRange(),
8049 ExpansionTL.getEllipsisLoc(),
8050 NumExpansions);
8051 if (To.isNull())
8052 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008053
Douglas Gregor29c42f22012-02-24 07:38:34 +00008054 PackExpansionTypeLoc ToExpansionTL
8055 = TLB.push<PackExpansionTypeLoc>(To);
8056 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8057 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8058 continue;
8059 }
8060
8061 // Expand the pack expansion by substituting for each argument in the
8062 // pack(s).
8063 for (unsigned I = 0; I != *NumExpansions; ++I) {
8064 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
8065 TypeLocBuilder TLB;
8066 TLB.reserve(PatternTL.getFullDataSize());
8067 QualType To = getDerived().TransformType(TLB, PatternTL);
8068 if (To.isNull())
8069 return ExprError();
8070
Eli Friedman5e05c4a2013-07-19 21:49:32 +00008071 if (To->containsUnexpandedParameterPack()) {
8072 To = getDerived().RebuildPackExpansionType(To,
8073 PatternTL.getSourceRange(),
8074 ExpansionTL.getEllipsisLoc(),
8075 NumExpansions);
8076 if (To.isNull())
8077 return ExprError();
8078
8079 PackExpansionTypeLoc ToExpansionTL
8080 = TLB.push<PackExpansionTypeLoc>(To);
8081 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8082 }
8083
Douglas Gregor29c42f22012-02-24 07:38:34 +00008084 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8085 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008086
Douglas Gregor29c42f22012-02-24 07:38:34 +00008087 if (!RetainExpansion)
8088 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00008089
Douglas Gregor29c42f22012-02-24 07:38:34 +00008090 // If we're supposed to retain a pack expansion, do so by temporarily
8091 // forgetting the partially-substituted parameter pack.
8092 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
8093
8094 TypeLocBuilder TLB;
8095 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00008096
Douglas Gregor29c42f22012-02-24 07:38:34 +00008097 QualType To = getDerived().TransformType(TLB, PatternTL);
8098 if (To.isNull())
8099 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008100
8101 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00008102 PatternTL.getSourceRange(),
8103 ExpansionTL.getEllipsisLoc(),
8104 NumExpansions);
8105 if (To.isNull())
8106 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008107
Douglas Gregor29c42f22012-02-24 07:38:34 +00008108 PackExpansionTypeLoc ToExpansionTL
8109 = TLB.push<PackExpansionTypeLoc>(To);
8110 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8111 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8112 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008113
Douglas Gregor29c42f22012-02-24 07:38:34 +00008114 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8115 return SemaRef.Owned(E);
8116
8117 return getDerived().RebuildTypeTrait(E->getTrait(),
8118 E->getLocStart(),
8119 Args,
8120 E->getLocEnd());
8121}
8122
8123template<typename Derived>
8124ExprResult
John Wiegley6242b6a2011-04-28 00:16:57 +00008125TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
8126 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
8127 if (!T)
8128 return ExprError();
8129
8130 if (!getDerived().AlwaysRebuild() &&
8131 T == E->getQueriedTypeSourceInfo())
8132 return SemaRef.Owned(E);
8133
8134 ExprResult SubExpr;
8135 {
8136 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8137 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
8138 if (SubExpr.isInvalid())
8139 return ExprError();
8140
8141 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
8142 return SemaRef.Owned(E);
8143 }
8144
8145 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
8146 E->getLocStart(),
8147 T,
8148 SubExpr.get(),
8149 E->getLocEnd());
8150}
8151
8152template<typename Derived>
8153ExprResult
John Wiegleyf9f65842011-04-25 06:54:41 +00008154TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
8155 ExprResult SubExpr;
8156 {
8157 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8158 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
8159 if (SubExpr.isInvalid())
8160 return ExprError();
8161
8162 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
8163 return SemaRef.Owned(E);
8164 }
8165
8166 return getDerived().RebuildExpressionTrait(
8167 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
8168}
8169
8170template<typename Derived>
8171ExprResult
John McCall8cd78132009-11-19 22:55:06 +00008172TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008173 DependentScopeDeclRefExpr *E) {
Richard Smithdb2630f2012-10-21 03:28:35 +00008174 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand*/false);
8175}
8176
8177template<typename Derived>
8178ExprResult
8179TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
8180 DependentScopeDeclRefExpr *E,
8181 bool IsAddressOfOperand) {
Reid Kleckner916ac4d2013-10-15 18:38:02 +00008182 assert(E->getQualifierLoc());
Douglas Gregor3a43fd62011-02-25 20:49:16 +00008183 NestedNameSpecifierLoc QualifierLoc
8184 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
8185 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008186 return ExprError();
Abramo Bagnara7945c982012-01-27 09:46:47 +00008187 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00008188
John McCall31f82722010-11-12 08:19:04 +00008189 // TODO: If this is a conversion-function-id, verify that the
8190 // destination type name (if present) resolves the same way after
8191 // instantiation as it did in the local scope.
8192
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008193 DeclarationNameInfo NameInfo
8194 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
8195 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00008196 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008197
John McCalle66edc12009-11-24 19:00:30 +00008198 if (!E->hasExplicitTemplateArgs()) {
8199 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3a43fd62011-02-25 20:49:16 +00008200 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008201 // Note: it is sufficient to compare the Name component of NameInfo:
8202 // if name has not changed, DNLoc has not changed either.
8203 NameInfo.getName() == E->getDeclName())
John McCallc3007a22010-10-26 07:05:15 +00008204 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00008205
Douglas Gregor3a43fd62011-02-25 20:49:16 +00008206 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008207 TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008208 NameInfo,
Richard Smithdb2630f2012-10-21 03:28:35 +00008209 /*TemplateArgs*/ 0,
8210 IsAddressOfOperand);
Douglas Gregord019ff62009-10-22 17:20:55 +00008211 }
John McCall6b51f282009-11-23 01:53:49 +00008212
8213 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008214 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8215 E->getNumTemplateArgs(),
8216 TransArgs))
8217 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008218
Douglas Gregor3a43fd62011-02-25 20:49:16 +00008219 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008220 TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008221 NameInfo,
Richard Smithdb2630f2012-10-21 03:28:35 +00008222 &TransArgs,
8223 IsAddressOfOperand);
Douglas Gregora16548e2009-08-11 05:31:07 +00008224}
8225
8226template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008227ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008228TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithd59b8322012-12-19 01:39:02 +00008229 // CXXConstructExprs other than for list-initialization and
8230 // CXXTemporaryObjectExpr are always implicit, so when we have
8231 // a 1-argument construction we just transform that argument.
Richard Smithdd2ca572012-11-26 08:32:48 +00008232 if ((E->getNumArgs() == 1 ||
8233 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithd59b8322012-12-19 01:39:02 +00008234 (!getDerived().DropCallArgument(E->getArg(0))) &&
8235 !E->isListInitialization())
Douglas Gregordb56b912010-02-03 03:01:57 +00008236 return getDerived().TransformExpr(E->getArg(0));
8237
Douglas Gregora16548e2009-08-11 05:31:07 +00008238 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
8239
8240 QualType T = getDerived().TransformType(E->getType());
8241 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00008242 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008243
8244 CXXConstructorDecl *Constructor
8245 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008246 getDerived().TransformDecl(E->getLocStart(),
8247 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008248 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00008249 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008250
Douglas Gregora16548e2009-08-11 05:31:07 +00008251 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008252 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00008253 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00008254 &ArgumentChanged))
8255 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008256
Douglas Gregora16548e2009-08-11 05:31:07 +00008257 if (!getDerived().AlwaysRebuild() &&
8258 T == E->getType() &&
8259 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00008260 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00008261 // Mark the constructor as referenced.
8262 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00008263 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00008264 return SemaRef.Owned(E);
Douglas Gregorde550352010-02-26 00:01:57 +00008265 }
Mike Stump11289f42009-09-09 15:08:12 +00008266
Douglas Gregordb121ba2009-12-14 16:27:04 +00008267 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
8268 Constructor, E->isElidable(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008269 Args,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00008270 E->hadMultipleCandidates(),
Richard Smithd59b8322012-12-19 01:39:02 +00008271 E->isListInitialization(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00008272 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00008273 E->getConstructionKind(),
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00008274 E->getParenOrBraceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00008275}
Mike Stump11289f42009-09-09 15:08:12 +00008276
Douglas Gregora16548e2009-08-11 05:31:07 +00008277/// \brief Transform a C++ temporary-binding expression.
8278///
Douglas Gregor363b1512009-12-24 18:51:59 +00008279/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
8280/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00008281template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008282ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008283TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00008284 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008285}
Mike Stump11289f42009-09-09 15:08:12 +00008286
John McCall5d413782010-12-06 08:20:24 +00008287/// \brief Transform a C++ expression that contains cleanups that should
8288/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +00008289///
John McCall5d413782010-12-06 08:20:24 +00008290/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +00008291/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00008292template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008293ExprResult
John McCall5d413782010-12-06 08:20:24 +00008294TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00008295 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008296}
Mike Stump11289f42009-09-09 15:08:12 +00008297
Douglas Gregora16548e2009-08-11 05:31:07 +00008298template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008299ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008300TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00008301 CXXTemporaryObjectExpr *E) {
8302 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8303 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00008304 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008305
Douglas Gregora16548e2009-08-11 05:31:07 +00008306 CXXConstructorDecl *Constructor
8307 = cast_or_null<CXXConstructorDecl>(
Chad Rosier1dcde962012-08-08 18:46:20 +00008308 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008309 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008310 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00008311 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008312
Douglas Gregora16548e2009-08-11 05:31:07 +00008313 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008314 SmallVector<Expr*, 8> Args;
Douglas Gregora16548e2009-08-11 05:31:07 +00008315 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +00008316 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00008317 &ArgumentChanged))
8318 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008319
Douglas Gregora16548e2009-08-11 05:31:07 +00008320 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00008321 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008322 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00008323 !ArgumentChanged) {
8324 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00008325 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00008326 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00008327 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008328
Richard Smithd59b8322012-12-19 01:39:02 +00008329 // FIXME: Pass in E->isListInitialization().
Douglas Gregor2b88c112010-09-08 00:15:04 +00008330 return getDerived().RebuildCXXTemporaryObjectExpr(T,
8331 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008332 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00008333 E->getLocEnd());
8334}
Mike Stump11289f42009-09-09 15:08:12 +00008335
Douglas Gregora16548e2009-08-11 05:31:07 +00008336template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008337ExprResult
Douglas Gregore31e6062012-02-07 10:09:13 +00008338TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008339
8340 // Transform any init-capture expressions before entering the scope of the
8341 // lambda body, because they are not semantically within that scope.
8342 SmallVector<InitCaptureInfoTy, 8> InitCaptureExprsAndTypes;
8343 InitCaptureExprsAndTypes.resize(E->explicit_capture_end() -
8344 E->explicit_capture_begin());
8345
8346 for (LambdaExpr::capture_iterator C = E->capture_begin(),
8347 CEnd = E->capture_end();
8348 C != CEnd; ++C) {
8349 if (!C->isInitCapture())
8350 continue;
8351 EnterExpressionEvaluationContext EEEC(getSema(),
8352 Sema::PotentiallyEvaluated);
8353 ExprResult NewExprInitResult = getDerived().TransformInitializer(
8354 C->getCapturedVar()->getInit(),
8355 C->getCapturedVar()->getInitStyle() == VarDecl::CallInit);
8356
8357 if (NewExprInitResult.isInvalid())
8358 return ExprError();
8359 Expr *NewExprInit = NewExprInitResult.get();
8360
8361 VarDecl *OldVD = C->getCapturedVar();
8362 QualType NewInitCaptureType =
8363 getSema().performLambdaInitCaptureInitialization(C->getLocation(),
8364 OldVD->getType()->isReferenceType(), OldVD->getIdentifier(),
8365 NewExprInit);
8366 NewExprInitResult = NewExprInit;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008367 InitCaptureExprsAndTypes[C - E->capture_begin()] =
8368 std::make_pair(NewExprInitResult, NewInitCaptureType);
8369
8370 }
8371
Faisal Vali524ca282013-11-12 01:40:44 +00008372 LambdaScopeInfo *LSI = getSema().PushLambdaScope();
Faisal Vali2cba1332013-10-23 06:44:28 +00008373 // Transform the template parameters, and add them to the current
8374 // instantiation scope. The null case is handled correctly.
8375 LSI->GLTemplateParameterList = getDerived().TransformTemplateParameterList(
8376 E->getTemplateParameterList());
8377
8378 // Check to see if the TypeSourceInfo of the call operator needs to
8379 // be transformed, and if so do the transformation in the
8380 // CurrentInstantiationScope.
8381
8382 TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo();
8383 FunctionProtoTypeLoc OldCallOpFPTL =
8384 OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>();
8385 TypeSourceInfo *NewCallOpTSI = 0;
8386
8387 const bool CallOpWasAlreadyTransformed =
8388 getDerived().AlreadyTransformed(OldCallOpTSI->getType());
8389
8390 // Use the Old Call Operator's TypeSourceInfo if it is already transformed.
8391 if (CallOpWasAlreadyTransformed)
8392 NewCallOpTSI = OldCallOpTSI;
8393 else {
8394 // Transform the TypeSourceInfo of the Original Lambda's Call Operator.
8395 // The transformation MUST be done in the CurrentInstantiationScope since
8396 // it introduces a mapping of the original to the newly created
8397 // transformed parameters.
8398
8399 TypeLocBuilder NewCallOpTLBuilder;
8400 QualType NewCallOpType = TransformFunctionProtoType(NewCallOpTLBuilder,
8401 OldCallOpFPTL,
8402 0, 0);
8403 NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context,
8404 NewCallOpType);
Faisal Vali2b391ab2013-09-26 19:54:12 +00008405 }
Faisal Vali2cba1332013-10-23 06:44:28 +00008406 // Extract the ParmVarDecls from the NewCallOpTSI and add them to
8407 // the vector below - this will be used to synthesize the
8408 // NewCallOperator. Additionally, add the parameters of the untransformed
8409 // lambda call operator to the CurrentInstantiationScope.
8410 SmallVector<ParmVarDecl *, 4> Params;
8411 {
8412 FunctionProtoTypeLoc NewCallOpFPTL =
8413 NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>();
8414 ParmVarDecl **NewParamDeclArray = NewCallOpFPTL.getParmArray();
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00008415 const unsigned NewNumArgs = NewCallOpFPTL.getNumParams();
Faisal Vali2cba1332013-10-23 06:44:28 +00008416
8417 for (unsigned I = 0; I < NewNumArgs; ++I) {
8418 // If this call operator's type does not require transformation,
8419 // the parameters do not get added to the current instantiation scope,
8420 // - so ADD them! This allows the following to compile when the enclosing
8421 // template is specialized and the entire lambda expression has to be
8422 // transformed.
8423 // template<class T> void foo(T t) {
8424 // auto L = [](auto a) {
8425 // auto M = [](char b) { <-- note: non-generic lambda
8426 // auto N = [](auto c) {
8427 // int x = sizeof(a);
8428 // x = sizeof(b); <-- specifically this line
8429 // x = sizeof(c);
8430 // };
8431 // };
8432 // };
8433 // }
8434 // foo('a')
8435 if (CallOpWasAlreadyTransformed)
8436 getDerived().transformedLocalDecl(NewParamDeclArray[I],
8437 NewParamDeclArray[I]);
8438 // Add to Params array, so these parameters can be used to create
8439 // the newly transformed call operator.
8440 Params.push_back(NewParamDeclArray[I]);
8441 }
8442 }
8443
8444 if (!NewCallOpTSI)
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008445 return ExprError();
8446
Eli Friedmand564afb2012-09-19 01:18:11 +00008447 // Create the local class that will describe the lambda.
8448 CXXRecordDecl *Class
8449 = getSema().createLambdaClosureType(E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +00008450 NewCallOpTSI,
Faisal Valic1a6dc42013-10-23 16:10:50 +00008451 /*KnownDependent=*/false,
8452 E->getCaptureDefault());
8453
Eli Friedmand564afb2012-09-19 01:18:11 +00008454 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
8455
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008456 // Build the call operator.
Faisal Vali2cba1332013-10-23 06:44:28 +00008457 CXXMethodDecl *NewCallOperator
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008458 = getSema().startLambdaDefinition(Class, E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +00008459 NewCallOpTSI,
Douglas Gregoradb376e2012-02-14 22:28:59 +00008460 E->getCallOperator()->getLocEnd(),
Richard Smith505df232012-07-22 23:45:10 +00008461 Params);
Faisal Vali2cba1332013-10-23 06:44:28 +00008462 LSI->CallOperator = NewCallOperator;
Rafael Espindola4b35f272013-10-04 14:28:51 +00008463
Faisal Vali2cba1332013-10-23 06:44:28 +00008464 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
8465
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008466 return getDerived().TransformLambdaScope(E, NewCallOperator,
8467 InitCaptureExprsAndTypes);
Richard Smith2589b9802012-07-25 03:56:55 +00008468}
8469
8470template<typename Derived>
8471ExprResult
8472TreeTransform<Derived>::TransformLambdaScope(LambdaExpr *E,
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008473 CXXMethodDecl *CallOperator,
8474 ArrayRef<InitCaptureInfoTy> InitCaptureExprsAndTypes) {
Richard Smithba71c082013-05-16 06:20:58 +00008475 bool Invalid = false;
8476
Douglas Gregorb4328232012-02-14 00:00:48 +00008477 // Introduce the context of the call operator.
Richard Smith7ff2bcb2014-01-24 01:54:52 +00008478 Sema::ContextRAII SavedContext(getSema(), CallOperator,
8479 /*NewThisContext*/false);
Douglas Gregorb4328232012-02-14 00:00:48 +00008480
Faisal Vali2b391ab2013-09-26 19:54:12 +00008481 LambdaScopeInfo *const LSI = getSema().getCurLambda();
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008482 // Enter the scope of the lambda.
Faisal Vali2b391ab2013-09-26 19:54:12 +00008483 getSema().buildLambdaScope(LSI, CallOperator, E->getIntroducerRange(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008484 E->getCaptureDefault(),
James Dennettddd36ff2013-08-09 23:08:25 +00008485 E->getCaptureDefaultLoc(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008486 E->hasExplicitParameters(),
8487 E->hasExplicitResultType(),
8488 E->isMutable());
Chad Rosier1dcde962012-08-08 18:46:20 +00008489
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008490 // Transform captures.
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008491 bool FinishedExplicitCaptures = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00008492 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008493 CEnd = E->capture_end();
8494 C != CEnd; ++C) {
8495 // When we hit the first implicit capture, tell Sema that we've finished
8496 // the list of explicit captures.
8497 if (!FinishedExplicitCaptures && C->isImplicit()) {
8498 getSema().finishLambdaExplicitCaptures(LSI);
8499 FinishedExplicitCaptures = true;
8500 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008501
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008502 // Capturing 'this' is trivial.
8503 if (C->capturesThis()) {
8504 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
8505 continue;
8506 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008507
Richard Smithba71c082013-05-16 06:20:58 +00008508 // Rebuild init-captures, including the implied field declaration.
8509 if (C->isInitCapture()) {
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008510
8511 InitCaptureInfoTy InitExprTypePair =
8512 InitCaptureExprsAndTypes[C - E->capture_begin()];
8513 ExprResult Init = InitExprTypePair.first;
8514 QualType InitQualType = InitExprTypePair.second;
8515 if (Init.isInvalid() || InitQualType.isNull()) {
Richard Smithba71c082013-05-16 06:20:58 +00008516 Invalid = true;
8517 continue;
8518 }
Richard Smithbb13c9a2013-09-28 04:02:39 +00008519 VarDecl *OldVD = C->getCapturedVar();
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008520 VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl(
8521 OldVD->getLocation(), InitExprTypePair.second,
8522 OldVD->getIdentifier(), Init.get());
Richard Smithbb13c9a2013-09-28 04:02:39 +00008523 if (!NewVD)
Richard Smithba71c082013-05-16 06:20:58 +00008524 Invalid = true;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008525 else {
Richard Smithbb13c9a2013-09-28 04:02:39 +00008526 getDerived().transformedLocalDecl(OldVD, NewVD);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008527 }
Richard Smithbb13c9a2013-09-28 04:02:39 +00008528 getSema().buildInitCaptureField(LSI, NewVD);
Richard Smithba71c082013-05-16 06:20:58 +00008529 continue;
8530 }
8531
8532 assert(C->capturesVariable() && "unexpected kind of lambda capture");
8533
Douglas Gregor3e308b12012-02-14 19:27:52 +00008534 // Determine the capture kind for Sema.
8535 Sema::TryCaptureKind Kind
8536 = C->isImplicit()? Sema::TryCapture_Implicit
8537 : C->getCaptureKind() == LCK_ByCopy
8538 ? Sema::TryCapture_ExplicitByVal
8539 : Sema::TryCapture_ExplicitByRef;
8540 SourceLocation EllipsisLoc;
8541 if (C->isPackExpansion()) {
8542 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
8543 bool ShouldExpand = false;
8544 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00008545 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +00008546 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
8547 C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +00008548 Unexpanded,
8549 ShouldExpand, RetainExpansion,
Richard Smithba71c082013-05-16 06:20:58 +00008550 NumExpansions)) {
8551 Invalid = true;
8552 continue;
8553 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008554
Douglas Gregor3e308b12012-02-14 19:27:52 +00008555 if (ShouldExpand) {
8556 // The transform has determined that we should perform an expansion;
8557 // transform and capture each of the arguments.
8558 // expansion of the pattern. Do so.
8559 VarDecl *Pack = C->getCapturedVar();
8560 for (unsigned I = 0; I != *NumExpansions; ++I) {
8561 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8562 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +00008563 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +00008564 Pack));
8565 if (!CapturedVar) {
8566 Invalid = true;
8567 continue;
8568 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008569
Douglas Gregor3e308b12012-02-14 19:27:52 +00008570 // Capture the transformed variable.
Chad Rosier1dcde962012-08-08 18:46:20 +00008571 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
8572 }
Douglas Gregor3e308b12012-02-14 19:27:52 +00008573 continue;
8574 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008575
Douglas Gregor3e308b12012-02-14 19:27:52 +00008576 EllipsisLoc = C->getEllipsisLoc();
8577 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008578
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008579 // Transform the captured variable.
8580 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +00008581 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008582 C->getCapturedVar()));
8583 if (!CapturedVar) {
8584 Invalid = true;
8585 continue;
8586 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008587
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008588 // Capture the transformed variable.
Douglas Gregorfdf598e2012-02-18 09:37:24 +00008589 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008590 }
8591 if (!FinishedExplicitCaptures)
8592 getSema().finishLambdaExplicitCaptures(LSI);
8593
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008594
8595 // Enter a new evaluation context to insulate the lambda from any
8596 // cleanups from the enclosing full-expression.
Chad Rosier1dcde962012-08-08 18:46:20 +00008597 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008598
8599 if (Invalid) {
Chad Rosier1dcde962012-08-08 18:46:20 +00008600 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008601 /*IsInstantiation=*/true);
8602 return ExprError();
8603 }
8604
8605 // Instantiate the body of the lambda expression.
Douglas Gregorb4328232012-02-14 00:00:48 +00008606 StmtResult Body = getDerived().TransformStmt(E->getBody());
8607 if (Body.isInvalid()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00008608 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
Douglas Gregorb4328232012-02-14 00:00:48 +00008609 /*IsInstantiation=*/true);
Chad Rosier1dcde962012-08-08 18:46:20 +00008610 return ExprError();
Douglas Gregorb4328232012-02-14 00:00:48 +00008611 }
Douglas Gregor7fcbd902012-02-21 00:37:24 +00008612
Chad Rosier1dcde962012-08-08 18:46:20 +00008613 return getSema().ActOnLambdaExpr(E->getLocStart(), Body.take(),
Douglas Gregorb61e8092012-04-04 17:40:10 +00008614 /*CurScope=*/0, /*IsInstantiation=*/true);
Douglas Gregore31e6062012-02-07 10:09:13 +00008615}
8616
8617template<typename Derived>
8618ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008619TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008620 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00008621 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8622 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00008623 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008624
Douglas Gregora16548e2009-08-11 05:31:07 +00008625 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008626 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +00008627 Args.reserve(E->arg_size());
Chad Rosier1dcde962012-08-08 18:46:20 +00008628 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00008629 &ArgumentChanged))
8630 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008631
Douglas Gregora16548e2009-08-11 05:31:07 +00008632 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00008633 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008634 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00008635 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00008636
Douglas Gregora16548e2009-08-11 05:31:07 +00008637 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +00008638 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +00008639 E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008640 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00008641 E->getRParenLoc());
8642}
Mike Stump11289f42009-09-09 15:08:12 +00008643
Douglas Gregora16548e2009-08-11 05:31:07 +00008644template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008645ExprResult
John McCall8cd78132009-11-19 22:55:06 +00008646TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008647 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008648 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00008649 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00008650 Expr *OldBase;
8651 QualType BaseType;
8652 QualType ObjectType;
8653 if (!E->isImplicitAccess()) {
8654 OldBase = E->getBase();
8655 Base = getDerived().TransformExpr(OldBase);
8656 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008657 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008658
John McCall2d74de92009-12-01 22:10:20 +00008659 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +00008660 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +00008661 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00008662 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00008663 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00008664 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00008665 ObjectTy,
8666 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00008667 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008668 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00008669
John McCallba7bf592010-08-24 05:47:05 +00008670 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +00008671 BaseType = ((Expr*) Base.get())->getType();
8672 } else {
8673 OldBase = 0;
8674 BaseType = getDerived().TransformType(E->getBaseType());
8675 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
8676 }
Mike Stump11289f42009-09-09 15:08:12 +00008677
Douglas Gregora5cb6da2009-10-20 05:58:46 +00008678 // Transform the first part of the nested-name-specifier that qualifies
8679 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00008680 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00008681 = getDerived().TransformFirstQualifierInScope(
Douglas Gregore16af532011-02-28 18:50:33 +00008682 E->getFirstQualifierFoundInScope(),
8683 E->getQualifierLoc().getBeginLoc());
Mike Stump11289f42009-09-09 15:08:12 +00008684
Douglas Gregore16af532011-02-28 18:50:33 +00008685 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00008686 if (E->getQualifier()) {
Douglas Gregore16af532011-02-28 18:50:33 +00008687 QualifierLoc
8688 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
8689 ObjectType,
8690 FirstQualifierInScope);
8691 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008692 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +00008693 }
Mike Stump11289f42009-09-09 15:08:12 +00008694
Abramo Bagnara7945c982012-01-27 09:46:47 +00008695 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
8696
John McCall31f82722010-11-12 08:19:04 +00008697 // TODO: If this is a conversion-function-id, verify that the
8698 // destination type name (if present) resolves the same way after
8699 // instantiation as it did in the local scope.
8700
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008701 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +00008702 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008703 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00008704 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008705
John McCall2d74de92009-12-01 22:10:20 +00008706 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00008707 // This is a reference to a member without an explicitly-specified
8708 // template argument list. Optimize for this common case.
8709 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00008710 Base.get() == OldBase &&
8711 BaseType == E->getBaseType() &&
Douglas Gregore16af532011-02-28 18:50:33 +00008712 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008713 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00008714 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCallc3007a22010-10-26 07:05:15 +00008715 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00008716
John McCallb268a282010-08-23 23:25:46 +00008717 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00008718 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00008719 E->isArrow(),
8720 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00008721 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008722 TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00008723 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008724 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00008725 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00008726 }
8727
John McCall6b51f282009-11-23 01:53:49 +00008728 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008729 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8730 E->getNumTemplateArgs(),
8731 TransArgs))
8732 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008733
John McCallb268a282010-08-23 23:25:46 +00008734 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00008735 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00008736 E->isArrow(),
8737 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00008738 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008739 TemplateKWLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +00008740 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008741 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00008742 &TransArgs);
8743}
8744
8745template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008746ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008747TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00008748 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00008749 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00008750 QualType BaseType;
8751 if (!Old->isImplicitAccess()) {
8752 Base = getDerived().TransformExpr(Old->getBase());
8753 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008754 return ExprError();
Richard Smithcab9a7d2011-10-26 19:06:56 +00008755 Base = getSema().PerformMemberExprBaseConversion(Base.take(),
8756 Old->isArrow());
8757 if (Base.isInvalid())
8758 return ExprError();
8759 BaseType = Base.get()->getType();
John McCall2d74de92009-12-01 22:10:20 +00008760 } else {
8761 BaseType = getDerived().TransformType(Old->getBaseType());
8762 }
John McCall10eae182009-11-30 22:42:35 +00008763
Douglas Gregor0da1d432011-02-28 20:01:57 +00008764 NestedNameSpecifierLoc QualifierLoc;
8765 if (Old->getQualifierLoc()) {
8766 QualifierLoc
8767 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
8768 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008769 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00008770 }
8771
Abramo Bagnara7945c982012-01-27 09:46:47 +00008772 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
8773
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008774 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +00008775 Sema::LookupOrdinaryName);
8776
8777 // Transform all the decls.
8778 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
8779 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008780 NamedDecl *InstD = static_cast<NamedDecl*>(
8781 getDerived().TransformDecl(Old->getMemberLoc(),
8782 *I));
John McCall84d87672009-12-10 09:41:52 +00008783 if (!InstD) {
8784 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
8785 // This can happen because of dependent hiding.
8786 if (isa<UsingShadowDecl>(*I))
8787 continue;
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00008788 else {
8789 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00008790 return ExprError();
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00008791 }
John McCall84d87672009-12-10 09:41:52 +00008792 }
John McCall10eae182009-11-30 22:42:35 +00008793
8794 // Expand using declarations.
8795 if (isa<UsingDecl>(InstD)) {
8796 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +00008797 for (auto *I : UD->shadows())
8798 R.addDecl(I);
John McCall10eae182009-11-30 22:42:35 +00008799 continue;
8800 }
8801
8802 R.addDecl(InstD);
8803 }
8804
8805 R.resolveKind();
8806
Douglas Gregor9262f472010-04-27 18:19:34 +00008807 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00008808 if (Old->getNamingClass()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00008809 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00008810 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00008811 Old->getMemberLoc(),
8812 Old->getNamingClass()));
8813 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00008814 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008815
Douglas Gregorda7be082010-04-27 16:10:10 +00008816 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00008817 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008818
John McCall10eae182009-11-30 22:42:35 +00008819 TemplateArgumentListInfo TransArgs;
8820 if (Old->hasExplicitTemplateArgs()) {
8821 TransArgs.setLAngleLoc(Old->getLAngleLoc());
8822 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008823 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
8824 Old->getNumTemplateArgs(),
8825 TransArgs))
8826 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00008827 }
John McCall38836f02010-01-15 08:34:02 +00008828
8829 // FIXME: to do this check properly, we will need to preserve the
8830 // first-qualifier-in-scope here, just in case we had a dependent
8831 // base (and therefore couldn't do the check) and a
8832 // nested-name-qualifier (and therefore could do the lookup).
8833 NamedDecl *FirstQualifierInScope = 0;
Chad Rosier1dcde962012-08-08 18:46:20 +00008834
John McCallb268a282010-08-23 23:25:46 +00008835 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00008836 BaseType,
John McCall10eae182009-11-30 22:42:35 +00008837 Old->getOperatorLoc(),
8838 Old->isArrow(),
Douglas Gregor0da1d432011-02-28 20:01:57 +00008839 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008840 TemplateKWLoc,
John McCall38836f02010-01-15 08:34:02 +00008841 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00008842 R,
8843 (Old->hasExplicitTemplateArgs()
8844 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00008845}
8846
8847template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008848ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +00008849TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Alexis Hunt414e3e32011-05-31 19:54:49 +00008850 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00008851 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
8852 if (SubExpr.isInvalid())
8853 return ExprError();
8854
8855 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCallc3007a22010-10-26 07:05:15 +00008856 return SemaRef.Owned(E);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00008857
8858 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
8859}
8860
8861template<typename Derived>
8862ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +00008863TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +00008864 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
8865 if (Pattern.isInvalid())
8866 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008867
Douglas Gregor0f836ea2011-01-13 00:19:55 +00008868 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
8869 return SemaRef.Owned(E);
8870
Douglas Gregorb8840002011-01-14 21:20:45 +00008871 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
8872 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +00008873}
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008874
8875template<typename Derived>
8876ExprResult
8877TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
8878 // If E is not value-dependent, then nothing will change when we transform it.
8879 // Note: This is an instantiation-centric view.
8880 if (!E->isValueDependent())
8881 return SemaRef.Owned(E);
8882
8883 // Note: None of the implementations of TryExpandParameterPacks can ever
8884 // produce a diagnostic when given only a single unexpanded parameter pack,
Chad Rosier1dcde962012-08-08 18:46:20 +00008885 // so
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008886 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
8887 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00008888 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00008889 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +00008890 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikieb9c168a2011-09-22 02:34:54 +00008891 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00008892 ShouldExpand, RetainExpansion,
8893 NumExpansions))
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008894 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008895
Douglas Gregorab96bcf2011-10-10 18:59:29 +00008896 if (RetainExpansion)
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008897 return SemaRef.Owned(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00008898
Douglas Gregorab96bcf2011-10-10 18:59:29 +00008899 NamedDecl *Pack = E->getPack();
8900 if (!ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00008901 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
Douglas Gregorab96bcf2011-10-10 18:59:29 +00008902 Pack));
8903 if (!Pack)
8904 return ExprError();
8905 }
8906
Chad Rosier1dcde962012-08-08 18:46:20 +00008907
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008908 // We now know the length of the parameter pack, so build a new expression
8909 // that stores that length.
Chad Rosier1dcde962012-08-08 18:46:20 +00008910 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
8911 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregorab96bcf2011-10-10 18:59:29 +00008912 NumExpansions);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008913}
8914
Douglas Gregore8e9dd62011-01-03 17:17:50 +00008915template<typename Derived>
8916ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +00008917TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
8918 SubstNonTypeTemplateParmPackExpr *E) {
8919 // Default behavior is to do nothing with this transformation.
8920 return SemaRef.Owned(E);
8921}
8922
8923template<typename Derived>
8924ExprResult
John McCall7c454bb2011-07-15 05:09:51 +00008925TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
8926 SubstNonTypeTemplateParmExpr *E) {
8927 // Default behavior is to do nothing with this transformation.
8928 return SemaRef.Owned(E);
8929}
8930
8931template<typename Derived>
8932ExprResult
Richard Smithb15fe3a2012-09-12 00:56:43 +00008933TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
8934 // Default behavior is to do nothing with this transformation.
8935 return SemaRef.Owned(E);
8936}
8937
8938template<typename Derived>
8939ExprResult
Douglas Gregorfe314812011-06-21 17:03:29 +00008940TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
8941 MaterializeTemporaryExpr *E) {
8942 return getDerived().TransformExpr(E->GetTemporaryExpr());
8943}
Chad Rosier1dcde962012-08-08 18:46:20 +00008944
Douglas Gregorfe314812011-06-21 17:03:29 +00008945template<typename Derived>
8946ExprResult
Richard Smithcc1b96d2013-06-12 22:31:48 +00008947TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
8948 CXXStdInitializerListExpr *E) {
8949 return getDerived().TransformExpr(E->getSubExpr());
8950}
8951
8952template<typename Derived>
8953ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008954TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00008955 return SemaRef.MaybeBindToTemporary(E);
8956}
8957
8958template<typename Derived>
8959ExprResult
8960TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Jordy Rose8986c5992012-03-12 17:53:02 +00008961 return SemaRef.Owned(E);
Ted Kremeneke65b0862012-03-06 20:05:56 +00008962}
8963
8964template<typename Derived>
8965ExprResult
Patrick Beard0caa3942012-04-19 00:25:12 +00008966TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
8967 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
8968 if (SubExpr.isInvalid())
8969 return ExprError();
8970
8971 if (!getDerived().AlwaysRebuild() &&
8972 SubExpr.get() == E->getSubExpr())
8973 return SemaRef.Owned(E);
8974
8975 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremeneke65b0862012-03-06 20:05:56 +00008976}
8977
8978template<typename Derived>
8979ExprResult
8980TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
8981 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +00008982 SmallVector<Expr *, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +00008983 bool ArgChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00008984 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremeneke65b0862012-03-06 20:05:56 +00008985 /*IsCall=*/false, Elements, &ArgChanged))
8986 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008987
Ted Kremeneke65b0862012-03-06 20:05:56 +00008988 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8989 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00008990
Ted Kremeneke65b0862012-03-06 20:05:56 +00008991 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
8992 Elements.data(),
8993 Elements.size());
8994}
8995
8996template<typename Derived>
8997ExprResult
8998TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier1dcde962012-08-08 18:46:20 +00008999 ObjCDictionaryLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00009000 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +00009001 SmallVector<ObjCDictionaryElement, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009002 bool ArgChanged = false;
9003 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
9004 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier1dcde962012-08-08 18:46:20 +00009005
Ted Kremeneke65b0862012-03-06 20:05:56 +00009006 if (OrigElement.isPackExpansion()) {
9007 // This key/value element is a pack expansion.
9008 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
9009 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
9010 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
9011 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
9012
9013 // Determine whether the set of unexpanded parameter packs can
9014 // and should be expanded.
9015 bool Expand = true;
9016 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00009017 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
9018 Optional<unsigned> NumExpansions = OrigNumExpansions;
Ted Kremeneke65b0862012-03-06 20:05:56 +00009019 SourceRange PatternRange(OrigElement.Key->getLocStart(),
9020 OrigElement.Value->getLocEnd());
9021 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
9022 PatternRange,
9023 Unexpanded,
9024 Expand, RetainExpansion,
9025 NumExpansions))
9026 return ExprError();
9027
9028 if (!Expand) {
9029 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00009030 // transformation on the pack expansion, producing another pack
Ted Kremeneke65b0862012-03-06 20:05:56 +00009031 // expansion.
9032 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
9033 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
9034 if (Key.isInvalid())
9035 return ExprError();
9036
9037 if (Key.get() != OrigElement.Key)
9038 ArgChanged = true;
9039
9040 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
9041 if (Value.isInvalid())
9042 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009043
Ted Kremeneke65b0862012-03-06 20:05:56 +00009044 if (Value.get() != OrigElement.Value)
9045 ArgChanged = true;
9046
Chad Rosier1dcde962012-08-08 18:46:20 +00009047 ObjCDictionaryElement Expansion = {
Ted Kremeneke65b0862012-03-06 20:05:56 +00009048 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
9049 };
9050 Elements.push_back(Expansion);
9051 continue;
9052 }
9053
9054 // Record right away that the argument was changed. This needs
9055 // to happen even if the array expands to nothing.
9056 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009057
Ted Kremeneke65b0862012-03-06 20:05:56 +00009058 // The transform has determined that we should perform an elementwise
9059 // expansion of the pattern. Do so.
9060 for (unsigned I = 0; I != *NumExpansions; ++I) {
9061 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
9062 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
9063 if (Key.isInvalid())
9064 return ExprError();
9065
9066 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
9067 if (Value.isInvalid())
9068 return ExprError();
9069
Chad Rosier1dcde962012-08-08 18:46:20 +00009070 ObjCDictionaryElement Element = {
Ted Kremeneke65b0862012-03-06 20:05:56 +00009071 Key.get(), Value.get(), SourceLocation(), NumExpansions
9072 };
9073
9074 // If any unexpanded parameter packs remain, we still have a
9075 // pack expansion.
9076 if (Key.get()->containsUnexpandedParameterPack() ||
9077 Value.get()->containsUnexpandedParameterPack())
9078 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier1dcde962012-08-08 18:46:20 +00009079
Ted Kremeneke65b0862012-03-06 20:05:56 +00009080 Elements.push_back(Element);
9081 }
9082
9083 // We've finished with this pack expansion.
9084 continue;
9085 }
9086
9087 // Transform and check key.
9088 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
9089 if (Key.isInvalid())
9090 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009091
Ted Kremeneke65b0862012-03-06 20:05:56 +00009092 if (Key.get() != OrigElement.Key)
9093 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009094
Ted Kremeneke65b0862012-03-06 20:05:56 +00009095 // Transform and check value.
9096 ExprResult Value
9097 = getDerived().TransformExpr(OrigElement.Value);
9098 if (Value.isInvalid())
9099 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009100
Ted Kremeneke65b0862012-03-06 20:05:56 +00009101 if (Value.get() != OrigElement.Value)
9102 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009103
9104 ObjCDictionaryElement Element = {
David Blaikie7a30dc52013-02-21 01:47:18 +00009105 Key.get(), Value.get(), SourceLocation(), None
Ted Kremeneke65b0862012-03-06 20:05:56 +00009106 };
9107 Elements.push_back(Element);
9108 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009109
Ted Kremeneke65b0862012-03-06 20:05:56 +00009110 if (!getDerived().AlwaysRebuild() && !ArgChanged)
9111 return SemaRef.MaybeBindToTemporary(E);
9112
9113 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
9114 Elements.data(),
9115 Elements.size());
Douglas Gregora16548e2009-08-11 05:31:07 +00009116}
9117
Mike Stump11289f42009-09-09 15:08:12 +00009118template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009119ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009120TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00009121 TypeSourceInfo *EncodedTypeInfo
9122 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
9123 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009124 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009125
Douglas Gregora16548e2009-08-11 05:31:07 +00009126 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00009127 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00009128 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009129
9130 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00009131 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00009132 E->getRParenLoc());
9133}
Mike Stump11289f42009-09-09 15:08:12 +00009134
Douglas Gregora16548e2009-08-11 05:31:07 +00009135template<typename Derived>
John McCall31168b02011-06-15 23:02:42 +00009136ExprResult TreeTransform<Derived>::
9137TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
John McCallbc489892013-04-11 02:14:26 +00009138 // This is a kind of implicit conversion, and it needs to get dropped
9139 // and recomputed for the same general reasons that ImplicitCastExprs
9140 // do, as well a more specific one: this expression is only valid when
9141 // it appears *immediately* as an argument expression.
9142 return getDerived().TransformExpr(E->getSubExpr());
John McCall31168b02011-06-15 23:02:42 +00009143}
9144
9145template<typename Derived>
9146ExprResult TreeTransform<Derived>::
9147TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier1dcde962012-08-08 18:46:20 +00009148 TypeSourceInfo *TSInfo
John McCall31168b02011-06-15 23:02:42 +00009149 = getDerived().TransformType(E->getTypeInfoAsWritten());
9150 if (!TSInfo)
9151 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009152
John McCall31168b02011-06-15 23:02:42 +00009153 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier1dcde962012-08-08 18:46:20 +00009154 if (Result.isInvalid())
John McCall31168b02011-06-15 23:02:42 +00009155 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009156
John McCall31168b02011-06-15 23:02:42 +00009157 if (!getDerived().AlwaysRebuild() &&
9158 TSInfo == E->getTypeInfoAsWritten() &&
9159 Result.get() == E->getSubExpr())
9160 return SemaRef.Owned(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009161
John McCall31168b02011-06-15 23:02:42 +00009162 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier1dcde962012-08-08 18:46:20 +00009163 E->getBridgeKeywordLoc(), TSInfo,
John McCall31168b02011-06-15 23:02:42 +00009164 Result.get());
9165}
9166
9167template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009168ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009169TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009170 // Transform arguments.
9171 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009172 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +00009173 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +00009174 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009175 &ArgChanged))
9176 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009177
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009178 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
9179 // Class message: transform the receiver type.
9180 TypeSourceInfo *ReceiverTypeInfo
9181 = getDerived().TransformType(E->getClassReceiverTypeInfo());
9182 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009183 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009184
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009185 // If nothing changed, just retain the existing message send.
9186 if (!getDerived().AlwaysRebuild() &&
9187 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009188 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009189
9190 // Build a new class message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009191 SmallVector<SourceLocation, 16> SelLocs;
9192 E->getSelectorLocs(SelLocs);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009193 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
9194 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009195 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009196 E->getMethodDecl(),
9197 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009198 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009199 E->getRightLoc());
9200 }
9201
9202 // Instance message: transform the receiver
9203 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
9204 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +00009205 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009206 = getDerived().TransformExpr(E->getInstanceReceiver());
9207 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009208 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009209
9210 // If nothing changed, just retain the existing message send.
9211 if (!getDerived().AlwaysRebuild() &&
9212 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009213 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009214
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009215 // Build a new instance message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009216 SmallVector<SourceLocation, 16> SelLocs;
9217 E->getSelectorLocs(SelLocs);
John McCallb268a282010-08-23 23:25:46 +00009218 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009219 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009220 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009221 E->getMethodDecl(),
9222 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009223 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009224 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00009225}
9226
Mike Stump11289f42009-09-09 15:08:12 +00009227template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009228ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009229TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00009230 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009231}
9232
Mike Stump11289f42009-09-09 15:08:12 +00009233template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009234ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009235TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00009236 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009237}
9238
Mike Stump11289f42009-09-09 15:08:12 +00009239template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009240ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009241TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00009242 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00009243 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00009244 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009245 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +00009246
9247 // We don't need to transform the ivar; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +00009248
Douglas Gregord51d90d2010-04-26 20:11:03 +00009249 // If nothing changed, just retain the existing expression.
9250 if (!getDerived().AlwaysRebuild() &&
9251 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00009252 return SemaRef.Owned(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009253
John McCallb268a282010-08-23 23:25:46 +00009254 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00009255 E->getLocation(),
9256 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +00009257}
9258
Mike Stump11289f42009-09-09 15:08:12 +00009259template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009260ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009261TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +00009262 // 'super' and types never change. Property never changes. Just
9263 // retain the existing expression.
9264 if (!E->isObjectReceiver())
John McCallc3007a22010-10-26 07:05:15 +00009265 return SemaRef.Owned(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009266
Douglas Gregor9faee212010-04-26 20:47:02 +00009267 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00009268 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +00009269 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009270 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009271
Douglas Gregor9faee212010-04-26 20:47:02 +00009272 // We don't need to transform the property; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +00009273
Douglas Gregor9faee212010-04-26 20:47:02 +00009274 // If nothing changed, just retain the existing expression.
9275 if (!getDerived().AlwaysRebuild() &&
9276 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00009277 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009278
John McCallb7bd14f2010-12-02 01:19:52 +00009279 if (E->isExplicitProperty())
9280 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
9281 E->getExplicitProperty(),
9282 E->getLocation());
9283
9284 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall526ab472011-10-25 17:37:35 +00009285 SemaRef.Context.PseudoObjectTy,
John McCallb7bd14f2010-12-02 01:19:52 +00009286 E->getImplicitPropertyGetter(),
9287 E->getImplicitPropertySetter(),
9288 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00009289}
9290
Mike Stump11289f42009-09-09 15:08:12 +00009291template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009292ExprResult
Ted Kremeneke65b0862012-03-06 20:05:56 +00009293TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
9294 // Transform the base expression.
9295 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
9296 if (Base.isInvalid())
9297 return ExprError();
9298
9299 // Transform the key expression.
9300 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
9301 if (Key.isInvalid())
9302 return ExprError();
9303
9304 // If nothing changed, just retain the existing expression.
9305 if (!getDerived().AlwaysRebuild() &&
9306 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
9307 return SemaRef.Owned(E);
9308
Chad Rosier1dcde962012-08-08 18:46:20 +00009309 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremeneke65b0862012-03-06 20:05:56 +00009310 Base.get(), Key.get(),
9311 E->getAtIndexMethodDecl(),
9312 E->setAtIndexMethodDecl());
9313}
9314
9315template<typename Derived>
9316ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009317TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00009318 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00009319 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00009320 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009321 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009322
Douglas Gregord51d90d2010-04-26 20:11:03 +00009323 // If nothing changed, just retain the existing expression.
9324 if (!getDerived().AlwaysRebuild() &&
9325 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00009326 return SemaRef.Owned(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009327
John McCallb268a282010-08-23 23:25:46 +00009328 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00009329 E->getOpLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00009330 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +00009331}
9332
Mike Stump11289f42009-09-09 15:08:12 +00009333template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009334ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009335TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009336 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009337 SmallVector<Expr*, 8> SubExprs;
Douglas Gregora3efea12011-01-03 19:04:46 +00009338 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier1dcde962012-08-08 18:46:20 +00009339 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00009340 SubExprs, &ArgumentChanged))
9341 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009342
Douglas Gregora16548e2009-08-11 05:31:07 +00009343 if (!getDerived().AlwaysRebuild() &&
9344 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00009345 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00009346
Douglas Gregora16548e2009-08-11 05:31:07 +00009347 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009348 SubExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00009349 E->getRParenLoc());
9350}
9351
Mike Stump11289f42009-09-09 15:08:12 +00009352template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009353ExprResult
Hal Finkelc4d7c822013-09-18 03:29:45 +00009354TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) {
9355 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
9356 if (SrcExpr.isInvalid())
9357 return ExprError();
9358
9359 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
9360 if (!Type)
9361 return ExprError();
9362
9363 if (!getDerived().AlwaysRebuild() &&
9364 Type == E->getTypeSourceInfo() &&
9365 SrcExpr.get() == E->getSrcExpr())
9366 return SemaRef.Owned(E);
9367
9368 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
9369 SrcExpr.get(), Type,
9370 E->getRParenLoc());
9371}
9372
9373template<typename Derived>
9374ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009375TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +00009376 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier1dcde962012-08-08 18:46:20 +00009377
John McCall490112f2011-02-04 18:33:18 +00009378 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
9379 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
9380
9381 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahaniandd5eb9d2011-12-03 17:47:53 +00009382 blockScope->TheDecl->setBlockMissingReturnType(
9383 oldBlock->blockMissingReturnType());
Chad Rosier1dcde962012-08-08 18:46:20 +00009384
Chris Lattner01cf8db2011-07-20 06:58:45 +00009385 SmallVector<ParmVarDecl*, 4> params;
9386 SmallVector<QualType, 4> paramTypes;
Chad Rosier1dcde962012-08-08 18:46:20 +00009387
Fariborz Jahanian1babe772010-07-09 18:44:02 +00009388 // Parameter substitution.
John McCall490112f2011-02-04 18:33:18 +00009389 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
9390 oldBlock->param_begin(),
9391 oldBlock->param_size(),
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +00009392 0, paramTypes, &params)) {
9393 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009394 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +00009395 }
John McCall490112f2011-02-04 18:33:18 +00009396
Jordan Rosea0a86be2013-03-08 22:25:36 +00009397 const FunctionProtoType *exprFunctionType = E->getFunctionType();
Eli Friedman34b49062012-01-26 03:00:14 +00009398 QualType exprResultType =
Alp Toker314cc812014-01-25 16:55:45 +00009399 getDerived().TransformType(exprFunctionType->getReturnType());
Douglas Gregor476e3022011-01-19 21:32:01 +00009400
Jordan Rose5c382722013-03-08 21:51:21 +00009401 QualType functionType =
9402 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +00009403 exprFunctionType->getExtProtoInfo());
John McCall490112f2011-02-04 18:33:18 +00009404 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +00009405
9406 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +00009407 if (!params.empty())
David Blaikie9c70e042011-09-21 18:16:56 +00009408 blockScope->TheDecl->setParams(params);
Eli Friedman34b49062012-01-26 03:00:14 +00009409
9410 if (!oldBlock->blockMissingReturnType()) {
9411 blockScope->HasImplicitReturnType = false;
9412 blockScope->ReturnType = exprResultType;
9413 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009414
John McCall3882ace2011-01-05 12:14:39 +00009415 // Transform the body
John McCall490112f2011-02-04 18:33:18 +00009416 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +00009417 if (body.isInvalid()) {
9418 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
John McCall3882ace2011-01-05 12:14:39 +00009419 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +00009420 }
John McCall3882ace2011-01-05 12:14:39 +00009421
John McCall490112f2011-02-04 18:33:18 +00009422#ifndef NDEBUG
9423 // In builds with assertions, make sure that we captured everything we
9424 // captured before.
Douglas Gregor4385d8b2011-05-20 15:32:55 +00009425 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
Aaron Ballman9371dd22014-03-14 18:34:04 +00009426 for (const auto &I : oldBlock->captures()) {
9427 VarDecl *oldCapture = I.getVariable();
John McCall490112f2011-02-04 18:33:18 +00009428
Douglas Gregor4385d8b2011-05-20 15:32:55 +00009429 // Ignore parameter packs.
9430 if (isa<ParmVarDecl>(oldCapture) &&
9431 cast<ParmVarDecl>(oldCapture)->isParameterPack())
9432 continue;
John McCall490112f2011-02-04 18:33:18 +00009433
Douglas Gregor4385d8b2011-05-20 15:32:55 +00009434 VarDecl *newCapture =
9435 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
9436 oldCapture));
9437 assert(blockScope->CaptureMap.count(newCapture));
9438 }
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00009439 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCall490112f2011-02-04 18:33:18 +00009440 }
9441#endif
9442
9443 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
9444 /*Scope=*/0);
Douglas Gregora16548e2009-08-11 05:31:07 +00009445}
9446
Mike Stump11289f42009-09-09 15:08:12 +00009447template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009448ExprResult
Tanya Lattner55808c12011-06-04 00:47:47 +00009449TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikie83d382b2011-09-23 05:06:16 +00009450 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner55808c12011-06-04 00:47:47 +00009451}
Eli Friedmandf14b3a2011-10-11 02:20:01 +00009452
9453template<typename Derived>
9454ExprResult
9455TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedman8d3e43f2011-10-14 22:48:56 +00009456 QualType RetTy = getDerived().TransformType(E->getType());
9457 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009458 SmallVector<Expr*, 8> SubExprs;
Eli Friedman8d3e43f2011-10-14 22:48:56 +00009459 SubExprs.reserve(E->getNumSubExprs());
9460 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
9461 SubExprs, &ArgumentChanged))
9462 return ExprError();
9463
9464 if (!getDerived().AlwaysRebuild() &&
9465 !ArgumentChanged)
9466 return SemaRef.Owned(E);
9467
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009468 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedman8d3e43f2011-10-14 22:48:56 +00009469 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedmandf14b3a2011-10-11 02:20:01 +00009470}
Chad Rosier1dcde962012-08-08 18:46:20 +00009471
Douglas Gregora16548e2009-08-11 05:31:07 +00009472//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00009473// Type reconstruction
9474//===----------------------------------------------------------------------===//
9475
Mike Stump11289f42009-09-09 15:08:12 +00009476template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00009477QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
9478 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00009479 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009480 getDerived().getBaseEntity());
9481}
9482
Mike Stump11289f42009-09-09 15:08:12 +00009483template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00009484QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
9485 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00009486 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009487 getDerived().getBaseEntity());
9488}
9489
Mike Stump11289f42009-09-09 15:08:12 +00009490template<typename Derived>
9491QualType
John McCall70dd5f62009-10-30 00:06:24 +00009492TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
9493 bool WrittenAsLValue,
9494 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00009495 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +00009496 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00009497}
9498
9499template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009500QualType
John McCall70dd5f62009-10-30 00:06:24 +00009501TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
9502 QualType ClassType,
9503 SourceLocation Sigil) {
Reid Kleckner0503a872013-12-05 01:23:43 +00009504 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil,
9505 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00009506}
9507
9508template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009509QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00009510TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
9511 ArrayType::ArraySizeModifier SizeMod,
9512 const llvm::APInt *Size,
9513 Expr *SizeExpr,
9514 unsigned IndexTypeQuals,
9515 SourceRange BracketsRange) {
9516 if (SizeExpr || !Size)
9517 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
9518 IndexTypeQuals, BracketsRange,
9519 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00009520
9521 QualType Types[] = {
9522 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
9523 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
9524 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00009525 };
Craig Toppere5ce8312013-07-15 03:38:40 +00009526 const unsigned NumTypes = llvm::array_lengthof(Types);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009527 QualType SizeType;
9528 for (unsigned I = 0; I != NumTypes; ++I)
9529 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
9530 SizeType = Types[I];
9531 break;
9532 }
Mike Stump11289f42009-09-09 15:08:12 +00009533
Eli Friedman9562f392012-01-25 23:20:27 +00009534 // Note that we can return a VariableArrayType here in the case where
9535 // the element type was a dependent VariableArrayType.
9536 IntegerLiteral *ArraySize
9537 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
9538 /*FIXME*/BracketsRange.getBegin());
9539 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009540 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00009541 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00009542}
Mike Stump11289f42009-09-09 15:08:12 +00009543
Douglas Gregord6ff3322009-08-04 16:50:30 +00009544template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009545QualType
9546TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009547 ArrayType::ArraySizeModifier SizeMod,
9548 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00009549 unsigned IndexTypeQuals,
9550 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00009551 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00009552 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009553}
9554
9555template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009556QualType
Mike Stump11289f42009-09-09 15:08:12 +00009557TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009558 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00009559 unsigned IndexTypeQuals,
9560 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00009561 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00009562 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009563}
Mike Stump11289f42009-09-09 15:08:12 +00009564
Douglas Gregord6ff3322009-08-04 16:50:30 +00009565template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009566QualType
9567TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009568 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00009569 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009570 unsigned IndexTypeQuals,
9571 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00009572 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00009573 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009574 IndexTypeQuals, BracketsRange);
9575}
9576
9577template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009578QualType
9579TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009580 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00009581 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009582 unsigned IndexTypeQuals,
9583 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00009584 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00009585 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009586 IndexTypeQuals, BracketsRange);
9587}
9588
9589template<typename Derived>
9590QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +00009591 unsigned NumElements,
9592 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00009593 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +00009594 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009595}
Mike Stump11289f42009-09-09 15:08:12 +00009596
Douglas Gregord6ff3322009-08-04 16:50:30 +00009597template<typename Derived>
9598QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
9599 unsigned NumElements,
9600 SourceLocation AttributeLoc) {
9601 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
9602 NumElements, true);
9603 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00009604 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
9605 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +00009606 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009607}
Mike Stump11289f42009-09-09 15:08:12 +00009608
Douglas Gregord6ff3322009-08-04 16:50:30 +00009609template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009610QualType
9611TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +00009612 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009613 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +00009614 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009615}
Mike Stump11289f42009-09-09 15:08:12 +00009616
Douglas Gregord6ff3322009-08-04 16:50:30 +00009617template<typename Derived>
Jordan Rose5c382722013-03-08 21:51:21 +00009618QualType TreeTransform<Derived>::RebuildFunctionProtoType(
9619 QualType T,
9620 llvm::MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +00009621 const FunctionProtoType::ExtProtoInfo &EPI) {
9622 return SemaRef.BuildFunctionType(T, ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009623 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +00009624 getDerived().getBaseEntity(),
Jordan Rosea0a86be2013-03-08 22:25:36 +00009625 EPI);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009626}
Mike Stump11289f42009-09-09 15:08:12 +00009627
Douglas Gregord6ff3322009-08-04 16:50:30 +00009628template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00009629QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
9630 return SemaRef.Context.getFunctionNoProtoType(T);
9631}
9632
9633template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00009634QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
9635 assert(D && "no decl found");
9636 if (D->isInvalidDecl()) return QualType();
9637
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009638 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +00009639 TypeDecl *Ty;
9640 if (isa<UsingDecl>(D)) {
9641 UsingDecl *Using = cast<UsingDecl>(D);
Enea Zaffanellae05a3cf2013-07-22 10:54:09 +00009642 assert(Using->hasTypename() &&
John McCallb96ec562009-12-04 22:46:56 +00009643 "UnresolvedUsingTypenameDecl transformed to non-typename using");
9644
9645 // A valid resolved using typename decl points to exactly one type decl.
9646 assert(++Using->shadow_begin() == Using->shadow_end());
9647 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +00009648
John McCallb96ec562009-12-04 22:46:56 +00009649 } else {
9650 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
9651 "UnresolvedUsingTypenameDecl transformed to non-using decl");
9652 Ty = cast<UnresolvedUsingTypenameDecl>(D);
9653 }
9654
9655 return SemaRef.Context.getTypeDeclType(Ty);
9656}
9657
9658template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00009659QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
9660 SourceLocation Loc) {
9661 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009662}
9663
9664template<typename Derived>
9665QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
9666 return SemaRef.Context.getTypeOfType(Underlying);
9667}
9668
9669template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00009670QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
9671 SourceLocation Loc) {
9672 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009673}
9674
9675template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00009676QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
9677 UnaryTransformType::UTTKind UKind,
9678 SourceLocation Loc) {
9679 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
9680}
9681
9682template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00009683QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00009684 TemplateName Template,
9685 SourceLocation TemplateNameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +00009686 TemplateArgumentListInfo &TemplateArgs) {
John McCall6b51f282009-11-23 01:53:49 +00009687 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009688}
Mike Stump11289f42009-09-09 15:08:12 +00009689
Douglas Gregor1135c352009-08-06 05:28:30 +00009690template<typename Derived>
Eli Friedman0dfb8892011-10-06 23:00:33 +00009691QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
9692 SourceLocation KWLoc) {
9693 return SemaRef.BuildAtomicType(ValueType, KWLoc);
9694}
9695
9696template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009697TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00009698TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +00009699 bool TemplateKW,
9700 TemplateDecl *Template) {
Douglas Gregor9db53502011-03-02 18:07:45 +00009701 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00009702 Template);
9703}
9704
9705template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009706TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00009707TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
9708 const IdentifierInfo &Name,
9709 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +00009710 QualType ObjectType,
9711 NamedDecl *FirstQualifierInScope) {
Douglas Gregor9db53502011-03-02 18:07:45 +00009712 UnqualifiedId TemplateName;
9713 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregorbb119652010-06-16 23:00:59 +00009714 Sema::TemplateTy Template;
Abramo Bagnara7945c982012-01-27 09:46:47 +00009715 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregorbb119652010-06-16 23:00:59 +00009716 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009717 SS, TemplateKWLoc, TemplateName,
John McCallba7bf592010-08-24 05:47:05 +00009718 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00009719 /*EnteringContext=*/false,
9720 Template);
John McCall31f82722010-11-12 08:19:04 +00009721 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +00009722}
Mike Stump11289f42009-09-09 15:08:12 +00009723
Douglas Gregora16548e2009-08-11 05:31:07 +00009724template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00009725TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00009726TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +00009727 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +00009728 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +00009729 QualType ObjectType) {
Douglas Gregor71395fa2009-11-04 00:56:37 +00009730 UnqualifiedId Name;
Douglas Gregor9db53502011-03-02 18:07:45 +00009731 // FIXME: Bogus location information.
Abramo Bagnara7945c982012-01-27 09:46:47 +00009732 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregor9db53502011-03-02 18:07:45 +00009733 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnara7945c982012-01-27 09:46:47 +00009734 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregorbb119652010-06-16 23:00:59 +00009735 Sema::TemplateTy Template;
9736 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009737 SS, TemplateKWLoc, Name,
John McCallba7bf592010-08-24 05:47:05 +00009738 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00009739 /*EnteringContext=*/false,
9740 Template);
Serge Pavlov9ddb76e2013-08-27 13:15:56 +00009741 return Template.get();
Douglas Gregor71395fa2009-11-04 00:56:37 +00009742}
Chad Rosier1dcde962012-08-08 18:46:20 +00009743
Douglas Gregor71395fa2009-11-04 00:56:37 +00009744template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009745ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009746TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
9747 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00009748 Expr *OrigCallee,
9749 Expr *First,
9750 Expr *Second) {
9751 Expr *Callee = OrigCallee->IgnoreParenCasts();
9752 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00009753
Douglas Gregora16548e2009-08-11 05:31:07 +00009754 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00009755 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +00009756 if (!First->getType()->isOverloadableType() &&
9757 !Second->getType()->isOverloadableType())
9758 return getSema().CreateBuiltinArraySubscriptExpr(First,
9759 Callee->getLocStart(),
9760 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00009761 } else if (Op == OO_Arrow) {
9762 // -> is never a builtin operation.
John McCallb268a282010-08-23 23:25:46 +00009763 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
9764 } else if (Second == 0 || isPostIncDec) {
9765 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009766 // The argument is not of overloadable type, so try to create a
9767 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +00009768 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00009769 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00009770
John McCallb268a282010-08-23 23:25:46 +00009771 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00009772 }
9773 } else {
John McCallb268a282010-08-23 23:25:46 +00009774 if (!First->getType()->isOverloadableType() &&
9775 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009776 // Neither of the arguments is an overloadable type, so try to
9777 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +00009778 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00009779 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00009780 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +00009781 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009782 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009783
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009784 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00009785 }
9786 }
Mike Stump11289f42009-09-09 15:08:12 +00009787
9788 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00009789 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00009790 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00009791
John McCallb268a282010-08-23 23:25:46 +00009792 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +00009793 assert(ULE->requiresADL());
Richard Smith100b24a2014-04-17 01:52:14 +00009794 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00009795 } else {
Richard Smith58db83d2012-11-28 21:47:39 +00009796 // If we've resolved this to a particular non-member function, just call
9797 // that function. If we resolved it to a member function,
9798 // CreateOverloaded* will find that function for us.
9799 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
9800 if (!isa<CXXMethodDecl>(ND))
9801 Functions.addDecl(ND);
John McCalld14a8642009-11-21 08:51:07 +00009802 }
Mike Stump11289f42009-09-09 15:08:12 +00009803
Douglas Gregora16548e2009-08-11 05:31:07 +00009804 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +00009805 Expr *Args[2] = { First, Second };
9806 unsigned NumArgs = 1 + (Second != 0);
Mike Stump11289f42009-09-09 15:08:12 +00009807
Douglas Gregora16548e2009-08-11 05:31:07 +00009808 // Create the overloaded operator invocation for unary operators.
9809 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +00009810 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00009811 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +00009812 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00009813 }
Mike Stump11289f42009-09-09 15:08:12 +00009814
Douglas Gregore9d62932011-07-15 16:25:15 +00009815 if (Op == OO_Subscript) {
9816 SourceLocation LBrace;
9817 SourceLocation RBrace;
9818
9819 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
9820 DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
9821 LBrace = SourceLocation::getFromRawEncoding(
9822 NameLoc.CXXOperatorName.BeginOpNameLoc);
9823 RBrace = SourceLocation::getFromRawEncoding(
9824 NameLoc.CXXOperatorName.EndOpNameLoc);
9825 } else {
9826 LBrace = Callee->getLocStart();
9827 RBrace = OpLoc;
9828 }
9829
9830 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
9831 First, Second);
9832 }
Sebastian Redladba46e2009-10-29 20:17:01 +00009833
Douglas Gregora16548e2009-08-11 05:31:07 +00009834 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +00009835 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00009836 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00009837 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
9838 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009839 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009840
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009841 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00009842}
Mike Stump11289f42009-09-09 15:08:12 +00009843
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009844template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00009845ExprResult
John McCallb268a282010-08-23 23:25:46 +00009846TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009847 SourceLocation OperatorLoc,
9848 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +00009849 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009850 TypeSourceInfo *ScopeType,
9851 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00009852 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00009853 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +00009854 QualType BaseType = Base->getType();
9855 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009856 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier1dcde962012-08-08 18:46:20 +00009857 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +00009858 !BaseType->getAs<PointerType>()->getPointeeType()
9859 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009860 // This pseudo-destructor expression is still a pseudo-destructor.
John McCallb268a282010-08-23 23:25:46 +00009861 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009862 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00009863 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00009864 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009865 /*FIXME?*/true);
9866 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009867
Douglas Gregor678f90d2010-02-25 01:56:36 +00009868 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009869 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
9870 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
9871 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
9872 NameInfo.setNamedTypeInfo(DestroyedType);
9873
Richard Smith8e4a3862012-05-15 06:15:11 +00009874 // The scope type is now known to be a valid nested name specifier
9875 // component. Tack it on to the end of the nested name specifier.
9876 if (ScopeType)
9877 SS.Extend(SemaRef.Context, SourceLocation(),
9878 ScopeType->getTypeLoc(), CCLoc);
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009879
Abramo Bagnara7945c982012-01-27 09:46:47 +00009880 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCallb268a282010-08-23 23:25:46 +00009881 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009882 OperatorLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009883 SS, TemplateKWLoc,
9884 /*FIXME: FirstQualifier*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009885 NameInfo,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009886 /*TemplateArgs*/ 0);
9887}
9888
Tareq A. Siraj24110cc2013-04-16 18:53:08 +00009889template<typename Derived>
9890StmtResult
9891TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
Wei Pan17fbf6e2013-05-04 03:59:06 +00009892 SourceLocation Loc = S->getLocStart();
9893 unsigned NumParams = S->getCapturedDecl()->getNumParams();
9894 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/0,
9895 S->getCapturedRegionKind(), NumParams);
9896 StmtResult Body = getDerived().TransformStmt(S->getCapturedStmt());
9897
9898 if (Body.isInvalid()) {
9899 getSema().ActOnCapturedRegionError();
9900 return StmtError();
9901 }
9902
9903 return getSema().ActOnCapturedRegionEnd(Body.take());
Tareq A. Siraj24110cc2013-04-16 18:53:08 +00009904}
9905
Douglas Gregord6ff3322009-08-04 16:50:30 +00009906} // end namespace clang
9907
9908#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H