blob: a8ec18c74040b73ac30e60a1943276ccd4121769 [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
James Dennett2a4d13c2012-06-15 07:13:21 +00001385 /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
John McCalld9bb7432011-07-27 21:50:02 +00001386 ///
1387 /// By default, performs semantic analysis to build the new statement.
1388 /// Subclasses may override this routine to provide different behavior.
1389 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1390 Expr *object) {
1391 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1392 }
1393
James Dennett2a4d13c2012-06-15 07:13:21 +00001394 /// \brief Build a new Objective-C \@synchronized statement.
Douglas Gregor6148de72010-04-22 22:01:21 +00001395 ///
Douglas Gregor6148de72010-04-22 22:01:21 +00001396 /// By default, performs semantic analysis to build the new statement.
1397 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001398 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCalld9bb7432011-07-27 21:50:02 +00001399 Expr *Object, Stmt *Body) {
1400 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor6148de72010-04-22 22:01:21 +00001401 }
Douglas Gregorf68a5082010-04-22 23:10:45 +00001402
James Dennett2a4d13c2012-06-15 07:13:21 +00001403 /// \brief Build a new Objective-C \@autoreleasepool statement.
John McCall31168b02011-06-15 23:02:42 +00001404 ///
1405 /// By default, performs semantic analysis to build the new statement.
1406 /// Subclasses may override this routine to provide different behavior.
1407 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1408 Stmt *Body) {
1409 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1410 }
John McCall53848232011-07-27 01:07:15 +00001411
Douglas Gregorf68a5082010-04-22 23:10:45 +00001412 /// \brief Build a new Objective-C fast enumeration statement.
1413 ///
1414 /// By default, performs semantic analysis to build the new statement.
1415 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001416 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001417 Stmt *Element,
1418 Expr *Collection,
1419 SourceLocation RParenLoc,
1420 Stmt *Body) {
Sam Panzer2c4ca0f2012-08-16 21:47:25 +00001421 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001422 Element,
John McCallb268a282010-08-23 23:25:46 +00001423 Collection,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001424 RParenLoc);
1425 if (ForEachStmt.isInvalid())
1426 return StmtError();
1427
1428 return getSema().FinishObjCForCollectionStmt(ForEachStmt.take(), Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +00001429 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001430
Douglas Gregorebe10102009-08-20 07:17:43 +00001431 /// \brief Build a new C++ exception declaration.
1432 ///
1433 /// By default, performs semantic analysis to build the new decaration.
1434 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaradff19302011-03-08 08:55:46 +00001435 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +00001436 TypeSourceInfo *Declarator,
Abramo Bagnaradff19302011-03-08 08:55:46 +00001437 SourceLocation StartLoc,
1438 SourceLocation IdLoc,
1439 IdentifierInfo *Id) {
Douglas Gregor40965fa2011-04-14 22:32:28 +00001440 VarDecl *Var = getSema().BuildExceptionDeclaration(0, Declarator,
1441 StartLoc, IdLoc, Id);
1442 if (Var)
1443 getSema().CurContext->addDecl(Var);
1444 return Var;
Douglas Gregorebe10102009-08-20 07:17:43 +00001445 }
1446
1447 /// \brief Build a new C++ catch statement.
1448 ///
1449 /// By default, performs semantic analysis to build the new statement.
1450 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001451 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001452 VarDecl *ExceptionDecl,
1453 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00001454 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1455 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00001456 }
Mike Stump11289f42009-09-09 15:08:12 +00001457
Douglas Gregorebe10102009-08-20 07:17:43 +00001458 /// \brief Build a new C++ try statement.
1459 ///
1460 /// By default, performs semantic analysis to build the new statement.
1461 /// Subclasses may override this routine to provide different behavior.
Robert Wilhelmcafda822013-08-22 09:20:03 +00001462 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock,
1463 ArrayRef<Stmt *> Handlers) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001464 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00001465 }
Mike Stump11289f42009-09-09 15:08:12 +00001466
Richard Smith02e85f32011-04-14 22:09:26 +00001467 /// \brief Build a new C++0x range-based for statement.
1468 ///
1469 /// By default, performs semantic analysis to build the new statement.
1470 /// Subclasses may override this routine to provide different behavior.
1471 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1472 SourceLocation ColonLoc,
1473 Stmt *Range, Stmt *BeginEnd,
1474 Expr *Cond, Expr *Inc,
1475 Stmt *LoopVar,
1476 SourceLocation RParenLoc) {
Douglas Gregorf7106af2013-04-08 18:40:13 +00001477 // If we've just learned that the range is actually an Objective-C
1478 // collection, treat this as an Objective-C fast enumeration loop.
1479 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
1480 if (RangeStmt->isSingleDecl()) {
1481 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
Douglas Gregor39aaeef2013-05-02 18:35:56 +00001482 if (RangeVar->isInvalidDecl())
1483 return StmtError();
1484
Douglas Gregorf7106af2013-04-08 18:40:13 +00001485 Expr *RangeExpr = RangeVar->getInit();
1486 if (!RangeExpr->isTypeDependent() &&
1487 RangeExpr->getType()->isObjCObjectPointerType())
1488 return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, RangeExpr,
1489 RParenLoc);
1490 }
1491 }
1492 }
1493
Richard Smith02e85f32011-04-14 22:09:26 +00001494 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
Richard Smitha05b3b52012-09-20 21:52:32 +00001495 Cond, Inc, LoopVar, RParenLoc,
1496 Sema::BFRK_Rebuild);
Richard Smith02e85f32011-04-14 22:09:26 +00001497 }
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001498
1499 /// \brief Build a new C++0x range-based for statement.
1500 ///
1501 /// By default, performs semantic analysis to build the new statement.
1502 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00001503 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001504 bool IsIfExists,
1505 NestedNameSpecifierLoc QualifierLoc,
1506 DeclarationNameInfo NameInfo,
1507 Stmt *Nested) {
1508 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1509 QualifierLoc, NameInfo, Nested);
1510 }
1511
Richard Smith02e85f32011-04-14 22:09:26 +00001512 /// \brief Attach body to a C++0x range-based for statement.
1513 ///
1514 /// By default, performs semantic analysis to finish the new statement.
1515 /// Subclasses may override this routine to provide different behavior.
1516 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1517 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1518 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001519
David Majnemerfad8f482013-10-15 09:33:02 +00001520 StmtResult RebuildSEHTryStmt(bool IsCXXTry, SourceLocation TryLoc,
1521 Stmt *TryBlock, Stmt *Handler) {
1522 return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +00001523 }
1524
David Majnemerfad8f482013-10-15 09:33:02 +00001525 StmtResult RebuildSEHExceptStmt(SourceLocation Loc, Expr *FilterExpr,
John Wiegley1c0675e2011-04-28 01:08:34 +00001526 Stmt *Block) {
David Majnemerfad8f482013-10-15 09:33:02 +00001527 return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001528 }
1529
David Majnemerfad8f482013-10-15 09:33:02 +00001530 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, Stmt *Block) {
1531 return getSema().ActOnSEHFinallyBlock(Loc, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001532 }
1533
Douglas Gregora16548e2009-08-11 05:31:07 +00001534 /// \brief Build a new expression that references a declaration.
1535 ///
1536 /// By default, performs semantic analysis to build the new expression.
1537 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001538 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00001539 LookupResult &R,
1540 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00001541 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1542 }
1543
1544
1545 /// \brief Build a new expression that references a declaration.
1546 ///
1547 /// By default, performs semantic analysis to build the new expression.
1548 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorea972d32011-02-28 21:54:11 +00001549 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001550 ValueDecl *VD,
1551 const DeclarationNameInfo &NameInfo,
1552 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001553 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001554 SS.Adopt(QualifierLoc);
John McCallce546572009-12-08 09:08:17 +00001555
1556 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001557
1558 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001559 }
Mike Stump11289f42009-09-09 15:08:12 +00001560
Douglas Gregora16548e2009-08-11 05:31:07 +00001561 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001562 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001563 /// By default, performs semantic analysis to build the new expression.
1564 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001565 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00001566 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00001567 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001568 }
1569
Douglas Gregorad8a3362009-09-04 17:36:40 +00001570 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001571 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001572 /// By default, performs semantic analysis to build the new expression.
1573 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001574 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora6ce6082011-02-25 18:19:59 +00001575 SourceLocation OperatorLoc,
1576 bool isArrow,
1577 CXXScopeSpec &SS,
1578 TypeSourceInfo *ScopeType,
1579 SourceLocation CCLoc,
1580 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001581 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001582
Douglas Gregora16548e2009-08-11 05:31:07 +00001583 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001584 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001585 /// By default, performs semantic analysis to build the new expression.
1586 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001587 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001588 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001589 Expr *SubExpr) {
1590 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001591 }
Mike Stump11289f42009-09-09 15:08:12 +00001592
Douglas Gregor882211c2010-04-28 22:16:22 +00001593 /// \brief Build a new builtin offsetof expression.
1594 ///
1595 /// By default, performs semantic analysis to build the new expression.
1596 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001597 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor882211c2010-04-28 22:16:22 +00001598 TypeSourceInfo *Type,
John McCallfaf5fb42010-08-26 23:41:50 +00001599 Sema::OffsetOfComponent *Components,
Douglas Gregor882211c2010-04-28 22:16:22 +00001600 unsigned NumComponents,
1601 SourceLocation RParenLoc) {
1602 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1603 NumComponents, RParenLoc);
1604 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001605
1606 /// \brief Build a new sizeof, alignof or vec_step expression with a
Peter Collingbournee190dee2011-03-11 19:24:49 +00001607 /// type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001608 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001609 /// By default, performs semantic analysis to build the new expression.
1610 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001611 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1612 SourceLocation OpLoc,
1613 UnaryExprOrTypeTrait ExprKind,
1614 SourceRange R) {
1615 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001616 }
1617
Peter Collingbournee190dee2011-03-11 19:24:49 +00001618 /// \brief Build a new sizeof, alignof or vec step expression with an
1619 /// expression argument.
Mike Stump11289f42009-09-09 15:08:12 +00001620 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001621 /// By default, performs semantic analysis to build the new expression.
1622 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001623 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1624 UnaryExprOrTypeTrait ExprKind,
1625 SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00001626 ExprResult Result
Chandler Carrutha923fb22011-05-29 07:32:14 +00001627 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregora16548e2009-08-11 05:31:07 +00001628 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001629 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001630
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001631 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001632 }
Mike Stump11289f42009-09-09 15:08:12 +00001633
Douglas Gregora16548e2009-08-11 05:31:07 +00001634 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001635 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001636 /// By default, performs semantic analysis to build the new expression.
1637 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001638 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001639 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00001640 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001641 SourceLocation RBracketLoc) {
John McCallb268a282010-08-23 23:25:46 +00001642 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1643 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001644 RBracketLoc);
1645 }
1646
1647 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00001648 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001649 /// By default, performs semantic analysis to build the new expression.
1650 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001651 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001652 MultiExprArg Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00001653 SourceLocation RParenLoc,
1654 Expr *ExecConfig = 0) {
John McCallb268a282010-08-23 23:25:46 +00001655 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001656 Args, RParenLoc, ExecConfig);
Douglas Gregora16548e2009-08-11 05:31:07 +00001657 }
1658
1659 /// \brief Build a new member access 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 RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001664 bool isArrow,
Douglas Gregorea972d32011-02-28 21:54:11 +00001665 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001666 SourceLocation TemplateKWLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001667 const DeclarationNameInfo &MemberNameInfo,
1668 ValueDecl *Member,
1669 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001670 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00001671 NamedDecl *FirstQualifierInScope) {
Richard Smithcab9a7d2011-10-26 19:06:56 +00001672 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
1673 isArrow);
Anders Carlsson5da84842009-09-01 04:26:58 +00001674 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00001675 // We have a reference to an unnamed field. This is always the
1676 // base of an anonymous struct/union member access, i.e. the
1677 // field is always of record type.
Douglas Gregorea972d32011-02-28 21:54:11 +00001678 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCall7decc9e2010-11-18 06:31:45 +00001679 assert(Member->getType()->isRecordType() &&
1680 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00001681
Richard Smithcab9a7d2011-10-26 19:06:56 +00001682 BaseResult =
1683 getSema().PerformObjectMemberConversion(BaseResult.take(),
John Wiegley01296292011-04-08 18:41:53 +00001684 QualifierLoc.getNestedNameSpecifier(),
1685 FoundDecl, Member);
1686 if (BaseResult.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001687 return ExprError();
John Wiegley01296292011-04-08 18:41:53 +00001688 Base = BaseResult.take();
John McCall7decc9e2010-11-18 06:31:45 +00001689 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump11289f42009-09-09 15:08:12 +00001690 MemberExpr *ME =
John McCallb268a282010-08-23 23:25:46 +00001691 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001692 Member, MemberNameInfo,
John McCall7decc9e2010-11-18 06:31:45 +00001693 cast<FieldDecl>(Member)->getType(),
1694 VK, OK_Ordinary);
Anders Carlsson5da84842009-09-01 04:26:58 +00001695 return getSema().Owned(ME);
1696 }
Mike Stump11289f42009-09-09 15:08:12 +00001697
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001698 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001699 SS.Adopt(QualifierLoc);
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001700
John Wiegley01296292011-04-08 18:41:53 +00001701 Base = BaseResult.take();
John McCallb268a282010-08-23 23:25:46 +00001702 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00001703
John McCall16df1e52010-03-30 21:47:33 +00001704 // FIXME: this involves duplicating earlier analysis in a lot of
1705 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001706 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001707 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001708 R.resolveKind();
1709
John McCallb268a282010-08-23 23:25:46 +00001710 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001711 SS, TemplateKWLoc,
1712 FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001713 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001714 }
Mike Stump11289f42009-09-09 15:08:12 +00001715
Douglas Gregora16548e2009-08-11 05:31:07 +00001716 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001717 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001718 /// By default, performs semantic analysis to build the new expression.
1719 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001720 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001721 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001722 Expr *LHS, Expr *RHS) {
1723 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001724 }
1725
1726 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001727 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001728 /// By default, performs semantic analysis to build the new expression.
1729 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001730 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCallc07a0c72011-02-17 10:25:35 +00001731 SourceLocation QuestionLoc,
1732 Expr *LHS,
1733 SourceLocation ColonLoc,
1734 Expr *RHS) {
John McCallb268a282010-08-23 23:25:46 +00001735 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1736 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001737 }
1738
Douglas Gregora16548e2009-08-11 05:31:07 +00001739 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001740 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001741 /// By default, performs semantic analysis to build the new expression.
1742 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001743 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00001744 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001745 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001746 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001747 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001748 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001749 }
Mike Stump11289f42009-09-09 15:08:12 +00001750
Douglas Gregora16548e2009-08-11 05:31:07 +00001751 /// \brief Build a new compound literal 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 RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001756 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001757 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001758 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001759 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001760 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001761 }
Mike Stump11289f42009-09-09 15:08:12 +00001762
Douglas Gregora16548e2009-08-11 05:31:07 +00001763 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001764 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001765 /// By default, performs semantic analysis to build the new expression.
1766 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001767 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001768 SourceLocation OpLoc,
1769 SourceLocation AccessorLoc,
1770 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001771
John McCall10eae182009-11-30 22:42:35 +00001772 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001773 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00001774 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00001775 OpLoc, /*IsArrow*/ false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001776 SS, SourceLocation(),
1777 /*FirstQualifierInScope*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001778 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00001779 /* TemplateArgs */ 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00001780 }
Mike Stump11289f42009-09-09 15:08:12 +00001781
Douglas Gregora16548e2009-08-11 05:31:07 +00001782 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001783 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001784 /// By default, performs semantic analysis to build the new expression.
1785 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001786 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCall542e7c62011-07-06 07:30:07 +00001787 MultiExprArg Inits,
1788 SourceLocation RBraceLoc,
1789 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00001790 ExprResult Result
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001791 = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
Douglas Gregord3d93062009-11-09 17:16:50 +00001792 if (Result.isInvalid() || ResultTy->isDependentType())
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001793 return Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00001794
Douglas Gregord3d93062009-11-09 17:16:50 +00001795 // Patch in the result type we were given, which may have been computed
1796 // when the initial InitListExpr was built.
1797 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1798 ILE->setType(ResultTy);
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001799 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001800 }
Mike Stump11289f42009-09-09 15:08:12 +00001801
Douglas Gregora16548e2009-08-11 05:31:07 +00001802 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001803 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001804 /// By default, performs semantic analysis to build the new expression.
1805 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001806 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00001807 MultiExprArg ArrayExprs,
1808 SourceLocation EqualOrColonLoc,
1809 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001810 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00001811 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001812 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001813 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001814 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001815 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001816
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001817 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001818 }
Mike Stump11289f42009-09-09 15:08:12 +00001819
Douglas Gregora16548e2009-08-11 05:31:07 +00001820 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001821 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001822 /// By default, builds the implicit value initialization without performing
1823 /// any semantic analysis. Subclasses may override this routine to provide
1824 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001825 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001826 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1827 }
Mike Stump11289f42009-09-09 15:08:12 +00001828
Douglas Gregora16548e2009-08-11 05:31:07 +00001829 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001830 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001831 /// By default, performs semantic analysis to build the new expression.
1832 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001833 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001834 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001835 SourceLocation RParenLoc) {
1836 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001837 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001838 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001839 }
1840
1841 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001842 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001843 /// By default, performs semantic analysis to build the new expression.
1844 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001845 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redla9351792012-02-11 23:51:47 +00001846 MultiExprArg SubExprs,
1847 SourceLocation RParenLoc) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001848 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001849 }
Mike Stump11289f42009-09-09 15:08:12 +00001850
Douglas Gregora16548e2009-08-11 05:31:07 +00001851 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001852 ///
1853 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00001854 /// rather than attempting to map the label statement itself.
1855 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001856 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001857 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001858 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregora16548e2009-08-11 05:31:07 +00001859 }
Mike Stump11289f42009-09-09 15:08:12 +00001860
Douglas Gregora16548e2009-08-11 05:31:07 +00001861 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00001862 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001863 /// By default, performs semantic analysis to build the new expression.
1864 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001865 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001866 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00001867 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001868 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001869 }
Mike Stump11289f42009-09-09 15:08:12 +00001870
Douglas Gregora16548e2009-08-11 05:31:07 +00001871 /// \brief Build a new __builtin_choose_expr expression.
1872 ///
1873 /// By default, performs semantic analysis to build the new expression.
1874 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001875 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001876 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001877 SourceLocation RParenLoc) {
1878 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001879 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001880 RParenLoc);
1881 }
Mike Stump11289f42009-09-09 15:08:12 +00001882
Peter Collingbourne91147592011-04-15 00:35:48 +00001883 /// \brief Build a new generic selection expression.
1884 ///
1885 /// By default, performs semantic analysis to build the new expression.
1886 /// Subclasses may override this routine to provide different behavior.
1887 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
1888 SourceLocation DefaultLoc,
1889 SourceLocation RParenLoc,
1890 Expr *ControllingExpr,
Dmitri Gribenko82360372013-05-10 13:06:58 +00001891 ArrayRef<TypeSourceInfo *> Types,
1892 ArrayRef<Expr *> Exprs) {
Peter Collingbourne91147592011-04-15 00:35:48 +00001893 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
Dmitri Gribenko82360372013-05-10 13:06:58 +00001894 ControllingExpr, Types, Exprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00001895 }
1896
Douglas Gregora16548e2009-08-11 05:31:07 +00001897 /// \brief Build a new overloaded operator call expression.
1898 ///
1899 /// By default, performs semantic analysis to build the new expression.
1900 /// The semantic analysis provides the behavior of template instantiation,
1901 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00001902 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00001903 /// argument-dependent lookup, etc. Subclasses may override this routine to
1904 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001905 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00001906 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00001907 Expr *Callee,
1908 Expr *First,
1909 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00001910
1911 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00001912 /// reinterpret_cast.
1913 ///
1914 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00001915 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00001916 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001917 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001918 Stmt::StmtClass Class,
1919 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001920 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001921 SourceLocation RAngleLoc,
1922 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001923 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001924 SourceLocation RParenLoc) {
1925 switch (Class) {
1926 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001927 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001928 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001929 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001930
1931 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001932 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001933 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001934 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001935
Douglas Gregora16548e2009-08-11 05:31:07 +00001936 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001937 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001938 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001939 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001940 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001941
Douglas Gregora16548e2009-08-11 05:31:07 +00001942 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001943 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001944 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001945 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001946
Douglas Gregora16548e2009-08-11 05:31:07 +00001947 default:
David Blaikie83d382b2011-09-23 05:06:16 +00001948 llvm_unreachable("Invalid C++ named cast");
Douglas Gregora16548e2009-08-11 05:31:07 +00001949 }
Douglas Gregora16548e2009-08-11 05:31:07 +00001950 }
Mike Stump11289f42009-09-09 15:08:12 +00001951
Douglas Gregora16548e2009-08-11 05:31:07 +00001952 /// \brief Build a new C++ static_cast expression.
1953 ///
1954 /// By default, performs semantic analysis to build the new expression.
1955 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001956 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001957 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001958 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001959 SourceLocation RAngleLoc,
1960 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001961 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001962 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001963 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00001964 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001965 SourceRange(LAngleLoc, RAngleLoc),
1966 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001967 }
1968
1969 /// \brief Build a new C++ dynamic_cast expression.
1970 ///
1971 /// By default, performs semantic analysis to build the new expression.
1972 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001973 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001974 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001975 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001976 SourceLocation RAngleLoc,
1977 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001978 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001979 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001980 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00001981 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001982 SourceRange(LAngleLoc, RAngleLoc),
1983 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001984 }
1985
1986 /// \brief Build a new C++ reinterpret_cast expression.
1987 ///
1988 /// By default, performs semantic analysis to build the new expression.
1989 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001990 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001991 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001992 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001993 SourceLocation RAngleLoc,
1994 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001995 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001996 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001997 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00001998 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001999 SourceRange(LAngleLoc, RAngleLoc),
2000 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002001 }
2002
2003 /// \brief Build a new C++ const_cast expression.
2004 ///
2005 /// By default, performs semantic analysis to build the new expression.
2006 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002007 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002008 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002009 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002010 SourceLocation RAngleLoc,
2011 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002012 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002013 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002014 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00002015 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002016 SourceRange(LAngleLoc, RAngleLoc),
2017 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002018 }
Mike Stump11289f42009-09-09 15:08:12 +00002019
Douglas Gregora16548e2009-08-11 05:31:07 +00002020 /// \brief Build a new C++ functional-style cast expression.
2021 ///
2022 /// By default, performs semantic analysis to build the new expression.
2023 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002024 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
2025 SourceLocation LParenLoc,
2026 Expr *Sub,
2027 SourceLocation RParenLoc) {
2028 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00002029 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00002030 RParenLoc);
2031 }
Mike Stump11289f42009-09-09 15:08:12 +00002032
Douglas Gregora16548e2009-08-11 05:31:07 +00002033 /// \brief Build a new C++ typeid(type) expression.
2034 ///
2035 /// By default, performs semantic analysis to build the new expression.
2036 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002037 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002038 SourceLocation TypeidLoc,
2039 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002040 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002041 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002042 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002043 }
Mike Stump11289f42009-09-09 15:08:12 +00002044
Francois Pichet9f4f2072010-09-08 12:20:18 +00002045
Douglas Gregora16548e2009-08-11 05:31:07 +00002046 /// \brief Build a new C++ typeid(expr) expression.
2047 ///
2048 /// By default, performs semantic analysis to build the new expression.
2049 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002050 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002051 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00002052 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002053 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002054 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002055 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002056 }
2057
Francois Pichet9f4f2072010-09-08 12:20:18 +00002058 /// \brief Build a new C++ __uuidof(type) expression.
2059 ///
2060 /// By default, performs semantic analysis to build the new expression.
2061 /// Subclasses may override this routine to provide different behavior.
2062 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2063 SourceLocation TypeidLoc,
2064 TypeSourceInfo *Operand,
2065 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002066 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
Francois Pichet9f4f2072010-09-08 12:20:18 +00002067 RParenLoc);
2068 }
2069
2070 /// \brief Build a new C++ __uuidof(expr) expression.
2071 ///
2072 /// By default, performs semantic analysis to build the new expression.
2073 /// Subclasses may override this routine to provide different behavior.
2074 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2075 SourceLocation TypeidLoc,
2076 Expr *Operand,
2077 SourceLocation RParenLoc) {
2078 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
2079 RParenLoc);
2080 }
2081
Douglas Gregora16548e2009-08-11 05:31:07 +00002082 /// \brief Build a new C++ "this" expression.
2083 ///
2084 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00002085 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00002086 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002087 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00002088 QualType ThisType,
2089 bool isImplicit) {
Eli Friedman20139d32012-01-11 02:36:31 +00002090 getSema().CheckCXXThisCapture(ThisLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002091 return getSema().Owned(
Douglas Gregorb15af892010-01-07 23:12:05 +00002092 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
2093 isImplicit));
Douglas Gregora16548e2009-08-11 05:31:07 +00002094 }
2095
2096 /// \brief Build a new C++ throw expression.
2097 ///
2098 /// By default, performs semantic analysis to build the new expression.
2099 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor53e191ed2011-07-06 22:04:06 +00002100 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
2101 bool IsThrownVariableInScope) {
2102 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00002103 }
2104
2105 /// \brief Build a new C++ default-argument expression.
2106 ///
2107 /// By default, builds a new default-argument expression, which does not
2108 /// require any semantic analysis. Subclasses may override this routine to
2109 /// provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002110 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00002111 ParmVarDecl *Param) {
2112 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
2113 Param));
Douglas Gregora16548e2009-08-11 05:31:07 +00002114 }
2115
Richard Smith852c9db2013-04-20 22:23:05 +00002116 /// \brief Build a new C++11 default-initialization expression.
2117 ///
2118 /// By default, builds a new default field initialization expression, which
2119 /// does not require any semantic analysis. Subclasses may override this
2120 /// routine to provide different behavior.
2121 ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc,
2122 FieldDecl *Field) {
2123 return getSema().Owned(CXXDefaultInitExpr::Create(getSema().Context, Loc,
2124 Field));
2125 }
2126
Douglas Gregora16548e2009-08-11 05:31:07 +00002127 /// \brief Build a new C++ zero-initialization expression.
2128 ///
2129 /// By default, performs semantic analysis to build the new expression.
2130 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002131 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
2132 SourceLocation LParenLoc,
2133 SourceLocation RParenLoc) {
2134 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002135 None, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002136 }
Mike Stump11289f42009-09-09 15:08:12 +00002137
Douglas Gregora16548e2009-08-11 05:31:07 +00002138 /// \brief Build a new C++ "new" expression.
2139 ///
2140 /// By default, performs semantic analysis to build the new expression.
2141 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002142 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002143 bool UseGlobal,
2144 SourceLocation PlacementLParen,
2145 MultiExprArg PlacementArgs,
2146 SourceLocation PlacementRParen,
2147 SourceRange TypeIdParens,
2148 QualType AllocatedType,
2149 TypeSourceInfo *AllocatedTypeInfo,
2150 Expr *ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002151 SourceRange DirectInitRange,
2152 Expr *Initializer) {
Mike Stump11289f42009-09-09 15:08:12 +00002153 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00002154 PlacementLParen,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002155 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00002156 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00002157 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002158 AllocatedType,
2159 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00002160 ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002161 DirectInitRange,
2162 Initializer);
Douglas Gregora16548e2009-08-11 05:31:07 +00002163 }
Mike Stump11289f42009-09-09 15:08:12 +00002164
Douglas Gregora16548e2009-08-11 05:31:07 +00002165 /// \brief Build a new C++ "delete" expression.
2166 ///
2167 /// By default, performs semantic analysis to build the new expression.
2168 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002169 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002170 bool IsGlobalDelete,
2171 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002172 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002173 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002174 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00002175 }
Mike Stump11289f42009-09-09 15:08:12 +00002176
Douglas Gregor29c42f22012-02-24 07:38:34 +00002177 /// \brief Build a new type trait expression.
2178 ///
2179 /// By default, performs semantic analysis to build the new expression.
2180 /// Subclasses may override this routine to provide different behavior.
2181 ExprResult RebuildTypeTrait(TypeTrait Trait,
2182 SourceLocation StartLoc,
2183 ArrayRef<TypeSourceInfo *> Args,
2184 SourceLocation RParenLoc) {
2185 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2186 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002187
John Wiegley6242b6a2011-04-28 00:16:57 +00002188 /// \brief Build a new array type trait expression.
2189 ///
2190 /// By default, performs semantic analysis to build the new expression.
2191 /// Subclasses may override this routine to provide different behavior.
2192 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2193 SourceLocation StartLoc,
2194 TypeSourceInfo *TSInfo,
2195 Expr *DimExpr,
2196 SourceLocation RParenLoc) {
2197 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2198 }
2199
John Wiegleyf9f65842011-04-25 06:54:41 +00002200 /// \brief Build a new expression trait expression.
2201 ///
2202 /// By default, performs semantic analysis to build the new expression.
2203 /// Subclasses may override this routine to provide different behavior.
2204 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2205 SourceLocation StartLoc,
2206 Expr *Queried,
2207 SourceLocation RParenLoc) {
2208 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2209 }
2210
Mike Stump11289f42009-09-09 15:08:12 +00002211 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00002212 /// expression.
2213 ///
2214 /// By default, performs semantic analysis to build the new expression.
2215 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002216 ExprResult RebuildDependentScopeDeclRefExpr(
2217 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002218 SourceLocation TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002219 const DeclarationNameInfo &NameInfo,
Richard Smithdb2630f2012-10-21 03:28:35 +00002220 const TemplateArgumentListInfo *TemplateArgs,
2221 bool IsAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002222 CXXScopeSpec SS;
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002223 SS.Adopt(QualifierLoc);
John McCalle66edc12009-11-24 19:00:30 +00002224
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002225 if (TemplateArgs || TemplateKWLoc.isValid())
Abramo Bagnara7945c982012-01-27 09:46:47 +00002226 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002227 NameInfo, TemplateArgs);
John McCalle66edc12009-11-24 19:00:30 +00002228
Richard Smithdb2630f2012-10-21 03:28:35 +00002229 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo,
2230 IsAddressOfOperand);
Douglas Gregora16548e2009-08-11 05:31:07 +00002231 }
2232
2233 /// \brief Build a new template-id expression.
2234 ///
2235 /// By default, performs semantic analysis to build the new expression.
2236 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002237 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002238 SourceLocation TemplateKWLoc,
2239 LookupResult &R,
2240 bool RequiresADL,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002241 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnara7945c982012-01-27 09:46:47 +00002242 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2243 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002244 }
2245
2246 /// \brief Build a new object-construction expression.
2247 ///
2248 /// By default, performs semantic analysis to build the new expression.
2249 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002250 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002251 SourceLocation Loc,
2252 CXXConstructorDecl *Constructor,
2253 bool IsElidable,
2254 MultiExprArg Args,
2255 bool HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002256 bool ListInitialization,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002257 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00002258 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002259 SourceRange ParenRange) {
Benjamin Kramerf0623432012-08-23 22:51:59 +00002260 SmallVector<Expr*, 8> ConvertedArgs;
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002261 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00002262 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00002263 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002264
Douglas Gregordb121ba2009-12-14 16:27:04 +00002265 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002266 ConvertedArgs,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002267 HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002268 ListInitialization,
Chandler Carruth01718152010-10-25 08:47:36 +00002269 RequiresZeroInit, ConstructKind,
2270 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00002271 }
2272
2273 /// \brief Build a new object-construction expression.
2274 ///
2275 /// By default, performs semantic analysis to build the new expression.
2276 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002277 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2278 SourceLocation LParenLoc,
2279 MultiExprArg Args,
2280 SourceLocation RParenLoc) {
2281 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002282 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002283 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002284 RParenLoc);
2285 }
2286
2287 /// \brief Build a new object-construction expression.
2288 ///
2289 /// By default, performs semantic analysis to build the new expression.
2290 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002291 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2292 SourceLocation LParenLoc,
2293 MultiExprArg Args,
2294 SourceLocation RParenLoc) {
2295 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002296 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002297 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002298 RParenLoc);
2299 }
Mike Stump11289f42009-09-09 15:08:12 +00002300
Douglas Gregora16548e2009-08-11 05:31:07 +00002301 /// \brief Build a new member reference expression.
2302 ///
2303 /// By default, performs semantic analysis to build the new expression.
2304 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002305 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregore16af532011-02-28 18:50:33 +00002306 QualType BaseType,
2307 bool IsArrow,
2308 SourceLocation OperatorLoc,
2309 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002310 SourceLocation TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00002311 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002312 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00002313 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002314 CXXScopeSpec SS;
Douglas Gregore16af532011-02-28 18:50:33 +00002315 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002316
John McCallb268a282010-08-23 23:25:46 +00002317 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002318 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002319 SS, TemplateKWLoc,
2320 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002321 MemberNameInfo,
2322 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002323 }
2324
John McCall10eae182009-11-30 22:42:35 +00002325 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00002326 ///
2327 /// By default, performs semantic analysis to build the new expression.
2328 /// Subclasses may override this routine to provide different behavior.
Richard Smithcab9a7d2011-10-26 19:06:56 +00002329 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2330 SourceLocation OperatorLoc,
2331 bool IsArrow,
2332 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002333 SourceLocation TemplateKWLoc,
Richard Smithcab9a7d2011-10-26 19:06:56 +00002334 NamedDecl *FirstQualifierInScope,
2335 LookupResult &R,
John McCall10eae182009-11-30 22:42:35 +00002336 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00002337 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00002338 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002339
John McCallb268a282010-08-23 23:25:46 +00002340 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002341 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002342 SS, TemplateKWLoc,
2343 FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00002344 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00002345 }
Mike Stump11289f42009-09-09 15:08:12 +00002346
Sebastian Redl4202c0f2010-09-10 20:55:43 +00002347 /// \brief Build a new noexcept expression.
2348 ///
2349 /// By default, performs semantic analysis to build the new expression.
2350 /// Subclasses may override this routine to provide different behavior.
2351 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2352 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2353 }
2354
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002355 /// \brief Build a new expression to compute the length of a parameter pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00002356 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2357 SourceLocation PackLoc,
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002358 SourceLocation RParenLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002359 Optional<unsigned> Length) {
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002360 if (Length)
Chad Rosier1dcde962012-08-08 18:46:20 +00002361 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2362 OperatorLoc, Pack, PackLoc,
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002363 RParenLoc, *Length);
Chad Rosier1dcde962012-08-08 18:46:20 +00002364
2365 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2366 OperatorLoc, Pack, PackLoc,
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002367 RParenLoc);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002368 }
Ted Kremeneke65b0862012-03-06 20:05:56 +00002369
Patrick Beard0caa3942012-04-19 00:25:12 +00002370 /// \brief Build a new Objective-C boxed expression.
2371 ///
2372 /// By default, performs semantic analysis to build the new expression.
2373 /// Subclasses may override this routine to provide different behavior.
2374 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2375 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2376 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002377
Ted Kremeneke65b0862012-03-06 20:05:56 +00002378 /// \brief Build a new Objective-C array literal.
2379 ///
2380 /// By default, performs semantic analysis to build the new expression.
2381 /// Subclasses may override this routine to provide different behavior.
2382 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2383 Expr **Elements, unsigned NumElements) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002384 return getSema().BuildObjCArrayLiteral(Range,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002385 MultiExprArg(Elements, NumElements));
2386 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002387
2388 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002389 Expr *Base, Expr *Key,
2390 ObjCMethodDecl *getterMethod,
2391 ObjCMethodDecl *setterMethod) {
2392 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2393 getterMethod, setterMethod);
2394 }
2395
2396 /// \brief Build a new Objective-C dictionary literal.
2397 ///
2398 /// By default, performs semantic analysis to build the new expression.
2399 /// Subclasses may override this routine to provide different behavior.
2400 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
2401 ObjCDictionaryElement *Elements,
2402 unsigned NumElements) {
2403 return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements);
2404 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002405
James Dennett2a4d13c2012-06-15 07:13:21 +00002406 /// \brief Build a new Objective-C \@encode expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002407 ///
2408 /// By default, performs semantic analysis to build the new expression.
2409 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002410 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00002411 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002412 SourceLocation RParenLoc) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00002413 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002414 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00002415 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002416
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002417 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00002418 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002419 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002420 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002421 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002422 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002423 MultiExprArg Args,
2424 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002425 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2426 ReceiverTypeInfo->getType(),
2427 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002428 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002429 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002430 }
2431
2432 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00002433 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002434 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002435 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002436 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002437 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002438 MultiExprArg Args,
2439 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00002440 return SemaRef.BuildInstanceMessage(Receiver,
2441 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002442 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002443 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002444 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002445 }
2446
Douglas Gregord51d90d2010-04-26 20:11:03 +00002447 /// \brief Build a new Objective-C ivar reference expression.
2448 ///
2449 /// By default, performs semantic analysis to build the new expression.
2450 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002451 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002452 SourceLocation IvarLoc,
2453 bool IsArrow, bool IsFreeIvar) {
2454 // FIXME: We lose track of the IsFreeIvar bit.
2455 CXXScopeSpec SS;
John Wiegley01296292011-04-08 18:41:53 +00002456 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002457 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2458 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00002459 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002460 /*FIME:*/IvarLoc,
John McCall48871652010-08-21 09:40:31 +00002461 SS, 0,
John McCalle9cccd82010-06-16 08:42:20 +00002462 false);
John Wiegley01296292011-04-08 18:41:53 +00002463 if (Result.isInvalid() || Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002464 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002465
Douglas Gregord51d90d2010-04-26 20:11:03 +00002466 if (Result.get())
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002467 return Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00002468
John Wiegley01296292011-04-08 18:41:53 +00002469 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Abramo Bagnara7945c982012-01-27 09:46:47 +00002470 /*FIXME:*/IvarLoc, IsArrow,
2471 SS, SourceLocation(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00002472 /*FirstQualifierInScope=*/0,
Chad Rosier1dcde962012-08-08 18:46:20 +00002473 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002474 /*TemplateArgs=*/0);
2475 }
Douglas Gregor9faee212010-04-26 20:47:02 +00002476
2477 /// \brief Build a new Objective-C property reference expression.
2478 ///
2479 /// By default, performs semantic analysis to build the new expression.
2480 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002481 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall526ab472011-10-25 17:37:35 +00002482 ObjCPropertyDecl *Property,
2483 SourceLocation PropertyLoc) {
Douglas Gregor9faee212010-04-26 20:47:02 +00002484 CXXScopeSpec SS;
John Wiegley01296292011-04-08 18:41:53 +00002485 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregor9faee212010-04-26 20:47:02 +00002486 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2487 Sema::LookupMemberName);
2488 bool IsArrow = false;
John McCalldadc5752010-08-24 06:29:42 +00002489 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregor9faee212010-04-26 20:47:02 +00002490 /*FIME:*/PropertyLoc,
John McCall48871652010-08-21 09:40:31 +00002491 SS, 0, false);
John Wiegley01296292011-04-08 18:41:53 +00002492 if (Result.isInvalid() || Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002493 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002494
Douglas Gregor9faee212010-04-26 20:47:02 +00002495 if (Result.get())
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002496 return Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00002497
John Wiegley01296292011-04-08 18:41:53 +00002498 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Chad Rosier1dcde962012-08-08 18:46:20 +00002499 /*FIXME:*/PropertyLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002500 SS, SourceLocation(),
Douglas Gregor9faee212010-04-26 20:47:02 +00002501 /*FirstQualifierInScope=*/0,
Chad Rosier1dcde962012-08-08 18:46:20 +00002502 R,
Douglas Gregor9faee212010-04-26 20:47:02 +00002503 /*TemplateArgs=*/0);
2504 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002505
John McCallb7bd14f2010-12-02 01:19:52 +00002506 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002507 ///
2508 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00002509 /// Subclasses may override this routine to provide different behavior.
2510 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2511 ObjCMethodDecl *Getter,
2512 ObjCMethodDecl *Setter,
2513 SourceLocation PropertyLoc) {
2514 // Since these expressions can only be value-dependent, we do not
2515 // need to perform semantic analysis again.
2516 return Owned(
2517 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2518 VK_LValue, OK_ObjCProperty,
2519 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002520 }
2521
Douglas Gregord51d90d2010-04-26 20:11:03 +00002522 /// \brief Build a new Objective-C "isa" expression.
2523 ///
2524 /// By default, performs semantic analysis to build the new expression.
2525 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002526 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00002527 SourceLocation OpLoc,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002528 bool IsArrow) {
2529 CXXScopeSpec SS;
John Wiegley01296292011-04-08 18:41:53 +00002530 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002531 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2532 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00002533 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00002534 OpLoc,
John McCall48871652010-08-21 09:40:31 +00002535 SS, 0, false);
John Wiegley01296292011-04-08 18:41:53 +00002536 if (Result.isInvalid() || Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002537 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002538
Douglas Gregord51d90d2010-04-26 20:11:03 +00002539 if (Result.get())
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002540 return Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00002541
John Wiegley01296292011-04-08 18:41:53 +00002542 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00002543 OpLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002544 SS, SourceLocation(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00002545 /*FirstQualifierInScope=*/0,
Chad Rosier1dcde962012-08-08 18:46:20 +00002546 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002547 /*TemplateArgs=*/0);
2548 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002549
Douglas Gregora16548e2009-08-11 05:31:07 +00002550 /// \brief Build a new shuffle vector expression.
2551 ///
2552 /// By default, performs semantic analysis to build the new expression.
2553 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002554 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002555 MultiExprArg SubExprs,
2556 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002557 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00002558 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00002559 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2560 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2561 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
David Blaikieff7d47a2012-12-19 00:45:41 +00002562 assert(!Lookup.empty() && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00002563
Douglas Gregora16548e2009-08-11 05:31:07 +00002564 // Build a reference to the __builtin_shufflevector builtin
David Blaikieff7d47a2012-12-19 00:45:41 +00002565 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
Eli Friedman34866c72012-08-31 00:14:07 +00002566 Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false,
2567 SemaRef.Context.BuiltinFnTy,
2568 VK_RValue, BuiltinLoc);
2569 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
2570 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
2571 CK_BuiltinFnToFnPtr).take();
Mike Stump11289f42009-09-09 15:08:12 +00002572
2573 // Build the CallExpr
Alp Toker314cc812014-01-25 16:55:45 +00002574 ExprResult TheCall = SemaRef.Owned(new (SemaRef.Context) CallExpr(
2575 SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(),
2576 Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00002577
Douglas Gregora16548e2009-08-11 05:31:07 +00002578 // Type-check the __builtin_shufflevector expression.
John Wiegley01296292011-04-08 18:41:53 +00002579 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.take()));
Douglas Gregora16548e2009-08-11 05:31:07 +00002580 }
John McCall31f82722010-11-12 08:19:04 +00002581
Hal Finkelc4d7c822013-09-18 03:29:45 +00002582 /// \brief Build a new convert vector expression.
2583 ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc,
2584 Expr *SrcExpr, TypeSourceInfo *DstTInfo,
2585 SourceLocation RParenLoc) {
2586 return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo,
2587 BuiltinLoc, RParenLoc);
2588 }
2589
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002590 /// \brief Build a new template argument pack expansion.
2591 ///
2592 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00002593 /// for a template argument. Subclasses may override this routine to provide
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002594 /// different behavior.
2595 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002596 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002597 Optional<unsigned> NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002598 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00002599 case TemplateArgument::Expression: {
2600 ExprResult Result
Douglas Gregorb8840002011-01-14 21:20:45 +00002601 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2602 EllipsisLoc, NumExpansions);
Douglas Gregor98318c22011-01-03 21:37:45 +00002603 if (Result.isInvalid())
2604 return TemplateArgumentLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00002605
Douglas Gregor98318c22011-01-03 21:37:45 +00002606 return TemplateArgumentLoc(Result.get(), Result.get());
2607 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002608
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002609 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002610 return TemplateArgumentLoc(TemplateArgument(
2611 Pattern.getArgument().getAsTemplate(),
Douglas Gregore1d60df2011-01-14 23:41:42 +00002612 NumExpansions),
Douglas Gregor9d802122011-03-02 17:09:35 +00002613 Pattern.getTemplateQualifierLoc(),
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002614 Pattern.getTemplateNameLoc(),
2615 EllipsisLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00002616
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002617 case TemplateArgument::Null:
2618 case TemplateArgument::Integral:
2619 case TemplateArgument::Declaration:
2620 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002621 case TemplateArgument::TemplateExpansion:
Eli Friedmanb826a002012-09-26 02:36:12 +00002622 case TemplateArgument::NullPtr:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002623 llvm_unreachable("Pack expansion pattern has no parameter packs");
Chad Rosier1dcde962012-08-08 18:46:20 +00002624
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002625 case TemplateArgument::Type:
Chad Rosier1dcde962012-08-08 18:46:20 +00002626 if (TypeSourceInfo *Expansion
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002627 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002628 EllipsisLoc,
2629 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002630 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2631 Expansion);
2632 break;
2633 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002634
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002635 return TemplateArgumentLoc();
2636 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002637
Douglas Gregor968f23a2011-01-03 19:31:53 +00002638 /// \brief Build a new expression pack expansion.
2639 ///
2640 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00002641 /// for an expression. Subclasses may override this routine to provide
Douglas Gregor968f23a2011-01-03 19:31:53 +00002642 /// different behavior.
Douglas Gregorb8840002011-01-14 21:20:45 +00002643 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002644 Optional<unsigned> NumExpansions) {
Douglas Gregorb8840002011-01-14 21:20:45 +00002645 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002646 }
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002647
2648 /// \brief Build a new atomic operation expression.
2649 ///
2650 /// By default, performs semantic analysis to build the new expression.
2651 /// Subclasses may override this routine to provide different behavior.
2652 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2653 MultiExprArg SubExprs,
2654 QualType RetTy,
2655 AtomicExpr::AtomicOp Op,
2656 SourceLocation RParenLoc) {
2657 // Just create the expression; there is not any interesting semantic
2658 // analysis here because we can't actually build an AtomicExpr until
2659 // we are sure it is semantically sound.
Benjamin Kramerc215e762012-08-24 11:54:20 +00002660 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002661 RParenLoc);
2662 }
2663
John McCall31f82722010-11-12 08:19:04 +00002664private:
Douglas Gregor14454802011-02-25 02:25:35 +00002665 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2666 QualType ObjectType,
2667 NamedDecl *FirstQualifierInScope,
2668 CXXScopeSpec &SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00002669
2670 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2671 QualType ObjectType,
2672 NamedDecl *FirstQualifierInScope,
2673 CXXScopeSpec &SS);
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00002674
2675 TypeSourceInfo *TransformTSIInObjectScope(TypeLoc TL, QualType ObjectType,
2676 NamedDecl *FirstQualifierInScope,
2677 CXXScopeSpec &SS);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002678};
Douglas Gregora16548e2009-08-11 05:31:07 +00002679
Douglas Gregorebe10102009-08-20 07:17:43 +00002680template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002681StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002682 if (!S)
2683 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00002684
Douglas Gregorebe10102009-08-20 07:17:43 +00002685 switch (S->getStmtClass()) {
2686 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00002687
Douglas Gregorebe10102009-08-20 07:17:43 +00002688 // Transform individual statement nodes
2689#define STMT(Node, Parent) \
2690 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCallbd066782011-02-09 08:16:59 +00002691#define ABSTRACT_STMT(Node)
Douglas Gregorebe10102009-08-20 07:17:43 +00002692#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00002693#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002694
Douglas Gregorebe10102009-08-20 07:17:43 +00002695 // Transform expressions by calling TransformExpr.
2696#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00002697#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00002698#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00002699#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00002700 {
John McCalldadc5752010-08-24 06:29:42 +00002701 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00002702 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002703 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002704
Richard Smith945f8d32013-01-14 22:39:08 +00002705 return getSema().ActOnExprStmt(E);
Douglas Gregorebe10102009-08-20 07:17:43 +00002706 }
Mike Stump11289f42009-09-09 15:08:12 +00002707 }
2708
John McCallc3007a22010-10-26 07:05:15 +00002709 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00002710}
Mike Stump11289f42009-09-09 15:08:12 +00002711
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00002712template<typename Derived>
2713OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) {
2714 if (!S)
2715 return S;
2716
2717 switch (S->getClauseKind()) {
2718 default: break;
2719 // Transform individual clause nodes
2720#define OPENMP_CLAUSE(Name, Class) \
2721 case OMPC_ ## Name : \
2722 return getDerived().Transform ## Class(cast<Class>(S));
2723#include "clang/Basic/OpenMPKinds.def"
2724 }
2725
2726 return S;
2727}
2728
Mike Stump11289f42009-09-09 15:08:12 +00002729
Douglas Gregore922c772009-08-04 22:27:00 +00002730template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002731ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002732 if (!E)
2733 return SemaRef.Owned(E);
2734
2735 switch (E->getStmtClass()) {
2736 case Stmt::NoStmtClass: break;
2737#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00002738#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00002739#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00002740 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00002741#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002742 }
2743
John McCallc3007a22010-10-26 07:05:15 +00002744 return SemaRef.Owned(E);
Douglas Gregor766b0bb2009-08-06 22:17:10 +00002745}
2746
2747template<typename Derived>
Richard Smithd59b8322012-12-19 01:39:02 +00002748ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
2749 bool CXXDirectInit) {
2750 // Initializers are instantiated like expressions, except that various outer
2751 // layers are stripped.
2752 if (!Init)
2753 return SemaRef.Owned(Init);
2754
2755 if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init))
2756 Init = ExprTemp->getSubExpr();
2757
Richard Smithe6ca4752013-05-30 22:40:16 +00002758 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
2759 Init = MTE->GetTemporaryExpr();
2760
Richard Smithd59b8322012-12-19 01:39:02 +00002761 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
2762 Init = Binder->getSubExpr();
2763
2764 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
2765 Init = ICE->getSubExprAsWritten();
2766
Richard Smithcc1b96d2013-06-12 22:31:48 +00002767 if (CXXStdInitializerListExpr *ILE =
2768 dyn_cast<CXXStdInitializerListExpr>(Init))
2769 return TransformInitializer(ILE->getSubExpr(), CXXDirectInit);
2770
Richard Smith38a549b2012-12-21 08:13:35 +00002771 // If this is not a direct-initializer, we only need to reconstruct
2772 // InitListExprs. Other forms of copy-initialization will be a no-op if
2773 // the initializer is already the right type.
2774 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
2775 if (!CXXDirectInit && !(Construct && Construct->isListInitialization()))
2776 return getDerived().TransformExpr(Init);
2777
2778 // Revert value-initialization back to empty parens.
2779 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
2780 SourceRange Parens = VIE->getSourceRange();
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002781 return getDerived().RebuildParenListExpr(Parens.getBegin(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00002782 Parens.getEnd());
2783 }
2784
2785 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
2786 if (isa<ImplicitValueInitExpr>(Init))
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002787 return getDerived().RebuildParenListExpr(SourceLocation(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00002788 SourceLocation());
2789
2790 // Revert initialization by constructor back to a parenthesized or braced list
2791 // of expressions. Any other form of initializer can just be reused directly.
2792 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
Richard Smithd59b8322012-12-19 01:39:02 +00002793 return getDerived().TransformExpr(Init);
2794
2795 SmallVector<Expr*, 8> NewArgs;
2796 bool ArgChanged = false;
2797 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
2798 /*IsCall*/true, NewArgs, &ArgChanged))
2799 return ExprError();
2800
2801 // If this was list initialization, revert to list form.
2802 if (Construct->isListInitialization())
2803 return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs,
2804 Construct->getLocEnd(),
2805 Construct->getType());
2806
Richard Smithd59b8322012-12-19 01:39:02 +00002807 // Build a ParenListExpr to represent anything else.
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00002808 SourceRange Parens = Construct->getParenOrBraceRange();
Richard Smithd59b8322012-12-19 01:39:02 +00002809 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
2810 Parens.getEnd());
2811}
2812
2813template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00002814bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2815 unsigned NumInputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00002816 bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +00002817 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00002818 bool *ArgChanged) {
2819 for (unsigned I = 0; I != NumInputs; ++I) {
2820 // If requested, drop call arguments that need to be dropped.
2821 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2822 if (ArgChanged)
2823 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002824
Douglas Gregora3efea12011-01-03 19:04:46 +00002825 break;
2826 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002827
Douglas Gregor968f23a2011-01-03 19:31:53 +00002828 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2829 Expr *Pattern = Expansion->getPattern();
Chad Rosier1dcde962012-08-08 18:46:20 +00002830
Chris Lattner01cf8db2011-07-20 06:58:45 +00002831 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor968f23a2011-01-03 19:31:53 +00002832 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2833 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00002834
Douglas Gregor968f23a2011-01-03 19:31:53 +00002835 // Determine whether the set of unexpanded parameter packs can and should
2836 // be expanded.
2837 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002838 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00002839 Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
2840 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor968f23a2011-01-03 19:31:53 +00002841 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2842 Pattern->getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00002843 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002844 Expand, RetainExpansion,
2845 NumExpansions))
Douglas Gregor968f23a2011-01-03 19:31:53 +00002846 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002847
Douglas Gregor968f23a2011-01-03 19:31:53 +00002848 if (!Expand) {
2849 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00002850 // transformation on the pack expansion, producing another pack
Douglas Gregor968f23a2011-01-03 19:31:53 +00002851 // expansion.
2852 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2853 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2854 if (OutPattern.isInvalid())
2855 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002856
2857 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregorb8840002011-01-14 21:20:45 +00002858 Expansion->getEllipsisLoc(),
2859 NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002860 if (Out.isInvalid())
2861 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002862
Douglas Gregor968f23a2011-01-03 19:31:53 +00002863 if (ArgChanged)
2864 *ArgChanged = true;
2865 Outputs.push_back(Out.get());
2866 continue;
2867 }
John McCall542e7c62011-07-06 07:30:07 +00002868
2869 // Record right away that the argument was changed. This needs
2870 // to happen even if the array expands to nothing.
2871 if (ArgChanged) *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002872
Douglas Gregor968f23a2011-01-03 19:31:53 +00002873 // The transform has determined that we should perform an elementwise
2874 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002875 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor968f23a2011-01-03 19:31:53 +00002876 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2877 ExprResult Out = getDerived().TransformExpr(Pattern);
2878 if (Out.isInvalid())
2879 return true;
2880
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002881 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregorb8840002011-01-14 21:20:45 +00002882 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2883 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002884 if (Out.isInvalid())
2885 return true;
2886 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002887
Douglas Gregor968f23a2011-01-03 19:31:53 +00002888 Outputs.push_back(Out.get());
2889 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002890
Douglas Gregor968f23a2011-01-03 19:31:53 +00002891 continue;
2892 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002893
Richard Smithd59b8322012-12-19 01:39:02 +00002894 ExprResult Result =
2895 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
2896 : getDerived().TransformExpr(Inputs[I]);
Douglas Gregora3efea12011-01-03 19:04:46 +00002897 if (Result.isInvalid())
2898 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002899
Douglas Gregora3efea12011-01-03 19:04:46 +00002900 if (Result.get() != Inputs[I] && ArgChanged)
2901 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00002902
2903 Outputs.push_back(Result.get());
Douglas Gregora3efea12011-01-03 19:04:46 +00002904 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002905
Douglas Gregora3efea12011-01-03 19:04:46 +00002906 return false;
2907}
2908
2909template<typename Derived>
Douglas Gregor14454802011-02-25 02:25:35 +00002910NestedNameSpecifierLoc
2911TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2912 NestedNameSpecifierLoc NNS,
2913 QualType ObjectType,
2914 NamedDecl *FirstQualifierInScope) {
Chris Lattner01cf8db2011-07-20 06:58:45 +00002915 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier1dcde962012-08-08 18:46:20 +00002916 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregor14454802011-02-25 02:25:35 +00002917 Qualifier = Qualifier.getPrefix())
2918 Qualifiers.push_back(Qualifier);
2919
2920 CXXScopeSpec SS;
2921 while (!Qualifiers.empty()) {
2922 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2923 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier1dcde962012-08-08 18:46:20 +00002924
Douglas Gregor14454802011-02-25 02:25:35 +00002925 switch (QNNS->getKind()) {
2926 case NestedNameSpecifier::Identifier:
Chad Rosier1dcde962012-08-08 18:46:20 +00002927 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
Douglas Gregor14454802011-02-25 02:25:35 +00002928 *QNNS->getAsIdentifier(),
Chad Rosier1dcde962012-08-08 18:46:20 +00002929 Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00002930 Q.getLocalEndLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00002931 ObjectType, false, SS,
Douglas Gregor14454802011-02-25 02:25:35 +00002932 FirstQualifierInScope, false))
2933 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00002934
Douglas Gregor14454802011-02-25 02:25:35 +00002935 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00002936
Douglas Gregor14454802011-02-25 02:25:35 +00002937 case NestedNameSpecifier::Namespace: {
2938 NamespaceDecl *NS
2939 = cast_or_null<NamespaceDecl>(
2940 getDerived().TransformDecl(
2941 Q.getLocalBeginLoc(),
2942 QNNS->getAsNamespace()));
2943 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2944 break;
2945 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002946
Douglas Gregor14454802011-02-25 02:25:35 +00002947 case NestedNameSpecifier::NamespaceAlias: {
2948 NamespaceAliasDecl *Alias
2949 = cast_or_null<NamespaceAliasDecl>(
2950 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2951 QNNS->getAsNamespaceAlias()));
Chad Rosier1dcde962012-08-08 18:46:20 +00002952 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00002953 Q.getLocalEndLoc());
2954 break;
2955 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002956
Douglas Gregor14454802011-02-25 02:25:35 +00002957 case NestedNameSpecifier::Global:
2958 // There is no meaningful transformation that one could perform on the
2959 // global scope.
2960 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2961 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00002962
Douglas Gregor14454802011-02-25 02:25:35 +00002963 case NestedNameSpecifier::TypeSpecWithTemplate:
2964 case NestedNameSpecifier::TypeSpec: {
2965 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2966 FirstQualifierInScope, SS);
Chad Rosier1dcde962012-08-08 18:46:20 +00002967
Douglas Gregor14454802011-02-25 02:25:35 +00002968 if (!TL)
2969 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00002970
Douglas Gregor14454802011-02-25 02:25:35 +00002971 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Richard Smith2bf7fdb2013-01-02 11:42:31 +00002972 (SemaRef.getLangOpts().CPlusPlus11 &&
Douglas Gregor14454802011-02-25 02:25:35 +00002973 TL.getType()->isEnumeralType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002974 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregor14454802011-02-25 02:25:35 +00002975 "Can't get cv-qualifiers here");
Richard Smith91c7bbd2011-10-20 03:28:47 +00002976 if (TL.getType()->isEnumeralType())
2977 SemaRef.Diag(TL.getBeginLoc(),
2978 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregor14454802011-02-25 02:25:35 +00002979 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2980 Q.getLocalEndLoc());
2981 break;
2982 }
Richard Trieude756fb2011-05-07 01:36:37 +00002983 // If the nested-name-specifier is an invalid type def, don't emit an
2984 // error because a previous error should have already been emitted.
David Blaikie6adc78e2013-02-18 22:06:02 +00002985 TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
2986 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002987 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieude756fb2011-05-07 01:36:37 +00002988 << TL.getType() << SS.getRange();
2989 }
Douglas Gregor14454802011-02-25 02:25:35 +00002990 return NestedNameSpecifierLoc();
2991 }
Douglas Gregore16af532011-02-28 18:50:33 +00002992 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002993
Douglas Gregore16af532011-02-28 18:50:33 +00002994 // The qualifier-in-scope and object type only apply to the leftmost entity.
Douglas Gregor14454802011-02-25 02:25:35 +00002995 FirstQualifierInScope = 0;
Douglas Gregore16af532011-02-28 18:50:33 +00002996 ObjectType = QualType();
Douglas Gregor14454802011-02-25 02:25:35 +00002997 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002998
Douglas Gregor14454802011-02-25 02:25:35 +00002999 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier1dcde962012-08-08 18:46:20 +00003000 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003001 !getDerived().AlwaysRebuild())
3002 return NNS;
Chad Rosier1dcde962012-08-08 18:46:20 +00003003
3004 // If we can re-use the source-location data from the original
Douglas Gregor14454802011-02-25 02:25:35 +00003005 // nested-name-specifier, do so.
3006 if (SS.location_size() == NNS.getDataLength() &&
3007 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
3008 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
3009
3010 // Allocate new nested-name-specifier location information.
3011 return SS.getWithLocInContext(SemaRef.Context);
3012}
3013
3014template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003015DeclarationNameInfo
3016TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00003017::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003018 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003019 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003020 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003021
3022 switch (Name.getNameKind()) {
3023 case DeclarationName::Identifier:
3024 case DeclarationName::ObjCZeroArgSelector:
3025 case DeclarationName::ObjCOneArgSelector:
3026 case DeclarationName::ObjCMultiArgSelector:
3027 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00003028 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00003029 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003030 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00003031
Douglas Gregorf816bd72009-09-03 22:13:48 +00003032 case DeclarationName::CXXConstructorName:
3033 case DeclarationName::CXXDestructorName:
3034 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003035 TypeSourceInfo *NewTInfo;
3036 CanQualType NewCanTy;
3037 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00003038 NewTInfo = getDerived().TransformType(OldTInfo);
3039 if (!NewTInfo)
3040 return DeclarationNameInfo();
3041 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003042 }
3043 else {
3044 NewTInfo = 0;
3045 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00003046 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003047 if (NewT.isNull())
3048 return DeclarationNameInfo();
3049 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
3050 }
Mike Stump11289f42009-09-09 15:08:12 +00003051
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003052 DeclarationName NewName
3053 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
3054 NewCanTy);
3055 DeclarationNameInfo NewNameInfo(NameInfo);
3056 NewNameInfo.setName(NewName);
3057 NewNameInfo.setNamedTypeInfo(NewTInfo);
3058 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00003059 }
Mike Stump11289f42009-09-09 15:08:12 +00003060 }
3061
David Blaikie83d382b2011-09-23 05:06:16 +00003062 llvm_unreachable("Unknown name kind.");
Douglas Gregorf816bd72009-09-03 22:13:48 +00003063}
3064
3065template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003066TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00003067TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
3068 TemplateName Name,
3069 SourceLocation NameLoc,
3070 QualType ObjectType,
3071 NamedDecl *FirstQualifierInScope) {
3072 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
3073 TemplateDecl *Template = QTN->getTemplateDecl();
3074 assert(Template && "qualified template name must refer to a template");
Chad Rosier1dcde962012-08-08 18:46:20 +00003075
Douglas Gregor9db53502011-03-02 18:07:45 +00003076 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003077 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003078 Template));
3079 if (!TransTemplate)
3080 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003081
Douglas Gregor9db53502011-03-02 18:07:45 +00003082 if (!getDerived().AlwaysRebuild() &&
3083 SS.getScopeRep() == QTN->getQualifier() &&
3084 TransTemplate == Template)
3085 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003086
Douglas Gregor9db53502011-03-02 18:07:45 +00003087 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
3088 TransTemplate);
3089 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003090
Douglas Gregor9db53502011-03-02 18:07:45 +00003091 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
3092 if (SS.getScopeRep()) {
3093 // These apply to the scope specifier, not the template.
3094 ObjectType = QualType();
3095 FirstQualifierInScope = 0;
Chad Rosier1dcde962012-08-08 18:46:20 +00003096 }
3097
Douglas Gregor9db53502011-03-02 18:07:45 +00003098 if (!getDerived().AlwaysRebuild() &&
3099 SS.getScopeRep() == DTN->getQualifier() &&
3100 ObjectType.isNull())
3101 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003102
Douglas Gregor9db53502011-03-02 18:07:45 +00003103 if (DTN->isIdentifier()) {
3104 return getDerived().RebuildTemplateName(SS,
Chad Rosier1dcde962012-08-08 18:46:20 +00003105 *DTN->getIdentifier(),
Douglas Gregor9db53502011-03-02 18:07:45 +00003106 NameLoc,
3107 ObjectType,
3108 FirstQualifierInScope);
3109 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003110
Douglas Gregor9db53502011-03-02 18:07:45 +00003111 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
3112 ObjectType);
3113 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003114
Douglas Gregor9db53502011-03-02 18:07:45 +00003115 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
3116 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003117 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003118 Template));
3119 if (!TransTemplate)
3120 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003121
Douglas Gregor9db53502011-03-02 18:07:45 +00003122 if (!getDerived().AlwaysRebuild() &&
3123 TransTemplate == Template)
3124 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003125
Douglas Gregor9db53502011-03-02 18:07:45 +00003126 return TemplateName(TransTemplate);
3127 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003128
Douglas Gregor9db53502011-03-02 18:07:45 +00003129 if (SubstTemplateTemplateParmPackStorage *SubstPack
3130 = Name.getAsSubstTemplateTemplateParmPack()) {
3131 TemplateTemplateParmDecl *TransParam
3132 = cast_or_null<TemplateTemplateParmDecl>(
3133 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
3134 if (!TransParam)
3135 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003136
Douglas Gregor9db53502011-03-02 18:07:45 +00003137 if (!getDerived().AlwaysRebuild() &&
3138 TransParam == SubstPack->getParameterPack())
3139 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003140
3141 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregor9db53502011-03-02 18:07:45 +00003142 SubstPack->getArgumentPack());
3143 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003144
Douglas Gregor9db53502011-03-02 18:07:45 +00003145 // These should be getting filtered out before they reach the AST.
3146 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregor9db53502011-03-02 18:07:45 +00003147}
3148
3149template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003150void TreeTransform<Derived>::InventTemplateArgumentLoc(
3151 const TemplateArgument &Arg,
3152 TemplateArgumentLoc &Output) {
3153 SourceLocation Loc = getDerived().getBaseLocation();
3154 switch (Arg.getKind()) {
3155 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003156 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00003157 break;
3158
3159 case TemplateArgument::Type:
3160 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00003161 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier1dcde962012-08-08 18:46:20 +00003162
John McCall0ad16662009-10-29 08:12:44 +00003163 break;
3164
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003165 case TemplateArgument::Template:
Douglas Gregor9d802122011-03-02 17:09:35 +00003166 case TemplateArgument::TemplateExpansion: {
3167 NestedNameSpecifierLocBuilder Builder;
3168 TemplateName Template = Arg.getAsTemplate();
3169 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3170 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3171 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3172 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003173
Douglas Gregor9d802122011-03-02 17:09:35 +00003174 if (Arg.getKind() == TemplateArgument::Template)
Chad Rosier1dcde962012-08-08 18:46:20 +00003175 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003176 Builder.getWithLocInContext(SemaRef.Context),
3177 Loc);
3178 else
Chad Rosier1dcde962012-08-08 18:46:20 +00003179 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003180 Builder.getWithLocInContext(SemaRef.Context),
3181 Loc, Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003182
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003183 break;
Douglas Gregor9d802122011-03-02 17:09:35 +00003184 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003185
John McCall0ad16662009-10-29 08:12:44 +00003186 case TemplateArgument::Expression:
3187 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3188 break;
3189
3190 case TemplateArgument::Declaration:
3191 case TemplateArgument::Integral:
3192 case TemplateArgument::Pack:
Eli Friedmanb826a002012-09-26 02:36:12 +00003193 case TemplateArgument::NullPtr:
John McCall0d07eb32009-10-29 18:45:58 +00003194 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00003195 break;
3196 }
3197}
3198
3199template<typename Derived>
3200bool TreeTransform<Derived>::TransformTemplateArgument(
3201 const TemplateArgumentLoc &Input,
3202 TemplateArgumentLoc &Output) {
3203 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00003204 switch (Arg.getKind()) {
3205 case TemplateArgument::Null:
3206 case TemplateArgument::Integral:
Eli Friedmancda3db82012-09-25 01:02:42 +00003207 case TemplateArgument::Pack:
3208 case TemplateArgument::Declaration:
Eli Friedmanb826a002012-09-26 02:36:12 +00003209 case TemplateArgument::NullPtr:
3210 llvm_unreachable("Unexpected TemplateArgument");
Mike Stump11289f42009-09-09 15:08:12 +00003211
Douglas Gregore922c772009-08-04 22:27:00 +00003212 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00003213 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall0ad16662009-10-29 08:12:44 +00003214 if (DI == NULL)
John McCallbcd03502009-12-07 02:54:59 +00003215 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00003216
3217 DI = getDerived().TransformType(DI);
3218 if (!DI) return true;
3219
3220 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3221 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003222 }
Mike Stump11289f42009-09-09 15:08:12 +00003223
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003224 case TemplateArgument::Template: {
Douglas Gregor9d802122011-03-02 17:09:35 +00003225 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3226 if (QualifierLoc) {
3227 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3228 if (!QualifierLoc)
3229 return true;
3230 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003231
Douglas Gregordf846d12011-03-02 18:46:51 +00003232 CXXScopeSpec SS;
3233 SS.Adopt(QualifierLoc);
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003234 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00003235 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3236 Input.getTemplateNameLoc());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003237 if (Template.isNull())
3238 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003239
Douglas Gregor9d802122011-03-02 17:09:35 +00003240 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003241 Input.getTemplateNameLoc());
3242 return false;
3243 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003244
3245 case TemplateArgument::TemplateExpansion:
3246 llvm_unreachable("Caller should expand pack expansions");
3247
Douglas Gregore922c772009-08-04 22:27:00 +00003248 case TemplateArgument::Expression: {
Richard Smith764d2fe2011-12-20 02:08:33 +00003249 // Template argument expressions are constant expressions.
Mike Stump11289f42009-09-09 15:08:12 +00003250 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smith764d2fe2011-12-20 02:08:33 +00003251 Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003252
John McCall0ad16662009-10-29 08:12:44 +00003253 Expr *InputExpr = Input.getSourceExpression();
3254 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3255
Chris Lattnercdb591a2011-04-25 20:37:58 +00003256 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanc6237c62012-02-29 03:16:56 +00003257 E = SemaRef.ActOnConstantExpression(E);
John McCall0ad16662009-10-29 08:12:44 +00003258 if (E.isInvalid()) return true;
John McCallb268a282010-08-23 23:25:46 +00003259 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall0ad16662009-10-29 08:12:44 +00003260 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003261 }
Douglas Gregore922c772009-08-04 22:27:00 +00003262 }
Mike Stump11289f42009-09-09 15:08:12 +00003263
Douglas Gregore922c772009-08-04 22:27:00 +00003264 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00003265 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00003266}
3267
Douglas Gregorfe921a72010-12-20 23:36:19 +00003268/// \brief Iterator adaptor that invents template argument location information
3269/// for each of the template arguments in its underlying iterator.
3270template<typename Derived, typename InputIterator>
3271class TemplateArgumentLocInventIterator {
3272 TreeTransform<Derived> &Self;
3273 InputIterator Iter;
Chad Rosier1dcde962012-08-08 18:46:20 +00003274
Douglas Gregorfe921a72010-12-20 23:36:19 +00003275public:
3276 typedef TemplateArgumentLoc value_type;
3277 typedef TemplateArgumentLoc reference;
3278 typedef typename std::iterator_traits<InputIterator>::difference_type
3279 difference_type;
3280 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00003281
Douglas Gregorfe921a72010-12-20 23:36:19 +00003282 class pointer {
3283 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00003284
Douglas Gregorfe921a72010-12-20 23:36:19 +00003285 public:
3286 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003287
Douglas Gregorfe921a72010-12-20 23:36:19 +00003288 const TemplateArgumentLoc *operator->() const { return &Arg; }
3289 };
Chad Rosier1dcde962012-08-08 18:46:20 +00003290
Douglas Gregorfe921a72010-12-20 23:36:19 +00003291 TemplateArgumentLocInventIterator() { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003292
Douglas Gregorfe921a72010-12-20 23:36:19 +00003293 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3294 InputIterator Iter)
3295 : Self(Self), Iter(Iter) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003296
Douglas Gregorfe921a72010-12-20 23:36:19 +00003297 TemplateArgumentLocInventIterator &operator++() {
3298 ++Iter;
3299 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00003300 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003301
Douglas Gregorfe921a72010-12-20 23:36:19 +00003302 TemplateArgumentLocInventIterator operator++(int) {
3303 TemplateArgumentLocInventIterator Old(*this);
3304 ++(*this);
3305 return Old;
3306 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003307
Douglas Gregorfe921a72010-12-20 23:36:19 +00003308 reference operator*() const {
3309 TemplateArgumentLoc Result;
3310 Self.InventTemplateArgumentLoc(*Iter, Result);
3311 return Result;
3312 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003313
Douglas Gregorfe921a72010-12-20 23:36:19 +00003314 pointer operator->() const { return pointer(**this); }
Chad Rosier1dcde962012-08-08 18:46:20 +00003315
Douglas Gregorfe921a72010-12-20 23:36:19 +00003316 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3317 const TemplateArgumentLocInventIterator &Y) {
3318 return X.Iter == Y.Iter;
3319 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00003320
Douglas Gregorfe921a72010-12-20 23:36:19 +00003321 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3322 const TemplateArgumentLocInventIterator &Y) {
3323 return X.Iter != Y.Iter;
3324 }
3325};
Chad Rosier1dcde962012-08-08 18:46:20 +00003326
Douglas Gregor42cafa82010-12-20 17:42:22 +00003327template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00003328template<typename InputIterator>
3329bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3330 InputIterator Last,
Douglas Gregor42cafa82010-12-20 17:42:22 +00003331 TemplateArgumentListInfo &Outputs) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00003332 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00003333 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00003334 TemplateArgumentLoc In = *First;
Chad Rosier1dcde962012-08-08 18:46:20 +00003335
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003336 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3337 // Unpack argument packs, which we translate them into separate
3338 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00003339 // FIXME: We could do much better if we could guarantee that the
3340 // TemplateArgumentLocInfo for the pack expansion would be usable for
3341 // all of the template arguments in the argument pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00003342 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003343 TemplateArgument::pack_iterator>
3344 PackLocIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00003345 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003346 In.getArgument().pack_begin()),
3347 PackLocIterator(*this,
3348 In.getArgument().pack_end()),
3349 Outputs))
3350 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003351
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003352 continue;
3353 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003354
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003355 if (In.getArgument().isPackExpansion()) {
3356 // We have a pack expansion, for which we will be substituting into
3357 // the pattern.
3358 SourceLocation Ellipsis;
David Blaikie05785d12013-02-20 22:23:23 +00003359 Optional<unsigned> OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003360 TemplateArgumentLoc Pattern
Eli Friedman94e9eaa2013-06-20 04:11:21 +00003361 = getSema().getTemplateArgumentPackExpansionPattern(
3362 In, Ellipsis, OrigNumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00003363
Chris Lattner01cf8db2011-07-20 06:58:45 +00003364 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003365 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3366 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00003367
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003368 // Determine whether the set of unexpanded parameter packs can and should
3369 // be expanded.
3370 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003371 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00003372 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003373 if (getDerived().TryExpandParameterPacks(Ellipsis,
3374 Pattern.getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003375 Unexpanded,
Chad Rosier1dcde962012-08-08 18:46:20 +00003376 Expand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003377 RetainExpansion,
3378 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003379 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003380
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003381 if (!Expand) {
3382 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00003383 // transformation on the pack expansion, producing another pack
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003384 // expansion.
3385 TemplateArgumentLoc OutPattern;
3386 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3387 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3388 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003389
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003390 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3391 NumExpansions);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003392 if (Out.getArgument().isNull())
3393 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003394
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003395 Outputs.addArgument(Out);
3396 continue;
3397 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003398
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003399 // The transform has determined that we should perform an elementwise
3400 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003401 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003402 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3403
3404 if (getDerived().TransformTemplateArgument(Pattern, Out))
3405 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003406
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003407 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003408 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3409 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003410 if (Out.getArgument().isNull())
3411 return true;
3412 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003413
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003414 Outputs.addArgument(Out);
3415 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003416
Douglas Gregor48d24112011-01-10 20:53:55 +00003417 // If we're supposed to retain a pack expansion, do so by temporarily
3418 // forgetting the partially-substituted parameter pack.
3419 if (RetainExpansion) {
3420 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00003421
Douglas Gregor48d24112011-01-10 20:53:55 +00003422 if (getDerived().TransformTemplateArgument(Pattern, Out))
3423 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003424
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003425 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3426 OrigNumExpansions);
Douglas Gregor48d24112011-01-10 20:53:55 +00003427 if (Out.getArgument().isNull())
3428 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003429
Douglas Gregor48d24112011-01-10 20:53:55 +00003430 Outputs.addArgument(Out);
3431 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003432
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003433 continue;
3434 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003435
3436 // The simple case:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003437 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor42cafa82010-12-20 17:42:22 +00003438 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003439
Douglas Gregor42cafa82010-12-20 17:42:22 +00003440 Outputs.addArgument(Out);
3441 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003442
Douglas Gregor42cafa82010-12-20 17:42:22 +00003443 return false;
3444
3445}
3446
Douglas Gregord6ff3322009-08-04 16:50:30 +00003447//===----------------------------------------------------------------------===//
3448// Type transformation
3449//===----------------------------------------------------------------------===//
3450
3451template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003452QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00003453 if (getDerived().AlreadyTransformed(T))
3454 return T;
Mike Stump11289f42009-09-09 15:08:12 +00003455
John McCall550e0c22009-10-21 00:40:46 +00003456 // Temporary workaround. All of these transformations should
3457 // eventually turn into transformations on TypeLocs.
Douglas Gregor2d525f02011-01-25 19:13:18 +00003458 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3459 getDerived().getBaseLocation());
Chad Rosier1dcde962012-08-08 18:46:20 +00003460
John McCall31f82722010-11-12 08:19:04 +00003461 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00003462
John McCall550e0c22009-10-21 00:40:46 +00003463 if (!NewDI)
3464 return QualType();
3465
3466 return NewDI->getType();
3467}
3468
3469template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003470TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smith764d2fe2011-12-20 02:08:33 +00003471 // Refine the base location to the type's location.
3472 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3473 getDerived().getBaseEntity());
John McCall550e0c22009-10-21 00:40:46 +00003474 if (getDerived().AlreadyTransformed(DI->getType()))
3475 return DI;
3476
3477 TypeLocBuilder TLB;
3478
3479 TypeLoc TL = DI->getTypeLoc();
3480 TLB.reserve(TL.getFullDataSize());
3481
John McCall31f82722010-11-12 08:19:04 +00003482 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00003483 if (Result.isNull())
3484 return 0;
3485
John McCallbcd03502009-12-07 02:54:59 +00003486 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00003487}
3488
3489template<typename Derived>
3490QualType
John McCall31f82722010-11-12 08:19:04 +00003491TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003492 switch (T.getTypeLocClass()) {
3493#define ABSTRACT_TYPELOC(CLASS, PARENT)
David Blaikie6adc78e2013-02-18 22:06:02 +00003494#define TYPELOC(CLASS, PARENT) \
3495 case TypeLoc::CLASS: \
3496 return getDerived().Transform##CLASS##Type(TLB, \
3497 T.castAs<CLASS##TypeLoc>());
John McCall550e0c22009-10-21 00:40:46 +00003498#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00003499 }
Mike Stump11289f42009-09-09 15:08:12 +00003500
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003501 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00003502}
3503
3504/// FIXME: By default, this routine adds type qualifiers only to types
3505/// that can have qualifiers, and silently suppresses those qualifiers
3506/// that are not permitted (e.g., qualifiers on reference or function
3507/// types). This is the right thing for template instantiation, but
3508/// probably not for other clients.
3509template<typename Derived>
3510QualType
3511TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003512 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00003513 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00003514
John McCall31f82722010-11-12 08:19:04 +00003515 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00003516 if (Result.isNull())
3517 return QualType();
3518
3519 // Silently suppress qualifiers if the result type can't be qualified.
3520 // FIXME: this is the right thing for template instantiation, but
3521 // probably not for other clients.
3522 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00003523 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00003524
John McCall31168b02011-06-15 23:02:42 +00003525 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore46db902011-06-17 22:11:49 +00003526 // resulting type.
3527 if (Quals.hasObjCLifetime()) {
3528 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3529 Quals.removeObjCLifetime();
Douglas Gregord7357a92011-06-17 23:16:24 +00003530 else if (Result.getObjCLifetime()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003531 // Objective-C ARC:
Douglas Gregore46db902011-06-17 22:11:49 +00003532 // A lifetime qualifier applied to a substituted template parameter
3533 // overrides the lifetime qualifier from the template argument.
Douglas Gregorf4e43312013-01-17 23:59:28 +00003534 const AutoType *AutoTy;
Chad Rosier1dcde962012-08-08 18:46:20 +00003535 if (const SubstTemplateTypeParmType *SubstTypeParam
Douglas Gregore46db902011-06-17 22:11:49 +00003536 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3537 QualType Replacement = SubstTypeParam->getReplacementType();
3538 Qualifiers Qs = Replacement.getQualifiers();
3539 Qs.removeObjCLifetime();
Chad Rosier1dcde962012-08-08 18:46:20 +00003540 Replacement
Douglas Gregore46db902011-06-17 22:11:49 +00003541 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3542 Qs);
3543 Result = SemaRef.Context.getSubstTemplateTypeParmType(
Chad Rosier1dcde962012-08-08 18:46:20 +00003544 SubstTypeParam->getReplacedParameter(),
Douglas Gregore46db902011-06-17 22:11:49 +00003545 Replacement);
3546 TLB.TypeWasModifiedSafely(Result);
Douglas Gregorf4e43312013-01-17 23:59:28 +00003547 } else if ((AutoTy = dyn_cast<AutoType>(Result)) && AutoTy->isDeduced()) {
3548 // 'auto' types behave the same way as template parameters.
3549 QualType Deduced = AutoTy->getDeducedType();
3550 Qualifiers Qs = Deduced.getQualifiers();
3551 Qs.removeObjCLifetime();
3552 Deduced = SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(),
3553 Qs);
Faisal Vali2b391ab2013-09-26 19:54:12 +00003554 Result = SemaRef.Context.getAutoType(Deduced, AutoTy->isDecltypeAuto(),
3555 AutoTy->isDependentType());
Douglas Gregorf4e43312013-01-17 23:59:28 +00003556 TLB.TypeWasModifiedSafely(Result);
Douglas Gregore46db902011-06-17 22:11:49 +00003557 } else {
Douglas Gregord7357a92011-06-17 23:16:24 +00003558 // Otherwise, complain about the addition of a qualifier to an
3559 // already-qualified type.
Eli Friedman7152fbe2013-06-07 20:31:48 +00003560 SourceRange R = T.getUnqualifiedLoc().getSourceRange();
Argyrios Kyrtzidiscff00d92011-06-24 00:08:59 +00003561 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregord7357a92011-06-17 23:16:24 +00003562 << Result << R;
Chad Rosier1dcde962012-08-08 18:46:20 +00003563
Douglas Gregore46db902011-06-17 22:11:49 +00003564 Quals.removeObjCLifetime();
3565 }
3566 }
3567 }
John McCallcb0f89a2010-06-05 06:41:15 +00003568 if (!Quals.empty()) {
3569 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
Richard Smithdeec0742013-03-27 23:36:39 +00003570 // BuildQualifiedType might not add qualifiers if they are invalid.
3571 if (Result.hasLocalQualifiers())
3572 TLB.push<QualifiedTypeLoc>(Result);
John McCallcb0f89a2010-06-05 06:41:15 +00003573 // No location information to preserve.
3574 }
John McCall550e0c22009-10-21 00:40:46 +00003575
3576 return Result;
3577}
3578
Douglas Gregor14454802011-02-25 02:25:35 +00003579template<typename Derived>
3580TypeLoc
3581TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3582 QualType ObjectType,
3583 NamedDecl *UnqualLookup,
3584 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003585 if (getDerived().AlreadyTransformed(TL.getType()))
Douglas Gregor14454802011-02-25 02:25:35 +00003586 return TL;
Chad Rosier1dcde962012-08-08 18:46:20 +00003587
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003588 TypeSourceInfo *TSI =
3589 TransformTSIInObjectScope(TL, ObjectType, UnqualLookup, SS);
3590 if (TSI)
3591 return TSI->getTypeLoc();
3592 return TypeLoc();
Douglas Gregor14454802011-02-25 02:25:35 +00003593}
3594
Douglas Gregor579c15f2011-03-02 18:32:08 +00003595template<typename Derived>
3596TypeSourceInfo *
3597TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3598 QualType ObjectType,
3599 NamedDecl *UnqualLookup,
3600 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003601 if (getDerived().AlreadyTransformed(TSInfo->getType()))
Douglas Gregor579c15f2011-03-02 18:32:08 +00003602 return TSInfo;
Chad Rosier1dcde962012-08-08 18:46:20 +00003603
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003604 return TransformTSIInObjectScope(TSInfo->getTypeLoc(), ObjectType,
3605 UnqualLookup, SS);
3606}
3607
3608template <typename Derived>
3609TypeSourceInfo *TreeTransform<Derived>::TransformTSIInObjectScope(
3610 TypeLoc TL, QualType ObjectType, NamedDecl *UnqualLookup,
3611 CXXScopeSpec &SS) {
3612 QualType T = TL.getType();
3613 assert(!getDerived().AlreadyTransformed(T));
3614
Douglas Gregor579c15f2011-03-02 18:32:08 +00003615 TypeLocBuilder TLB;
3616 QualType Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00003617
Douglas Gregor579c15f2011-03-02 18:32:08 +00003618 if (isa<TemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00003619 TemplateSpecializationTypeLoc SpecTL =
3620 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00003621
Douglas Gregor579c15f2011-03-02 18:32:08 +00003622 TemplateName Template
3623 = getDerived().TransformTemplateName(SS,
3624 SpecTL.getTypePtr()->getTemplateName(),
3625 SpecTL.getTemplateNameLoc(),
3626 ObjectType, UnqualLookup);
Chad Rosier1dcde962012-08-08 18:46:20 +00003627 if (Template.isNull())
Douglas Gregor579c15f2011-03-02 18:32:08 +00003628 return 0;
Chad Rosier1dcde962012-08-08 18:46:20 +00003629
3630 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregor579c15f2011-03-02 18:32:08 +00003631 Template);
3632 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00003633 DependentTemplateSpecializationTypeLoc SpecTL =
3634 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00003635
Douglas Gregor579c15f2011-03-02 18:32:08 +00003636 TemplateName Template
Chad Rosier1dcde962012-08-08 18:46:20 +00003637 = getDerived().RebuildTemplateName(SS,
3638 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00003639 SpecTL.getTemplateNameLoc(),
Douglas Gregor579c15f2011-03-02 18:32:08 +00003640 ObjectType, UnqualLookup);
3641 if (Template.isNull())
3642 return 0;
Chad Rosier1dcde962012-08-08 18:46:20 +00003643
3644 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregor579c15f2011-03-02 18:32:08 +00003645 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00003646 Template,
3647 SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00003648 } else {
3649 // Nothing special needs to be done for these.
3650 Result = getDerived().TransformType(TLB, TL);
3651 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003652
3653 if (Result.isNull())
Douglas Gregor579c15f2011-03-02 18:32:08 +00003654 return 0;
Chad Rosier1dcde962012-08-08 18:46:20 +00003655
Douglas Gregor579c15f2011-03-02 18:32:08 +00003656 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3657}
3658
John McCall550e0c22009-10-21 00:40:46 +00003659template <class TyLoc> static inline
3660QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3661 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3662 NewT.setNameLoc(T.getNameLoc());
3663 return T.getType();
3664}
3665
John McCall550e0c22009-10-21 00:40:46 +00003666template<typename Derived>
3667QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003668 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00003669 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3670 NewT.setBuiltinLoc(T.getBuiltinLoc());
3671 if (T.needsExtraLocalData())
3672 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3673 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003674}
Mike Stump11289f42009-09-09 15:08:12 +00003675
Douglas Gregord6ff3322009-08-04 16:50:30 +00003676template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003677QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003678 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003679 // FIXME: recurse?
3680 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003681}
Mike Stump11289f42009-09-09 15:08:12 +00003682
Reid Kleckner0503a872013-12-05 01:23:43 +00003683template <typename Derived>
3684QualType TreeTransform<Derived>::TransformAdjustedType(TypeLocBuilder &TLB,
3685 AdjustedTypeLoc TL) {
3686 // Adjustments applied during transformation are handled elsewhere.
3687 return getDerived().TransformType(TLB, TL.getOriginalLoc());
3688}
3689
Douglas Gregord6ff3322009-08-04 16:50:30 +00003690template<typename Derived>
Reid Kleckner8a365022013-06-24 17:51:48 +00003691QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
3692 DecayedTypeLoc TL) {
3693 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
3694 if (OriginalType.isNull())
3695 return QualType();
3696
3697 QualType Result = TL.getType();
3698 if (getDerived().AlwaysRebuild() ||
3699 OriginalType != TL.getOriginalLoc().getType())
3700 Result = SemaRef.Context.getDecayedType(OriginalType);
3701 TLB.push<DecayedTypeLoc>(Result);
3702 // Nothing to set for DecayedTypeLoc.
3703 return Result;
3704}
3705
3706template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003707QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003708 PointerTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003709 QualType PointeeType
3710 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003711 if (PointeeType.isNull())
3712 return QualType();
3713
3714 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00003715 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003716 // A dependent pointer type 'T *' has is being transformed such
3717 // that an Objective-C class type is being replaced for 'T'. The
3718 // resulting pointer type is an ObjCObjectPointerType, not a
3719 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00003720 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier1dcde962012-08-08 18:46:20 +00003721
John McCall8b07ec22010-05-15 11:32:37 +00003722 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3723 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003724 return Result;
3725 }
John McCall31f82722010-11-12 08:19:04 +00003726
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003727 if (getDerived().AlwaysRebuild() ||
3728 PointeeType != TL.getPointeeLoc().getType()) {
3729 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3730 if (Result.isNull())
3731 return QualType();
3732 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003733
John McCall31168b02011-06-15 23:02:42 +00003734 // Objective-C ARC can add lifetime qualifiers to the type that we're
3735 // pointing to.
3736 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier1dcde962012-08-08 18:46:20 +00003737
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003738 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3739 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00003740 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003741}
Mike Stump11289f42009-09-09 15:08:12 +00003742
3743template<typename Derived>
3744QualType
John McCall550e0c22009-10-21 00:40:46 +00003745TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003746 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00003747 QualType PointeeType
Chad Rosier1dcde962012-08-08 18:46:20 +00003748 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3749 if (PointeeType.isNull())
3750 return QualType();
3751
3752 QualType Result = TL.getType();
3753 if (getDerived().AlwaysRebuild() ||
3754 PointeeType != TL.getPointeeLoc().getType()) {
3755 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00003756 TL.getSigilLoc());
3757 if (Result.isNull())
3758 return QualType();
3759 }
3760
Douglas Gregor049211a2010-04-22 16:50:51 +00003761 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00003762 NewT.setSigilLoc(TL.getSigilLoc());
3763 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003764}
3765
John McCall70dd5f62009-10-30 00:06:24 +00003766/// Transforms a reference type. Note that somewhat paradoxically we
3767/// don't care whether the type itself is an l-value type or an r-value
3768/// type; we only care if the type was *written* as an l-value type
3769/// or an r-value type.
3770template<typename Derived>
3771QualType
3772TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003773 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00003774 const ReferenceType *T = TL.getTypePtr();
3775
3776 // Note that this works with the pointee-as-written.
3777 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3778 if (PointeeType.isNull())
3779 return QualType();
3780
3781 QualType Result = TL.getType();
3782 if (getDerived().AlwaysRebuild() ||
3783 PointeeType != T->getPointeeTypeAsWritten()) {
3784 Result = getDerived().RebuildReferenceType(PointeeType,
3785 T->isSpelledAsLValue(),
3786 TL.getSigilLoc());
3787 if (Result.isNull())
3788 return QualType();
3789 }
3790
John McCall31168b02011-06-15 23:02:42 +00003791 // Objective-C ARC can add lifetime qualifiers to the type that we're
3792 // referring to.
3793 TLB.TypeWasModifiedSafely(
3794 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3795
John McCall70dd5f62009-10-30 00:06:24 +00003796 // r-value references can be rebuilt as l-value references.
3797 ReferenceTypeLoc NewTL;
3798 if (isa<LValueReferenceType>(Result))
3799 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3800 else
3801 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3802 NewTL.setSigilLoc(TL.getSigilLoc());
3803
3804 return Result;
3805}
3806
Mike Stump11289f42009-09-09 15:08:12 +00003807template<typename Derived>
3808QualType
John McCall550e0c22009-10-21 00:40:46 +00003809TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003810 LValueReferenceTypeLoc TL) {
3811 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003812}
3813
Mike Stump11289f42009-09-09 15:08:12 +00003814template<typename Derived>
3815QualType
John McCall550e0c22009-10-21 00:40:46 +00003816TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003817 RValueReferenceTypeLoc TL) {
3818 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003819}
Mike Stump11289f42009-09-09 15:08:12 +00003820
Douglas Gregord6ff3322009-08-04 16:50:30 +00003821template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003822QualType
John McCall550e0c22009-10-21 00:40:46 +00003823TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003824 MemberPointerTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003825 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003826 if (PointeeType.isNull())
3827 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003828
Abramo Bagnara509357842011-03-05 14:42:21 +00003829 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
3830 TypeSourceInfo* NewClsTInfo = 0;
3831 if (OldClsTInfo) {
3832 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3833 if (!NewClsTInfo)
3834 return QualType();
3835 }
3836
3837 const MemberPointerType *T = TL.getTypePtr();
3838 QualType OldClsType = QualType(T->getClass(), 0);
3839 QualType NewClsType;
3840 if (NewClsTInfo)
3841 NewClsType = NewClsTInfo->getType();
3842 else {
3843 NewClsType = getDerived().TransformType(OldClsType);
3844 if (NewClsType.isNull())
3845 return QualType();
3846 }
Mike Stump11289f42009-09-09 15:08:12 +00003847
John McCall550e0c22009-10-21 00:40:46 +00003848 QualType Result = TL.getType();
3849 if (getDerived().AlwaysRebuild() ||
3850 PointeeType != T->getPointeeType() ||
Abramo Bagnara509357842011-03-05 14:42:21 +00003851 NewClsType != OldClsType) {
3852 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall70dd5f62009-10-30 00:06:24 +00003853 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00003854 if (Result.isNull())
3855 return QualType();
3856 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00003857
Reid Kleckner0503a872013-12-05 01:23:43 +00003858 // If we had to adjust the pointee type when building a member pointer, make
3859 // sure to push TypeLoc info for it.
3860 const MemberPointerType *MPT = Result->getAs<MemberPointerType>();
3861 if (MPT && PointeeType != MPT->getPointeeType()) {
3862 assert(isa<AdjustedType>(MPT->getPointeeType()));
3863 TLB.push<AdjustedTypeLoc>(MPT->getPointeeType());
3864 }
3865
John McCall550e0c22009-10-21 00:40:46 +00003866 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3867 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnara509357842011-03-05 14:42:21 +00003868 NewTL.setClassTInfo(NewClsTInfo);
John McCall550e0c22009-10-21 00:40:46 +00003869
3870 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003871}
3872
Mike Stump11289f42009-09-09 15:08:12 +00003873template<typename Derived>
3874QualType
John McCall550e0c22009-10-21 00:40:46 +00003875TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003876 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003877 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003878 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003879 if (ElementType.isNull())
3880 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003881
John McCall550e0c22009-10-21 00:40:46 +00003882 QualType Result = TL.getType();
3883 if (getDerived().AlwaysRebuild() ||
3884 ElementType != T->getElementType()) {
3885 Result = getDerived().RebuildConstantArrayType(ElementType,
3886 T->getSizeModifier(),
3887 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00003888 T->getIndexTypeCVRQualifiers(),
3889 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003890 if (Result.isNull())
3891 return QualType();
3892 }
Eli Friedmanf7f102f2012-01-25 22:19:07 +00003893
3894 // We might have either a ConstantArrayType or a VariableArrayType now:
3895 // a ConstantArrayType is allowed to have an element type which is a
3896 // VariableArrayType if the type is dependent. Fortunately, all array
3897 // types have the same location layout.
3898 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00003899 NewTL.setLBracketLoc(TL.getLBracketLoc());
3900 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00003901
John McCall550e0c22009-10-21 00:40:46 +00003902 Expr *Size = TL.getSizeExpr();
3903 if (Size) {
Richard Smith764d2fe2011-12-20 02:08:33 +00003904 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3905 Sema::ConstantEvaluated);
John McCall550e0c22009-10-21 00:40:46 +00003906 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
Eli Friedmanc6237c62012-02-29 03:16:56 +00003907 Size = SemaRef.ActOnConstantExpression(Size).take();
John McCall550e0c22009-10-21 00:40:46 +00003908 }
3909 NewTL.setSizeExpr(Size);
3910
3911 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003912}
Mike Stump11289f42009-09-09 15:08:12 +00003913
Douglas Gregord6ff3322009-08-04 16:50:30 +00003914template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003915QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00003916 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003917 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003918 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003919 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003920 if (ElementType.isNull())
3921 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003922
John McCall550e0c22009-10-21 00:40:46 +00003923 QualType Result = TL.getType();
3924 if (getDerived().AlwaysRebuild() ||
3925 ElementType != T->getElementType()) {
3926 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00003927 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00003928 T->getIndexTypeCVRQualifiers(),
3929 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003930 if (Result.isNull())
3931 return QualType();
3932 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003933
John McCall550e0c22009-10-21 00:40:46 +00003934 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3935 NewTL.setLBracketLoc(TL.getLBracketLoc());
3936 NewTL.setRBracketLoc(TL.getRBracketLoc());
3937 NewTL.setSizeExpr(0);
3938
3939 return Result;
3940}
3941
3942template<typename Derived>
3943QualType
3944TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003945 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003946 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003947 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3948 if (ElementType.isNull())
3949 return QualType();
3950
John McCalldadc5752010-08-24 06:29:42 +00003951 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00003952 = getDerived().TransformExpr(T->getSizeExpr());
3953 if (SizeResult.isInvalid())
3954 return QualType();
3955
John McCallb268a282010-08-23 23:25:46 +00003956 Expr *Size = SizeResult.take();
John McCall550e0c22009-10-21 00:40:46 +00003957
3958 QualType Result = TL.getType();
3959 if (getDerived().AlwaysRebuild() ||
3960 ElementType != T->getElementType() ||
3961 Size != T->getSizeExpr()) {
3962 Result = getDerived().RebuildVariableArrayType(ElementType,
3963 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00003964 Size,
John McCall550e0c22009-10-21 00:40:46 +00003965 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00003966 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003967 if (Result.isNull())
3968 return QualType();
3969 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003970
Serge Pavlov774c6d02014-02-06 03:49:11 +00003971 // We might have constant size array now, but fortunately it has the same
3972 // location layout.
3973 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00003974 NewTL.setLBracketLoc(TL.getLBracketLoc());
3975 NewTL.setRBracketLoc(TL.getRBracketLoc());
3976 NewTL.setSizeExpr(Size);
3977
3978 return Result;
3979}
3980
3981template<typename Derived>
3982QualType
3983TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003984 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003985 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003986 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3987 if (ElementType.isNull())
3988 return QualType();
3989
Richard Smith764d2fe2011-12-20 02:08:33 +00003990 // Array bounds are constant expressions.
3991 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3992 Sema::ConstantEvaluated);
John McCall550e0c22009-10-21 00:40:46 +00003993
John McCall33ddac02011-01-19 10:06:00 +00003994 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3995 Expr *origSize = TL.getSizeExpr();
3996 if (!origSize) origSize = T->getSizeExpr();
3997
3998 ExprResult sizeResult
3999 = getDerived().TransformExpr(origSize);
Eli Friedmanc6237c62012-02-29 03:16:56 +00004000 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall33ddac02011-01-19 10:06:00 +00004001 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00004002 return QualType();
4003
John McCall33ddac02011-01-19 10:06:00 +00004004 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004005
4006 QualType Result = TL.getType();
4007 if (getDerived().AlwaysRebuild() ||
4008 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00004009 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00004010 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
4011 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00004012 size,
John McCall550e0c22009-10-21 00:40:46 +00004013 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004014 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004015 if (Result.isNull())
4016 return QualType();
4017 }
John McCall550e0c22009-10-21 00:40:46 +00004018
4019 // We might have any sort of array type now, but fortunately they
4020 // all have the same location layout.
4021 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4022 NewTL.setLBracketLoc(TL.getLBracketLoc());
4023 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00004024 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00004025
4026 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004027}
Mike Stump11289f42009-09-09 15:08:12 +00004028
4029template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004030QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00004031 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004032 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004033 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004034
4035 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00004036 QualType ElementType = getDerived().TransformType(T->getElementType());
4037 if (ElementType.isNull())
4038 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004039
Richard Smith764d2fe2011-12-20 02:08:33 +00004040 // Vector sizes are constant expressions.
4041 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4042 Sema::ConstantEvaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00004043
John McCalldadc5752010-08-24 06:29:42 +00004044 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanc6237c62012-02-29 03:16:56 +00004045 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004046 if (Size.isInvalid())
4047 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004048
John McCall550e0c22009-10-21 00:40:46 +00004049 QualType Result = TL.getType();
4050 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00004051 ElementType != T->getElementType() ||
4052 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00004053 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCallb268a282010-08-23 23:25:46 +00004054 Size.take(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00004055 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00004056 if (Result.isNull())
4057 return QualType();
4058 }
John McCall550e0c22009-10-21 00:40:46 +00004059
4060 // Result might be dependent or not.
4061 if (isa<DependentSizedExtVectorType>(Result)) {
4062 DependentSizedExtVectorTypeLoc NewTL
4063 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
4064 NewTL.setNameLoc(TL.getNameLoc());
4065 } else {
4066 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4067 NewTL.setNameLoc(TL.getNameLoc());
4068 }
4069
4070 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004071}
Mike Stump11289f42009-09-09 15:08:12 +00004072
4073template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004074QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004075 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004076 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004077 QualType ElementType = getDerived().TransformType(T->getElementType());
4078 if (ElementType.isNull())
4079 return QualType();
4080
John McCall550e0c22009-10-21 00:40:46 +00004081 QualType Result = TL.getType();
4082 if (getDerived().AlwaysRebuild() ||
4083 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00004084 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00004085 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00004086 if (Result.isNull())
4087 return QualType();
4088 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004089
John McCall550e0c22009-10-21 00:40:46 +00004090 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
4091 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004092
John McCall550e0c22009-10-21 00:40:46 +00004093 return Result;
4094}
4095
4096template<typename Derived>
4097QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004098 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004099 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004100 QualType ElementType = getDerived().TransformType(T->getElementType());
4101 if (ElementType.isNull())
4102 return QualType();
4103
4104 QualType Result = TL.getType();
4105 if (getDerived().AlwaysRebuild() ||
4106 ElementType != T->getElementType()) {
4107 Result = getDerived().RebuildExtVectorType(ElementType,
4108 T->getNumElements(),
4109 /*FIXME*/ SourceLocation());
4110 if (Result.isNull())
4111 return QualType();
4112 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004113
John McCall550e0c22009-10-21 00:40:46 +00004114 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4115 NewTL.setNameLoc(TL.getNameLoc());
4116
4117 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004118}
Mike Stump11289f42009-09-09 15:08:12 +00004119
David Blaikie05785d12013-02-20 22:23:23 +00004120template <typename Derived>
4121ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
4122 ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
4123 bool ExpectParameterPack) {
John McCall58f10c32010-03-11 09:03:00 +00004124 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor715e4612011-01-14 22:40:04 +00004125 TypeSourceInfo *NewDI = 0;
Chad Rosier1dcde962012-08-08 18:46:20 +00004126
Douglas Gregor715e4612011-01-14 22:40:04 +00004127 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004128 // If we're substituting into a pack expansion type and we know the
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004129 // length we want to expand to, just substitute for the pattern.
Douglas Gregor715e4612011-01-14 22:40:04 +00004130 TypeLoc OldTL = OldDI->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004131 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004132
Douglas Gregor715e4612011-01-14 22:40:04 +00004133 TypeLocBuilder TLB;
4134 TypeLoc NewTL = OldDI->getTypeLoc();
4135 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00004136
4137 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor715e4612011-01-14 22:40:04 +00004138 OldExpansionTL.getPatternLoc());
4139 if (Result.isNull())
4140 return 0;
Chad Rosier1dcde962012-08-08 18:46:20 +00004141
4142 Result = RebuildPackExpansionType(Result,
4143 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor715e4612011-01-14 22:40:04 +00004144 OldExpansionTL.getEllipsisLoc(),
4145 NumExpansions);
4146 if (Result.isNull())
4147 return 0;
Chad Rosier1dcde962012-08-08 18:46:20 +00004148
Douglas Gregor715e4612011-01-14 22:40:04 +00004149 PackExpansionTypeLoc NewExpansionTL
4150 = TLB.push<PackExpansionTypeLoc>(Result);
4151 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
4152 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
4153 } else
4154 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00004155 if (!NewDI)
4156 return 0;
4157
John McCall8fb0d9d2011-05-01 22:35:37 +00004158 if (NewDI == OldDI && indexAdjustment == 0)
John McCall58f10c32010-03-11 09:03:00 +00004159 return OldParm;
John McCall8fb0d9d2011-05-01 22:35:37 +00004160
4161 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
4162 OldParm->getDeclContext(),
4163 OldParm->getInnerLocStart(),
4164 OldParm->getLocation(),
4165 OldParm->getIdentifier(),
4166 NewDI->getType(),
4167 NewDI,
4168 OldParm->getStorageClass(),
John McCall8fb0d9d2011-05-01 22:35:37 +00004169 /* DefArg */ NULL);
4170 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
4171 OldParm->getFunctionScopeIndex() + indexAdjustment);
4172 return newParm;
John McCall58f10c32010-03-11 09:03:00 +00004173}
4174
4175template<typename Derived>
4176bool TreeTransform<Derived>::
Douglas Gregordd472162011-01-07 00:20:55 +00004177 TransformFunctionTypeParams(SourceLocation Loc,
4178 ParmVarDecl **Params, unsigned NumParams,
4179 const QualType *ParamTypes,
Chris Lattner01cf8db2011-07-20 06:58:45 +00004180 SmallVectorImpl<QualType> &OutParamTypes,
4181 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004182 int indexAdjustment = 0;
4183
Douglas Gregordd472162011-01-07 00:20:55 +00004184 for (unsigned i = 0; i != NumParams; ++i) {
4185 if (ParmVarDecl *OldParm = Params[i]) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004186 assert(OldParm->getFunctionScopeIndex() == i);
4187
David Blaikie05785d12013-02-20 22:23:23 +00004188 Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004189 ParmVarDecl *NewParm = 0;
Douglas Gregor5499af42011-01-05 23:12:31 +00004190 if (OldParm->isParameterPack()) {
4191 // We have a function parameter pack that may need to be expanded.
Chris Lattner01cf8db2011-07-20 06:58:45 +00004192 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00004193
Douglas Gregor5499af42011-01-05 23:12:31 +00004194 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004195 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004196 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004197 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4198 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004199 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4200
Douglas Gregor5499af42011-01-05 23:12:31 +00004201 // Determine whether we should expand the parameter packs.
4202 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004203 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004204 Optional<unsigned> OrigNumExpansions =
4205 ExpansionTL.getTypePtr()->getNumExpansions();
Douglas Gregor715e4612011-01-14 22:40:04 +00004206 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004207 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4208 Pattern.getSourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004209 Unexpanded,
4210 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004211 RetainExpansion,
4212 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004213 return true;
4214 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004215
Douglas Gregor5499af42011-01-05 23:12:31 +00004216 if (ShouldExpand) {
4217 // Expand the function parameter pack into multiple, separate
4218 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00004219 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004220 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004221 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier1dcde962012-08-08 18:46:20 +00004222 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004223 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004224 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004225 OrigNumExpansions,
4226 /*ExpectParameterPack=*/false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004227 if (!NewParm)
4228 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004229
Douglas Gregordd472162011-01-07 00:20:55 +00004230 OutParamTypes.push_back(NewParm->getType());
4231 if (PVars)
4232 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004233 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004234
4235 // If we're supposed to retain a pack expansion, do so by temporarily
4236 // forgetting the partially-substituted parameter pack.
4237 if (RetainExpansion) {
4238 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00004239 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004240 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004241 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004242 OrigNumExpansions,
4243 /*ExpectParameterPack=*/false);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004244 if (!NewParm)
4245 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004246
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004247 OutParamTypes.push_back(NewParm->getType());
4248 if (PVars)
4249 PVars->push_back(NewParm);
4250 }
4251
John McCall8fb0d9d2011-05-01 22:35:37 +00004252 // The next parameter should have the same adjustment as the
4253 // last thing we pushed, but we post-incremented indexAdjustment
4254 // on every push. Also, if we push nothing, the adjustment should
4255 // go down by one.
4256 indexAdjustment--;
4257
Douglas Gregor5499af42011-01-05 23:12:31 +00004258 // We're done with the pack expansion.
4259 continue;
4260 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004261
4262 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004263 // expansion.
Douglas Gregorc52264e2011-03-02 02:04:06 +00004264 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4265 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004266 indexAdjustment,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004267 NumExpansions,
4268 /*ExpectParameterPack=*/true);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004269 } else {
David Blaikie05785d12013-02-20 22:23:23 +00004270 NewParm = getDerived().TransformFunctionTypeParam(
David Blaikie7a30dc52013-02-21 01:47:18 +00004271 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004272 }
Douglas Gregorc52264e2011-03-02 02:04:06 +00004273
John McCall58f10c32010-03-11 09:03:00 +00004274 if (!NewParm)
4275 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004276
Douglas Gregordd472162011-01-07 00:20:55 +00004277 OutParamTypes.push_back(NewParm->getType());
4278 if (PVars)
4279 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004280 continue;
4281 }
John McCall58f10c32010-03-11 09:03:00 +00004282
4283 // Deal with the possibility that we don't have a parameter
4284 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00004285 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00004286 bool IsPackExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004287 Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004288 QualType NewType;
Chad Rosier1dcde962012-08-08 18:46:20 +00004289 if (const PackExpansionType *Expansion
Douglas Gregor5499af42011-01-05 23:12:31 +00004290 = dyn_cast<PackExpansionType>(OldType)) {
4291 // We have a function parameter pack that may need to be expanded.
4292 QualType Pattern = Expansion->getPattern();
Chris Lattner01cf8db2011-07-20 06:58:45 +00004293 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor5499af42011-01-05 23:12:31 +00004294 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00004295
Douglas Gregor5499af42011-01-05 23:12:31 +00004296 // Determine whether we should expand the parameter packs.
4297 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004298 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00004299 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004300 Unexpanded,
4301 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004302 RetainExpansion,
4303 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00004304 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00004305 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004306
Douglas Gregor5499af42011-01-05 23:12:31 +00004307 if (ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004308 // Expand the function parameter pack into multiple, separate
Douglas Gregor5499af42011-01-05 23:12:31 +00004309 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004310 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004311 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4312 QualType NewType = getDerived().TransformType(Pattern);
4313 if (NewType.isNull())
4314 return true;
John McCall58f10c32010-03-11 09:03:00 +00004315
Douglas Gregordd472162011-01-07 00:20:55 +00004316 OutParamTypes.push_back(NewType);
4317 if (PVars)
4318 PVars->push_back(0);
Douglas Gregor5499af42011-01-05 23:12:31 +00004319 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004320
Douglas Gregor5499af42011-01-05 23:12:31 +00004321 // We're done with the pack expansion.
4322 continue;
4323 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004324
Douglas Gregor48d24112011-01-10 20:53:55 +00004325 // If we're supposed to retain a pack expansion, do so by temporarily
4326 // forgetting the partially-substituted parameter pack.
4327 if (RetainExpansion) {
4328 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4329 QualType NewType = getDerived().TransformType(Pattern);
4330 if (NewType.isNull())
4331 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004332
Douglas Gregor48d24112011-01-10 20:53:55 +00004333 OutParamTypes.push_back(NewType);
4334 if (PVars)
4335 PVars->push_back(0);
4336 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004337
Chad Rosier1dcde962012-08-08 18:46:20 +00004338 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004339 // expansion.
4340 OldType = Expansion->getPattern();
4341 IsPackExpansion = true;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004342 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4343 NewType = getDerived().TransformType(OldType);
4344 } else {
4345 NewType = getDerived().TransformType(OldType);
Douglas Gregor5499af42011-01-05 23:12:31 +00004346 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004347
Douglas Gregor5499af42011-01-05 23:12:31 +00004348 if (NewType.isNull())
4349 return true;
4350
4351 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004352 NewType = getSema().Context.getPackExpansionType(NewType,
4353 NumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00004354
Douglas Gregordd472162011-01-07 00:20:55 +00004355 OutParamTypes.push_back(NewType);
4356 if (PVars)
4357 PVars->push_back(0);
John McCall58f10c32010-03-11 09:03:00 +00004358 }
4359
John McCall8fb0d9d2011-05-01 22:35:37 +00004360#ifndef NDEBUG
4361 if (PVars) {
4362 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4363 if (ParmVarDecl *parm = (*PVars)[i])
4364 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor5499af42011-01-05 23:12:31 +00004365 }
John McCall8fb0d9d2011-05-01 22:35:37 +00004366#endif
4367
4368 return false;
4369}
John McCall58f10c32010-03-11 09:03:00 +00004370
4371template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004372QualType
John McCall550e0c22009-10-21 00:40:46 +00004373TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004374 FunctionProtoTypeLoc TL) {
Douglas Gregor3024f072012-04-16 07:05:22 +00004375 return getDerived().TransformFunctionProtoType(TLB, TL, 0, 0);
4376}
4377
4378template<typename Derived>
4379QualType
4380TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
4381 FunctionProtoTypeLoc TL,
4382 CXXRecordDecl *ThisContext,
4383 unsigned ThisTypeQuals) {
Douglas Gregor4afc2362010-08-31 00:26:14 +00004384 // Transform the parameters and return type.
4385 //
Richard Smithf623c962012-04-17 00:58:00 +00004386 // We are required to instantiate the params and return type in source order.
Douglas Gregor7fb25412010-10-01 18:44:50 +00004387 // When the function has a trailing return type, we instantiate the
4388 // parameters before the return type, since the return type can then refer
4389 // to the parameters themselves (via decltype, sizeof, etc.).
4390 //
Chris Lattner01cf8db2011-07-20 06:58:45 +00004391 SmallVector<QualType, 4> ParamTypes;
4392 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall424cec92011-01-19 06:33:43 +00004393 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00004394
Douglas Gregor7fb25412010-10-01 18:44:50 +00004395 QualType ResultType;
4396
Richard Smith1226c602012-08-14 22:51:13 +00004397 if (T->hasTrailingReturn()) {
Alp Toker9cacbab2014-01-20 20:26:09 +00004398 if (getDerived().TransformFunctionTypeParams(
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004399 TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(),
Alp Toker9cacbab2014-01-20 20:26:09 +00004400 TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004401 return QualType();
4402
Douglas Gregor3024f072012-04-16 07:05:22 +00004403 {
4404 // C++11 [expr.prim.general]p3:
Chad Rosier1dcde962012-08-08 18:46:20 +00004405 // If a declaration declares a member function or member function
4406 // template of a class X, the expression this is a prvalue of type
Douglas Gregor3024f072012-04-16 07:05:22 +00004407 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier1dcde962012-08-08 18:46:20 +00004408 // and the end of the function-definition, member-declarator, or
Douglas Gregor3024f072012-04-16 07:05:22 +00004409 // declarator.
4410 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier1dcde962012-08-08 18:46:20 +00004411
Alp Toker42a16a62014-01-25 23:51:36 +00004412 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor3024f072012-04-16 07:05:22 +00004413 if (ResultType.isNull())
4414 return QualType();
4415 }
Douglas Gregor7fb25412010-10-01 18:44:50 +00004416 }
4417 else {
Alp Toker42a16a62014-01-25 23:51:36 +00004418 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00004419 if (ResultType.isNull())
4420 return QualType();
4421
Alp Toker9cacbab2014-01-20 20:26:09 +00004422 if (getDerived().TransformFunctionTypeParams(
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004423 TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(),
Alp Toker9cacbab2014-01-20 20:26:09 +00004424 TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004425 return QualType();
4426 }
4427
Richard Smithf623c962012-04-17 00:58:00 +00004428 // FIXME: Need to transform the exception-specification too.
4429
John McCall550e0c22009-10-21 00:40:46 +00004430 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00004431 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() ||
Alp Toker9cacbab2014-01-20 20:26:09 +00004432 T->getNumParams() != ParamTypes.size() ||
4433 !std::equal(T->param_type_begin(), T->param_type_end(),
4434 ParamTypes.begin())) {
Jordan Rose5c382722013-03-08 21:51:21 +00004435 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +00004436 T->getExtProtoInfo());
John McCall550e0c22009-10-21 00:40:46 +00004437 if (Result.isNull())
4438 return QualType();
4439 }
Mike Stump11289f42009-09-09 15:08:12 +00004440
John McCall550e0c22009-10-21 00:40:46 +00004441 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004442 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00004443 NewTL.setLParenLoc(TL.getLParenLoc());
4444 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004445 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004446 for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i)
4447 NewTL.setParam(i, ParamDecls[i]);
John McCall550e0c22009-10-21 00:40:46 +00004448
4449 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004450}
Mike Stump11289f42009-09-09 15:08:12 +00004451
Douglas Gregord6ff3322009-08-04 16:50:30 +00004452template<typename Derived>
4453QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00004454 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004455 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004456 const FunctionNoProtoType *T = TL.getTypePtr();
Alp Toker42a16a62014-01-25 23:51:36 +00004457 QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
John McCall550e0c22009-10-21 00:40:46 +00004458 if (ResultType.isNull())
4459 return QualType();
4460
4461 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00004462 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType())
John McCall550e0c22009-10-21 00:40:46 +00004463 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4464
4465 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004466 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00004467 NewTL.setLParenLoc(TL.getLParenLoc());
4468 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004469 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCall550e0c22009-10-21 00:40:46 +00004470
4471 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004472}
Mike Stump11289f42009-09-09 15:08:12 +00004473
John McCallb96ec562009-12-04 22:46:56 +00004474template<typename Derived> QualType
4475TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004476 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004477 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004478 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00004479 if (!D)
4480 return QualType();
4481
4482 QualType Result = TL.getType();
4483 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4484 Result = getDerived().RebuildUnresolvedUsingType(D);
4485 if (Result.isNull())
4486 return QualType();
4487 }
4488
4489 // We might get an arbitrary type spec type back. We should at
4490 // least always get a type spec type, though.
4491 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4492 NewTL.setNameLoc(TL.getNameLoc());
4493
4494 return Result;
4495}
4496
Douglas Gregord6ff3322009-08-04 16:50:30 +00004497template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004498QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004499 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004500 const TypedefType *T = TL.getTypePtr();
Richard Smithdda56e42011-04-15 14:24:37 +00004501 TypedefNameDecl *Typedef
4502 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4503 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004504 if (!Typedef)
4505 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004506
John McCall550e0c22009-10-21 00:40:46 +00004507 QualType Result = TL.getType();
4508 if (getDerived().AlwaysRebuild() ||
4509 Typedef != T->getDecl()) {
4510 Result = getDerived().RebuildTypedefType(Typedef);
4511 if (Result.isNull())
4512 return QualType();
4513 }
Mike Stump11289f42009-09-09 15:08:12 +00004514
John McCall550e0c22009-10-21 00:40:46 +00004515 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4516 NewTL.setNameLoc(TL.getNameLoc());
4517
4518 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004519}
Mike Stump11289f42009-09-09 15:08:12 +00004520
Douglas Gregord6ff3322009-08-04 16:50:30 +00004521template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004522QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004523 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00004524 // typeof expressions are not potentially evaluated contexts
Eli Friedman15681d62012-09-26 04:34:21 +00004525 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4526 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00004527
John McCalldadc5752010-08-24 06:29:42 +00004528 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004529 if (E.isInvalid())
4530 return QualType();
4531
Eli Friedmane4f22df2012-02-29 04:03:55 +00004532 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
4533 if (E.isInvalid())
4534 return QualType();
4535
John McCall550e0c22009-10-21 00:40:46 +00004536 QualType Result = TL.getType();
4537 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00004538 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004539 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00004540 if (Result.isNull())
4541 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004542 }
John McCall550e0c22009-10-21 00:40:46 +00004543 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00004544
John McCall550e0c22009-10-21 00:40:46 +00004545 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004546 NewTL.setTypeofLoc(TL.getTypeofLoc());
4547 NewTL.setLParenLoc(TL.getLParenLoc());
4548 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00004549
4550 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004551}
Mike Stump11289f42009-09-09 15:08:12 +00004552
4553template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004554QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004555 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00004556 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4557 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4558 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00004559 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004560
John McCall550e0c22009-10-21 00:40:46 +00004561 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00004562 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4563 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00004564 if (Result.isNull())
4565 return QualType();
4566 }
Mike Stump11289f42009-09-09 15:08:12 +00004567
John McCall550e0c22009-10-21 00:40:46 +00004568 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004569 NewTL.setTypeofLoc(TL.getTypeofLoc());
4570 NewTL.setLParenLoc(TL.getLParenLoc());
4571 NewTL.setRParenLoc(TL.getRParenLoc());
4572 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00004573
4574 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004575}
Mike Stump11289f42009-09-09 15:08:12 +00004576
4577template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004578QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004579 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004580 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004581
Douglas Gregore922c772009-08-04 22:27:00 +00004582 // decltype expressions are not potentially evaluated contexts
Richard Smithfd555f62012-02-22 02:04:18 +00004583 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, 0,
4584 /*IsDecltype=*/ true);
Mike Stump11289f42009-09-09 15:08:12 +00004585
John McCalldadc5752010-08-24 06:29:42 +00004586 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004587 if (E.isInvalid())
4588 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004589
Richard Smithfd555f62012-02-22 02:04:18 +00004590 E = getSema().ActOnDecltypeExpression(E.take());
4591 if (E.isInvalid())
4592 return QualType();
4593
John McCall550e0c22009-10-21 00:40:46 +00004594 QualType Result = TL.getType();
4595 if (getDerived().AlwaysRebuild() ||
4596 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004597 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004598 if (Result.isNull())
4599 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004600 }
John McCall550e0c22009-10-21 00:40:46 +00004601 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00004602
John McCall550e0c22009-10-21 00:40:46 +00004603 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4604 NewTL.setNameLoc(TL.getNameLoc());
4605
4606 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004607}
4608
4609template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00004610QualType TreeTransform<Derived>::TransformUnaryTransformType(
4611 TypeLocBuilder &TLB,
4612 UnaryTransformTypeLoc TL) {
4613 QualType Result = TL.getType();
4614 if (Result->isDependentType()) {
4615 const UnaryTransformType *T = TL.getTypePtr();
4616 QualType NewBase =
4617 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4618 Result = getDerived().RebuildUnaryTransformType(NewBase,
4619 T->getUTTKind(),
4620 TL.getKWLoc());
4621 if (Result.isNull())
4622 return QualType();
4623 }
4624
4625 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4626 NewTL.setKWLoc(TL.getKWLoc());
4627 NewTL.setParensRange(TL.getParensRange());
4628 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4629 return Result;
4630}
4631
4632template<typename Derived>
Richard Smith30482bc2011-02-20 03:19:35 +00004633QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4634 AutoTypeLoc TL) {
4635 const AutoType *T = TL.getTypePtr();
4636 QualType OldDeduced = T->getDeducedType();
4637 QualType NewDeduced;
4638 if (!OldDeduced.isNull()) {
4639 NewDeduced = getDerived().TransformType(OldDeduced);
4640 if (NewDeduced.isNull())
4641 return QualType();
4642 }
4643
4644 QualType Result = TL.getType();
Richard Smith27d807c2013-04-30 13:56:41 +00004645 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
4646 T->isDependentType()) {
Richard Smith74aeef52013-04-26 16:15:35 +00004647 Result = getDerived().RebuildAutoType(NewDeduced, T->isDecltypeAuto());
Richard Smith30482bc2011-02-20 03:19:35 +00004648 if (Result.isNull())
4649 return QualType();
4650 }
4651
4652 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4653 NewTL.setNameLoc(TL.getNameLoc());
4654
4655 return Result;
4656}
4657
4658template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004659QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004660 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004661 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004662 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004663 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4664 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004665 if (!Record)
4666 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004667
John McCall550e0c22009-10-21 00:40:46 +00004668 QualType Result = TL.getType();
4669 if (getDerived().AlwaysRebuild() ||
4670 Record != T->getDecl()) {
4671 Result = getDerived().RebuildRecordType(Record);
4672 if (Result.isNull())
4673 return QualType();
4674 }
Mike Stump11289f42009-09-09 15:08:12 +00004675
John McCall550e0c22009-10-21 00:40:46 +00004676 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4677 NewTL.setNameLoc(TL.getNameLoc());
4678
4679 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004680}
Mike Stump11289f42009-09-09 15:08:12 +00004681
4682template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004683QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004684 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004685 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004686 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004687 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4688 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004689 if (!Enum)
4690 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004691
John McCall550e0c22009-10-21 00:40:46 +00004692 QualType Result = TL.getType();
4693 if (getDerived().AlwaysRebuild() ||
4694 Enum != T->getDecl()) {
4695 Result = getDerived().RebuildEnumType(Enum);
4696 if (Result.isNull())
4697 return QualType();
4698 }
Mike Stump11289f42009-09-09 15:08:12 +00004699
John McCall550e0c22009-10-21 00:40:46 +00004700 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4701 NewTL.setNameLoc(TL.getNameLoc());
4702
4703 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004704}
John McCallfcc33b02009-09-05 00:15:47 +00004705
John McCalle78aac42010-03-10 03:28:59 +00004706template<typename Derived>
4707QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4708 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004709 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00004710 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4711 TL.getTypePtr()->getDecl());
4712 if (!D) return QualType();
4713
4714 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4715 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4716 return T;
4717}
4718
Douglas Gregord6ff3322009-08-04 16:50:30 +00004719template<typename Derived>
4720QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004721 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004722 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004723 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004724}
4725
Mike Stump11289f42009-09-09 15:08:12 +00004726template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00004727QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004728 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004729 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004730 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00004731
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004732 // Substitute into the replacement type, which itself might involve something
4733 // that needs to be transformed. This only tends to occur with default
4734 // template arguments of template template parameters.
4735 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4736 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4737 if (Replacement.isNull())
4738 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00004739
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004740 // Always canonicalize the replacement type.
4741 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4742 QualType Result
Chad Rosier1dcde962012-08-08 18:46:20 +00004743 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004744 Replacement);
Chad Rosier1dcde962012-08-08 18:46:20 +00004745
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004746 // Propagate type-source information.
4747 SubstTemplateTypeParmTypeLoc NewTL
4748 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4749 NewTL.setNameLoc(TL.getNameLoc());
4750 return Result;
4751
John McCallcebee162009-10-18 09:09:24 +00004752}
4753
4754template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00004755QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4756 TypeLocBuilder &TLB,
4757 SubstTemplateTypeParmPackTypeLoc TL) {
4758 return TransformTypeSpecType(TLB, TL);
4759}
4760
4761template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00004762QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00004763 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004764 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00004765 const TemplateSpecializationType *T = TL.getTypePtr();
4766
Douglas Gregordf846d12011-03-02 18:46:51 +00004767 // The nested-name-specifier never matters in a TemplateSpecializationType,
4768 // because we can't have a dependent nested-name-specifier anyway.
4769 CXXScopeSpec SS;
Mike Stump11289f42009-09-09 15:08:12 +00004770 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00004771 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4772 TL.getTemplateNameLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004773 if (Template.isNull())
4774 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004775
John McCall31f82722010-11-12 08:19:04 +00004776 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4777}
4778
Eli Friedman0dfb8892011-10-06 23:00:33 +00004779template<typename Derived>
4780QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
4781 AtomicTypeLoc TL) {
4782 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
4783 if (ValueType.isNull())
4784 return QualType();
4785
4786 QualType Result = TL.getType();
4787 if (getDerived().AlwaysRebuild() ||
4788 ValueType != TL.getValueLoc().getType()) {
4789 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
4790 if (Result.isNull())
4791 return QualType();
4792 }
4793
4794 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
4795 NewTL.setKWLoc(TL.getKWLoc());
4796 NewTL.setLParenLoc(TL.getLParenLoc());
4797 NewTL.setRParenLoc(TL.getRParenLoc());
4798
4799 return Result;
4800}
4801
Chad Rosier1dcde962012-08-08 18:46:20 +00004802 /// \brief Simple iterator that traverses the template arguments in a
Douglas Gregorfe921a72010-12-20 23:36:19 +00004803 /// container that provides a \c getArgLoc() member function.
4804 ///
4805 /// This iterator is intended to be used with the iterator form of
4806 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4807 template<typename ArgLocContainer>
4808 class TemplateArgumentLocContainerIterator {
4809 ArgLocContainer *Container;
4810 unsigned Index;
Chad Rosier1dcde962012-08-08 18:46:20 +00004811
Douglas Gregorfe921a72010-12-20 23:36:19 +00004812 public:
4813 typedef TemplateArgumentLoc value_type;
4814 typedef TemplateArgumentLoc reference;
4815 typedef int difference_type;
4816 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00004817
Douglas Gregorfe921a72010-12-20 23:36:19 +00004818 class pointer {
4819 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00004820
Douglas Gregorfe921a72010-12-20 23:36:19 +00004821 public:
4822 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00004823
Douglas Gregorfe921a72010-12-20 23:36:19 +00004824 const TemplateArgumentLoc *operator->() const {
4825 return &Arg;
4826 }
4827 };
Chad Rosier1dcde962012-08-08 18:46:20 +00004828
4829
Douglas Gregorfe921a72010-12-20 23:36:19 +00004830 TemplateArgumentLocContainerIterator() {}
Chad Rosier1dcde962012-08-08 18:46:20 +00004831
Douglas Gregorfe921a72010-12-20 23:36:19 +00004832 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4833 unsigned Index)
4834 : Container(&Container), Index(Index) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00004835
Douglas Gregorfe921a72010-12-20 23:36:19 +00004836 TemplateArgumentLocContainerIterator &operator++() {
4837 ++Index;
4838 return *this;
4839 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004840
Douglas Gregorfe921a72010-12-20 23:36:19 +00004841 TemplateArgumentLocContainerIterator operator++(int) {
4842 TemplateArgumentLocContainerIterator Old(*this);
4843 ++(*this);
4844 return Old;
4845 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004846
Douglas Gregorfe921a72010-12-20 23:36:19 +00004847 TemplateArgumentLoc operator*() const {
4848 return Container->getArgLoc(Index);
4849 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004850
Douglas Gregorfe921a72010-12-20 23:36:19 +00004851 pointer operator->() const {
4852 return pointer(Container->getArgLoc(Index));
4853 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004854
Douglas Gregorfe921a72010-12-20 23:36:19 +00004855 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004856 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004857 return X.Container == Y.Container && X.Index == Y.Index;
4858 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004859
Douglas Gregorfe921a72010-12-20 23:36:19 +00004860 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004861 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004862 return !(X == Y);
4863 }
4864 };
Chad Rosier1dcde962012-08-08 18:46:20 +00004865
4866
John McCall31f82722010-11-12 08:19:04 +00004867template <typename Derived>
4868QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4869 TypeLocBuilder &TLB,
4870 TemplateSpecializationTypeLoc TL,
4871 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00004872 TemplateArgumentListInfo NewTemplateArgs;
4873 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4874 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00004875 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4876 ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00004877 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregorfe921a72010-12-20 23:36:19 +00004878 ArgIterator(TL, TL.getNumArgs()),
4879 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00004880 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004881
John McCall0ad16662009-10-29 08:12:44 +00004882 // FIXME: maybe don't rebuild if all the template arguments are the same.
4883
4884 QualType Result =
4885 getDerived().RebuildTemplateSpecializationType(Template,
4886 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00004887 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00004888
4889 if (!Result.isNull()) {
Richard Smith3f1b5d02011-05-05 21:57:07 +00004890 // Specializations of template template parameters are represented as
4891 // TemplateSpecializationTypes, and substitution of type alias templates
4892 // within a dependent context can transform them into
4893 // DependentTemplateSpecializationTypes.
4894 if (isa<DependentTemplateSpecializationType>(Result)) {
4895 DependentTemplateSpecializationTypeLoc NewTL
4896 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004897 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3f1b5d02011-05-05 21:57:07 +00004898 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00004899 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004900 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3f1b5d02011-05-05 21:57:07 +00004901 NewTL.setLAngleLoc(TL.getLAngleLoc());
4902 NewTL.setRAngleLoc(TL.getRAngleLoc());
4903 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4904 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4905 return Result;
4906 }
4907
John McCall0ad16662009-10-29 08:12:44 +00004908 TemplateSpecializationTypeLoc NewTL
4909 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004910 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall0ad16662009-10-29 08:12:44 +00004911 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4912 NewTL.setLAngleLoc(TL.getLAngleLoc());
4913 NewTL.setRAngleLoc(TL.getRAngleLoc());
4914 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4915 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004916 }
Mike Stump11289f42009-09-09 15:08:12 +00004917
John McCall0ad16662009-10-29 08:12:44 +00004918 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004919}
Mike Stump11289f42009-09-09 15:08:12 +00004920
Douglas Gregor5a064722011-02-28 17:23:35 +00004921template <typename Derived>
4922QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4923 TypeLocBuilder &TLB,
4924 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +00004925 TemplateName Template,
4926 CXXScopeSpec &SS) {
Douglas Gregor5a064722011-02-28 17:23:35 +00004927 TemplateArgumentListInfo NewTemplateArgs;
4928 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4929 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4930 typedef TemplateArgumentLocContainerIterator<
4931 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00004932 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor5a064722011-02-28 17:23:35 +00004933 ArgIterator(TL, TL.getNumArgs()),
4934 NewTemplateArgs))
4935 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00004936
Douglas Gregor5a064722011-02-28 17:23:35 +00004937 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier1dcde962012-08-08 18:46:20 +00004938
Douglas Gregor5a064722011-02-28 17:23:35 +00004939 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4940 QualType Result
4941 = getSema().Context.getDependentTemplateSpecializationType(
4942 TL.getTypePtr()->getKeyword(),
4943 DTN->getQualifier(),
4944 DTN->getIdentifier(),
4945 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00004946
Douglas Gregor5a064722011-02-28 17:23:35 +00004947 DependentTemplateSpecializationTypeLoc NewTL
4948 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004949 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004950 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00004951 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004952 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00004953 NewTL.setLAngleLoc(TL.getLAngleLoc());
4954 NewTL.setRAngleLoc(TL.getRAngleLoc());
4955 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4956 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4957 return Result;
4958 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004959
4960 QualType Result
Douglas Gregor5a064722011-02-28 17:23:35 +00004961 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004962 TL.getTemplateNameLoc(),
Douglas Gregor5a064722011-02-28 17:23:35 +00004963 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00004964
Douglas Gregor5a064722011-02-28 17:23:35 +00004965 if (!Result.isNull()) {
4966 /// FIXME: Wrap this in an elaborated-type-specifier?
4967 TemplateSpecializationTypeLoc NewTL
4968 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00004969 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004970 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00004971 NewTL.setLAngleLoc(TL.getLAngleLoc());
4972 NewTL.setRAngleLoc(TL.getRAngleLoc());
4973 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4974 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4975 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004976
Douglas Gregor5a064722011-02-28 17:23:35 +00004977 return Result;
4978}
4979
Mike Stump11289f42009-09-09 15:08:12 +00004980template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004981QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00004982TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004983 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004984 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00004985
Douglas Gregor844cb502011-03-01 18:12:44 +00004986 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara6150c882010-05-11 21:36:43 +00004987 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor844cb502011-03-01 18:12:44 +00004988 if (TL.getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004989 QualifierLoc
Douglas Gregor844cb502011-03-01 18:12:44 +00004990 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4991 if (!QualifierLoc)
Abramo Bagnara6150c882010-05-11 21:36:43 +00004992 return QualType();
4993 }
Mike Stump11289f42009-09-09 15:08:12 +00004994
John McCall31f82722010-11-12 08:19:04 +00004995 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4996 if (NamedT.isNull())
4997 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00004998
Richard Smith3f1b5d02011-05-05 21:57:07 +00004999 // C++0x [dcl.type.elab]p2:
5000 // If the identifier resolves to a typedef-name or the simple-template-id
5001 // resolves to an alias template specialization, the
5002 // elaborated-type-specifier is ill-formed.
Richard Smith0c4a34b2011-05-14 15:04:18 +00005003 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
5004 if (const TemplateSpecializationType *TST =
5005 NamedT->getAs<TemplateSpecializationType>()) {
5006 TemplateName Template = TST->getTemplateName();
5007 if (TypeAliasTemplateDecl *TAT =
5008 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
5009 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
5010 diag::err_tag_reference_non_tag) << 4;
5011 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
5012 }
Richard Smith3f1b5d02011-05-05 21:57:07 +00005013 }
5014 }
5015
John McCall550e0c22009-10-21 00:40:46 +00005016 QualType Result = TL.getType();
5017 if (getDerived().AlwaysRebuild() ||
Douglas Gregor844cb502011-03-01 18:12:44 +00005018 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00005019 NamedT != T->getNamedType()) {
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005020 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00005021 T->getKeyword(),
Douglas Gregor844cb502011-03-01 18:12:44 +00005022 QualifierLoc, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00005023 if (Result.isNull())
5024 return QualType();
5025 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00005026
Abramo Bagnara6150c882010-05-11 21:36:43 +00005027 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005028 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005029 NewTL.setQualifierLoc(QualifierLoc);
John McCall550e0c22009-10-21 00:40:46 +00005030 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005031}
Mike Stump11289f42009-09-09 15:08:12 +00005032
5033template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00005034QualType TreeTransform<Derived>::TransformAttributedType(
5035 TypeLocBuilder &TLB,
5036 AttributedTypeLoc TL) {
5037 const AttributedType *oldType = TL.getTypePtr();
5038 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
5039 if (modifiedType.isNull())
5040 return QualType();
5041
5042 QualType result = TL.getType();
5043
5044 // FIXME: dependent operand expressions?
5045 if (getDerived().AlwaysRebuild() ||
5046 modifiedType != oldType->getModifiedType()) {
5047 // TODO: this is really lame; we should really be rebuilding the
5048 // equivalent type from first principles.
5049 QualType equivalentType
5050 = getDerived().TransformType(oldType->getEquivalentType());
5051 if (equivalentType.isNull())
5052 return QualType();
5053 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
5054 modifiedType,
5055 equivalentType);
5056 }
5057
5058 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
5059 newTL.setAttrNameLoc(TL.getAttrNameLoc());
5060 if (TL.hasAttrOperand())
5061 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5062 if (TL.hasAttrExprOperand())
5063 newTL.setAttrExprOperand(TL.getAttrExprOperand());
5064 else if (TL.hasAttrEnumOperand())
5065 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
5066
5067 return result;
5068}
5069
5070template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00005071QualType
5072TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
5073 ParenTypeLoc TL) {
5074 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
5075 if (Inner.isNull())
5076 return QualType();
5077
5078 QualType Result = TL.getType();
5079 if (getDerived().AlwaysRebuild() ||
5080 Inner != TL.getInnerLoc().getType()) {
5081 Result = getDerived().RebuildParenType(Inner);
5082 if (Result.isNull())
5083 return QualType();
5084 }
5085
5086 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
5087 NewTL.setLParenLoc(TL.getLParenLoc());
5088 NewTL.setRParenLoc(TL.getRParenLoc());
5089 return Result;
5090}
5091
5092template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00005093QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005094 DependentNameTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005095 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00005096
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005097 NestedNameSpecifierLoc QualifierLoc
5098 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5099 if (!QualifierLoc)
Douglas Gregord6ff3322009-08-04 16:50:30 +00005100 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005101
John McCallc392f372010-06-11 00:33:02 +00005102 QualType Result
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005103 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005104 TL.getElaboratedKeywordLoc(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005105 QualifierLoc,
5106 T->getIdentifier(),
John McCallc392f372010-06-11 00:33:02 +00005107 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00005108 if (Result.isNull())
5109 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005110
Abramo Bagnarad7548482010-05-19 21:37:53 +00005111 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
5112 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00005113 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
5114
Abramo Bagnarad7548482010-05-19 21:37:53 +00005115 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005116 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005117 NewTL.setQualifierLoc(QualifierLoc);
John McCallc392f372010-06-11 00:33:02 +00005118 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00005119 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005120 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005121 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00005122 NewTL.setNameLoc(TL.getNameLoc());
5123 }
John McCall550e0c22009-10-21 00:40:46 +00005124 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005125}
Mike Stump11289f42009-09-09 15:08:12 +00005126
Douglas Gregord6ff3322009-08-04 16:50:30 +00005127template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00005128QualType TreeTransform<Derived>::
5129 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005130 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregora7a795b2011-03-01 20:11:18 +00005131 NestedNameSpecifierLoc QualifierLoc;
5132 if (TL.getQualifierLoc()) {
5133 QualifierLoc
5134 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5135 if (!QualifierLoc)
Douglas Gregor5a064722011-02-28 17:23:35 +00005136 return QualType();
5137 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005138
John McCall31f82722010-11-12 08:19:04 +00005139 return getDerived()
Douglas Gregora7a795b2011-03-01 20:11:18 +00005140 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall31f82722010-11-12 08:19:04 +00005141}
5142
5143template<typename Derived>
5144QualType TreeTransform<Derived>::
Douglas Gregora7a795b2011-03-01 20:11:18 +00005145TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
5146 DependentTemplateSpecializationTypeLoc TL,
5147 NestedNameSpecifierLoc QualifierLoc) {
5148 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00005149
Douglas Gregora7a795b2011-03-01 20:11:18 +00005150 TemplateArgumentListInfo NewTemplateArgs;
5151 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5152 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00005153
Douglas Gregora7a795b2011-03-01 20:11:18 +00005154 typedef TemplateArgumentLocContainerIterator<
5155 DependentTemplateSpecializationTypeLoc> ArgIterator;
5156 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5157 ArgIterator(TL, TL.getNumArgs()),
5158 NewTemplateArgs))
5159 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005160
Douglas Gregora7a795b2011-03-01 20:11:18 +00005161 QualType Result
5162 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
5163 QualifierLoc,
5164 T->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005165 TL.getTemplateNameLoc(),
Douglas Gregora7a795b2011-03-01 20:11:18 +00005166 NewTemplateArgs);
5167 if (Result.isNull())
5168 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005169
Douglas Gregora7a795b2011-03-01 20:11:18 +00005170 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
5171 QualType NamedT = ElabT->getNamedType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005172
Douglas Gregora7a795b2011-03-01 20:11:18 +00005173 // Copy information relevant to the template specialization.
5174 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor43f788f2011-03-07 02:33:33 +00005175 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005176 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005177 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005178 NamedTL.setLAngleLoc(TL.getLAngleLoc());
5179 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005180 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005181 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier1dcde962012-08-08 18:46:20 +00005182
Douglas Gregora7a795b2011-03-01 20:11:18 +00005183 // Copy information relevant to the elaborated type.
5184 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005185 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005186 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor43f788f2011-03-07 02:33:33 +00005187 } else if (isa<DependentTemplateSpecializationType>(Result)) {
5188 DependentTemplateSpecializationTypeLoc SpecTL
5189 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005190 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005191 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005192 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005193 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005194 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5195 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005196 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005197 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005198 } else {
Douglas Gregor43f788f2011-03-07 02:33:33 +00005199 TemplateSpecializationTypeLoc SpecTL
5200 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005201 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005202 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005203 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5204 SpecTL.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 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005207 }
5208 return Result;
5209}
5210
5211template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00005212QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5213 PackExpansionTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005214 QualType Pattern
5215 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor822d0302011-01-12 17:07:58 +00005216 if (Pattern.isNull())
5217 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005218
5219 QualType Result = TL.getType();
Douglas Gregor822d0302011-01-12 17:07:58 +00005220 if (getDerived().AlwaysRebuild() ||
5221 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005222 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00005223 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00005224 TL.getEllipsisLoc(),
5225 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00005226 if (Result.isNull())
5227 return QualType();
5228 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005229
Douglas Gregor822d0302011-01-12 17:07:58 +00005230 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5231 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5232 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00005233}
5234
5235template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005236QualType
5237TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005238 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005239 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00005240 TLB.pushFullCopy(TL);
5241 return TL.getType();
5242}
5243
5244template<typename Derived>
5245QualType
5246TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005247 ObjCObjectTypeLoc TL) {
John McCall8b07ec22010-05-15 11:32:37 +00005248 // ObjCObjectType is never dependent.
5249 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00005250 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005251}
Mike Stump11289f42009-09-09 15:08:12 +00005252
5253template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005254QualType
5255TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005256 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005257 // ObjCObjectPointerType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00005258 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00005259 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00005260}
5261
Douglas Gregord6ff3322009-08-04 16:50:30 +00005262//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00005263// Statement transformation
5264//===----------------------------------------------------------------------===//
5265template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005266StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005267TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00005268 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005269}
5270
5271template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005272StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005273TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
5274 return getDerived().TransformCompoundStmt(S, false);
5275}
5276
5277template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005278StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005279TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00005280 bool IsStmtExpr) {
Dmitri Gribenko800ddf32012-02-14 22:14:32 +00005281 Sema::CompoundScopeRAII CompoundScope(getSema());
5282
John McCall1ababa62010-08-27 19:56:05 +00005283 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00005284 bool SubStmtChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005285 SmallVector<Stmt*, 8> Statements;
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005286 for (auto *B : S->body()) {
5287 StmtResult Result = getDerived().TransformStmt(B);
John McCall1ababa62010-08-27 19:56:05 +00005288 if (Result.isInvalid()) {
5289 // Immediately fail if this was a DeclStmt, since it's very
5290 // likely that this will cause problems for future statements.
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005291 if (isa<DeclStmt>(B))
John McCall1ababa62010-08-27 19:56:05 +00005292 return StmtError();
5293
5294 // Otherwise, just keep processing substatements and fail later.
5295 SubStmtInvalid = true;
5296 continue;
5297 }
Mike Stump11289f42009-09-09 15:08:12 +00005298
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005299 SubStmtChanged = SubStmtChanged || Result.get() != B;
Douglas Gregorebe10102009-08-20 07:17:43 +00005300 Statements.push_back(Result.takeAs<Stmt>());
5301 }
Mike Stump11289f42009-09-09 15:08:12 +00005302
John McCall1ababa62010-08-27 19:56:05 +00005303 if (SubStmtInvalid)
5304 return StmtError();
5305
Douglas Gregorebe10102009-08-20 07:17:43 +00005306 if (!getDerived().AlwaysRebuild() &&
5307 !SubStmtChanged)
John McCallc3007a22010-10-26 07:05:15 +00005308 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005309
5310 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00005311 Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00005312 S->getRBracLoc(),
5313 IsStmtExpr);
5314}
Mike Stump11289f42009-09-09 15:08:12 +00005315
Douglas Gregorebe10102009-08-20 07:17:43 +00005316template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005317StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005318TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005319 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00005320 {
Eli Friedman1f4f9dd2012-01-18 02:54:10 +00005321 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5322 Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005323
Eli Friedman06577382009-11-19 03:14:00 +00005324 // Transform the left-hand case value.
5325 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00005326 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman06577382009-11-19 03:14:00 +00005327 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005328 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005329
Eli Friedman06577382009-11-19 03:14:00 +00005330 // Transform the right-hand case value (for the GNU case-range extension).
5331 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00005332 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman06577382009-11-19 03:14:00 +00005333 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005334 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00005335 }
Mike Stump11289f42009-09-09 15:08:12 +00005336
Douglas Gregorebe10102009-08-20 07:17:43 +00005337 // Build the case statement.
5338 // Case statements are always rebuilt so that they will attached to their
5339 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005340 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00005341 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005342 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00005343 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005344 S->getColonLoc());
5345 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005346 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005347
Douglas Gregorebe10102009-08-20 07:17:43 +00005348 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00005349 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005350 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005351 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005352
Douglas Gregorebe10102009-08-20 07:17:43 +00005353 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00005354 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005355}
5356
5357template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005358StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005359TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005360 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00005361 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005362 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005363 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005364
Douglas Gregorebe10102009-08-20 07:17:43 +00005365 // Default statements are always rebuilt
5366 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00005367 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005368}
Mike Stump11289f42009-09-09 15:08:12 +00005369
Douglas Gregorebe10102009-08-20 07:17:43 +00005370template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005371StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005372TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005373 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005374 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005375 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005376
Chris Lattnercab02a62011-02-17 20:34:02 +00005377 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5378 S->getDecl());
5379 if (!LD)
5380 return StmtError();
Richard Smithc202b282012-04-14 00:33:13 +00005381
5382
Douglas Gregorebe10102009-08-20 07:17:43 +00005383 // FIXME: Pass the real colon location in.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00005384 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005385 cast<LabelDecl>(LD), SourceLocation(),
5386 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005387}
Mike Stump11289f42009-09-09 15:08:12 +00005388
Douglas Gregorebe10102009-08-20 07:17:43 +00005389template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005390StmtResult
Richard Smithc202b282012-04-14 00:33:13 +00005391TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
5392 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5393 if (SubStmt.isInvalid())
5394 return StmtError();
5395
5396 // TODO: transform attributes
5397 if (SubStmt.get() == S->getSubStmt() /* && attrs are the same */)
5398 return S;
5399
5400 return getDerived().RebuildAttributedStmt(S->getAttrLoc(),
5401 S->getAttrs(),
5402 SubStmt.get());
5403}
5404
5405template<typename Derived>
5406StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005407TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005408 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005409 ExprResult Cond;
Douglas Gregor633caca2009-11-23 23:44:04 +00005410 VarDecl *ConditionVar = 0;
5411 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005412 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00005413 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005414 getDerived().TransformDefinition(
5415 S->getConditionVariable()->getLocation(),
5416 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00005417 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005418 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005419 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00005420 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005421
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005422 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005423 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005424
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005425 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00005426 if (S->getCond()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005427 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005428 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005429 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005430 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005431
John McCallb268a282010-08-23 23:25:46 +00005432 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005433 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005434 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005435
John McCallb268a282010-08-23 23:25:46 +00005436 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5437 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005438 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005439
Douglas Gregorebe10102009-08-20 07:17:43 +00005440 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00005441 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00005442 if (Then.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005443 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005444
Douglas Gregorebe10102009-08-20 07:17:43 +00005445 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00005446 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00005447 if (Else.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005448 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005449
Douglas Gregorebe10102009-08-20 07:17:43 +00005450 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00005451 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005452 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005453 Then.get() == S->getThen() &&
5454 Else.get() == S->getElse())
John McCallc3007a22010-10-26 07:05:15 +00005455 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005456
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005457 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00005458 Then.get(),
John McCallb268a282010-08-23 23:25:46 +00005459 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005460}
5461
5462template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005463StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005464TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005465 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00005466 ExprResult Cond;
Douglas Gregordcf19622009-11-24 17:07:59 +00005467 VarDecl *ConditionVar = 0;
5468 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005469 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00005470 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005471 getDerived().TransformDefinition(
5472 S->getConditionVariable()->getLocation(),
5473 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00005474 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005475 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005476 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00005477 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005478
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005479 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005480 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005481 }
Mike Stump11289f42009-09-09 15:08:12 +00005482
Douglas Gregorebe10102009-08-20 07:17:43 +00005483 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005484 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00005485 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00005486 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00005487 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005488 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005489
Douglas Gregorebe10102009-08-20 07:17:43 +00005490 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005491 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005492 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005493 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005494
Douglas Gregorebe10102009-08-20 07:17:43 +00005495 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00005496 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5497 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005498}
Mike Stump11289f42009-09-09 15:08:12 +00005499
Douglas Gregorebe10102009-08-20 07:17:43 +00005500template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005501StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005502TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005503 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005504 ExprResult Cond;
Douglas Gregor680f8612009-11-24 21:15:44 +00005505 VarDecl *ConditionVar = 0;
5506 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005507 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00005508 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005509 getDerived().TransformDefinition(
5510 S->getConditionVariable()->getLocation(),
5511 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00005512 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005513 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005514 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00005515 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005516
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005517 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005518 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005519
5520 if (S->getCond()) {
5521 // Convert the condition to a boolean value.
Chad Rosier1dcde962012-08-08 18:46:20 +00005522 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005523 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005524 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005525 return StmtError();
John McCallb268a282010-08-23 23:25:46 +00005526 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00005527 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005528 }
Mike Stump11289f42009-09-09 15:08:12 +00005529
John McCallb268a282010-08-23 23:25:46 +00005530 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5531 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005532 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005533
Douglas Gregorebe10102009-08-20 07:17:43 +00005534 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005535 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005536 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005537 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005538
Douglas Gregorebe10102009-08-20 07:17:43 +00005539 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00005540 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005541 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005542 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00005543 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005544
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005545 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00005546 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005547}
Mike Stump11289f42009-09-09 15:08:12 +00005548
Douglas Gregorebe10102009-08-20 07:17:43 +00005549template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005550StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005551TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005552 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005553 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005554 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005555 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005556
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005557 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005558 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005559 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005560 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005561
Douglas Gregorebe10102009-08-20 07:17:43 +00005562 if (!getDerived().AlwaysRebuild() &&
5563 Cond.get() == S->getCond() &&
5564 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005565 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005566
John McCallb268a282010-08-23 23:25:46 +00005567 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5568 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005569 S->getRParenLoc());
5570}
Mike Stump11289f42009-09-09 15:08:12 +00005571
Douglas Gregorebe10102009-08-20 07:17:43 +00005572template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005573StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005574TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005575 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00005576 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00005577 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005578 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005579
Douglas Gregorebe10102009-08-20 07:17:43 +00005580 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005581 ExprResult Cond;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005582 VarDecl *ConditionVar = 0;
5583 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005584 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005585 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005586 getDerived().TransformDefinition(
5587 S->getConditionVariable()->getLocation(),
5588 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005589 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005590 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005591 } else {
5592 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005593
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005594 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005595 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005596
5597 if (S->getCond()) {
5598 // Convert the condition to a boolean value.
Chad Rosier1dcde962012-08-08 18:46:20 +00005599 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005600 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005601 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005602 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005603
John McCallb268a282010-08-23 23:25:46 +00005604 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005605 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005606 }
Mike Stump11289f42009-09-09 15:08:12 +00005607
Chad Rosier1dcde962012-08-08 18:46:20 +00005608 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
John McCallb268a282010-08-23 23:25:46 +00005609 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005610 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005611
Douglas Gregorebe10102009-08-20 07:17:43 +00005612 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00005613 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005614 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005615 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005616
Richard Smith945f8d32013-01-14 22:39:08 +00005617 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
John McCallb268a282010-08-23 23:25:46 +00005618 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005619 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005620
Douglas Gregorebe10102009-08-20 07:17:43 +00005621 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005622 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005623 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005624 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005625
Douglas Gregorebe10102009-08-20 07:17:43 +00005626 if (!getDerived().AlwaysRebuild() &&
5627 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00005628 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005629 Inc.get() == S->getInc() &&
5630 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005631 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005632
Douglas Gregorebe10102009-08-20 07:17:43 +00005633 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005634 Init.get(), FullCond, ConditionVar,
5635 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005636}
5637
5638template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005639StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005640TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattnercab02a62011-02-17 20:34:02 +00005641 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5642 S->getLabel());
5643 if (!LD)
5644 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005645
Douglas Gregorebe10102009-08-20 07:17:43 +00005646 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00005647 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005648 cast<LabelDecl>(LD));
Douglas Gregorebe10102009-08-20 07:17:43 +00005649}
5650
5651template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005652StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005653TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005654 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00005655 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005656 return StmtError();
Eli Friedman9ccdb1d2012-01-31 22:47:07 +00005657 Target = SemaRef.MaybeCreateExprWithCleanups(Target.take());
Mike Stump11289f42009-09-09 15:08:12 +00005658
Douglas Gregorebe10102009-08-20 07:17:43 +00005659 if (!getDerived().AlwaysRebuild() &&
5660 Target.get() == S->getTarget())
John McCallc3007a22010-10-26 07:05:15 +00005661 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005662
5663 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00005664 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005665}
5666
5667template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005668StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005669TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00005670 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005671}
Mike Stump11289f42009-09-09 15:08:12 +00005672
Douglas Gregorebe10102009-08-20 07:17:43 +00005673template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005674StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005675TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00005676 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005677}
Mike Stump11289f42009-09-09 15:08:12 +00005678
Douglas Gregorebe10102009-08-20 07:17:43 +00005679template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005680StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005681TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005682 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregorebe10102009-08-20 07:17:43 +00005683 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005684 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00005685
Mike Stump11289f42009-09-09 15:08:12 +00005686 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00005687 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00005688 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005689}
Mike Stump11289f42009-09-09 15:08:12 +00005690
Douglas Gregorebe10102009-08-20 07:17:43 +00005691template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005692StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005693TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005694 bool DeclChanged = false;
Chris Lattner01cf8db2011-07-20 06:58:45 +00005695 SmallVector<Decl *, 4> Decls;
Aaron Ballman535bbcc2014-03-14 17:01:24 +00005696 for (auto *D : S->decls()) {
5697 Decl *Transformed = getDerived().TransformDefinition(D->getLocation(), D);
Douglas Gregorebe10102009-08-20 07:17:43 +00005698 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00005699 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005700
Aaron Ballman535bbcc2014-03-14 17:01:24 +00005701 if (Transformed != D)
Douglas Gregorebe10102009-08-20 07:17:43 +00005702 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00005703
Douglas Gregorebe10102009-08-20 07:17:43 +00005704 Decls.push_back(Transformed);
5705 }
Mike Stump11289f42009-09-09 15:08:12 +00005706
Douglas Gregorebe10102009-08-20 07:17:43 +00005707 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCallc3007a22010-10-26 07:05:15 +00005708 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005709
Rafael Espindolaab417692013-07-09 12:05:01 +00005710 return getDerived().RebuildDeclStmt(Decls, S->getStartLoc(), S->getEndLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005711}
Mike Stump11289f42009-09-09 15:08:12 +00005712
Douglas Gregorebe10102009-08-20 07:17:43 +00005713template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005714StmtResult
Chad Rosierde70e0e2012-08-25 00:11:56 +00005715TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005716
Benjamin Kramerf0623432012-08-23 22:51:59 +00005717 SmallVector<Expr*, 8> Constraints;
5718 SmallVector<Expr*, 8> Exprs;
Chris Lattner01cf8db2011-07-20 06:58:45 +00005719 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00005720
John McCalldadc5752010-08-24 06:29:42 +00005721 ExprResult AsmString;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005722 SmallVector<Expr*, 8> Clobbers;
Anders Carlssonaaeef072010-01-24 05:50:09 +00005723
5724 bool ExprsChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00005725
Anders Carlssonaaeef072010-01-24 05:50:09 +00005726 // Go through the outputs.
5727 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005728 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005729
Anders Carlssonaaeef072010-01-24 05:50:09 +00005730 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005731 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005732
Anders Carlssonaaeef072010-01-24 05:50:09 +00005733 // Transform the output expr.
5734 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005735 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005736 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005737 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005738
Anders Carlssonaaeef072010-01-24 05:50:09 +00005739 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00005740
John McCallb268a282010-08-23 23:25:46 +00005741 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005742 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005743
Anders Carlssonaaeef072010-01-24 05:50:09 +00005744 // Go through the inputs.
5745 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005746 Names.push_back(S->getInputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005747
Anders Carlssonaaeef072010-01-24 05:50:09 +00005748 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005749 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00005750
Anders Carlssonaaeef072010-01-24 05:50:09 +00005751 // Transform the input expr.
5752 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005753 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005754 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005755 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005756
Anders Carlssonaaeef072010-01-24 05:50:09 +00005757 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00005758
John McCallb268a282010-08-23 23:25:46 +00005759 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005760 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005761
Anders Carlssonaaeef072010-01-24 05:50:09 +00005762 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCallc3007a22010-10-26 07:05:15 +00005763 return SemaRef.Owned(S);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005764
5765 // Go through the clobbers.
5766 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosierd9fb09a2012-08-27 23:28:41 +00005767 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00005768
5769 // No need to transform the asm string literal.
5770 AsmString = SemaRef.Owned(S->getAsmString());
Chad Rosierde70e0e2012-08-25 00:11:56 +00005771 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
5772 S->isVolatile(), S->getNumOutputs(),
5773 S->getNumInputs(), Names.data(),
5774 Constraints, Exprs, AsmString.get(),
5775 Clobbers, S->getRParenLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005776}
5777
Chad Rosier32503022012-06-11 20:47:18 +00005778template<typename Derived>
5779StmtResult
5780TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier99fc3812012-08-07 00:29:06 +00005781 ArrayRef<Token> AsmToks =
5782 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier3ed0bd92012-08-08 19:48:07 +00005783
John McCallf413f5e2013-05-03 00:10:13 +00005784 bool HadError = false, HadChange = false;
5785
5786 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
5787 SmallVector<Expr*, 8> TransformedExprs;
5788 TransformedExprs.reserve(SrcExprs.size());
5789 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
5790 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
5791 if (!Result.isUsable()) {
5792 HadError = true;
5793 } else {
5794 HadChange |= (Result.get() != SrcExprs[i]);
5795 TransformedExprs.push_back(Result.take());
5796 }
5797 }
5798
5799 if (HadError) return StmtError();
5800 if (!HadChange && !getDerived().AlwaysRebuild())
5801 return Owned(S);
5802
Chad Rosierb6f46c12012-08-15 16:53:30 +00005803 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
John McCallf413f5e2013-05-03 00:10:13 +00005804 AsmToks, S->getAsmString(),
5805 S->getNumOutputs(), S->getNumInputs(),
5806 S->getAllConstraints(), S->getClobbers(),
5807 TransformedExprs, S->getEndLoc());
Chad Rosier32503022012-06-11 20:47:18 +00005808}
Douglas Gregorebe10102009-08-20 07:17:43 +00005809
5810template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005811StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005812TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005813 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00005814 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005815 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005816 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005817
Douglas Gregor96c79492010-04-23 22:50:49 +00005818 // Transform the @catch statements (if present).
5819 bool AnyCatchChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005820 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor96c79492010-04-23 22:50:49 +00005821 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00005822 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00005823 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005824 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00005825 if (Catch.get() != S->getCatchStmt(I))
5826 AnyCatchChanged = true;
5827 CatchStmts.push_back(Catch.release());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005828 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005829
Douglas Gregor306de2f2010-04-22 23:59:56 +00005830 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00005831 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00005832 if (S->getFinallyStmt()) {
5833 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5834 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005835 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00005836 }
5837
5838 // If nothing changed, just retain this statement.
5839 if (!getDerived().AlwaysRebuild() &&
5840 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00005841 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00005842 Finally.get() == S->getFinallyStmt())
John McCallc3007a22010-10-26 07:05:15 +00005843 return SemaRef.Owned(S);
Chad Rosier1dcde962012-08-08 18:46:20 +00005844
Douglas Gregor306de2f2010-04-22 23:59:56 +00005845 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00005846 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00005847 CatchStmts, Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005848}
Mike Stump11289f42009-09-09 15:08:12 +00005849
Douglas Gregorebe10102009-08-20 07:17:43 +00005850template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005851StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005852TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005853 // Transform the @catch parameter, if there is one.
5854 VarDecl *Var = 0;
5855 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5856 TypeSourceInfo *TSInfo = 0;
5857 if (FromVar->getTypeSourceInfo()) {
5858 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5859 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005860 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005861 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005862
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005863 QualType T;
5864 if (TSInfo)
5865 T = TSInfo->getType();
5866 else {
5867 T = getDerived().TransformType(FromVar->getType());
5868 if (T.isNull())
Chad Rosier1dcde962012-08-08 18:46:20 +00005869 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005870 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005871
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005872 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5873 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00005874 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005875 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005876
John McCalldadc5752010-08-24 06:29:42 +00005877 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005878 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005879 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005880
5881 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005882 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005883 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005884}
Mike Stump11289f42009-09-09 15:08:12 +00005885
Douglas Gregorebe10102009-08-20 07:17:43 +00005886template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005887StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005888TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005889 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005890 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005891 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005892 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005893
Douglas Gregor306de2f2010-04-22 23:59:56 +00005894 // If nothing changed, just retain this statement.
5895 if (!getDerived().AlwaysRebuild() &&
5896 Body.get() == S->getFinallyBody())
John McCallc3007a22010-10-26 07:05:15 +00005897 return SemaRef.Owned(S);
Douglas Gregor306de2f2010-04-22 23:59:56 +00005898
5899 // Build a new statement.
5900 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00005901 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005902}
Mike Stump11289f42009-09-09 15:08:12 +00005903
Douglas Gregorebe10102009-08-20 07:17:43 +00005904template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005905StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005906TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005907 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00005908 if (S->getThrowExpr()) {
5909 Operand = getDerived().TransformExpr(S->getThrowExpr());
5910 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005911 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00005912 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005913
Douglas Gregor2900c162010-04-22 21:44:01 +00005914 if (!getDerived().AlwaysRebuild() &&
5915 Operand.get() == S->getThrowExpr())
John McCallc3007a22010-10-26 07:05:15 +00005916 return getSema().Owned(S);
Chad Rosier1dcde962012-08-08 18:46:20 +00005917
John McCallb268a282010-08-23 23:25:46 +00005918 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005919}
Mike Stump11289f42009-09-09 15:08:12 +00005920
Douglas Gregorebe10102009-08-20 07:17:43 +00005921template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005922StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005923TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00005924 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00005925 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00005926 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00005927 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005928 return StmtError();
John McCalld9bb7432011-07-27 21:50:02 +00005929 Object =
5930 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
5931 Object.get());
5932 if (Object.isInvalid())
5933 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005934
Douglas Gregor6148de72010-04-22 22:01:21 +00005935 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005936 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00005937 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005938 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005939
Douglas Gregor6148de72010-04-22 22:01:21 +00005940 // If nothing change, just retain the current statement.
5941 if (!getDerived().AlwaysRebuild() &&
5942 Object.get() == S->getSynchExpr() &&
5943 Body.get() == S->getSynchBody())
John McCallc3007a22010-10-26 07:05:15 +00005944 return SemaRef.Owned(S);
Douglas Gregor6148de72010-04-22 22:01:21 +00005945
5946 // Build a new statement.
5947 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00005948 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005949}
5950
5951template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005952StmtResult
John McCall31168b02011-06-15 23:02:42 +00005953TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
5954 ObjCAutoreleasePoolStmt *S) {
5955 // Transform the body.
5956 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
5957 if (Body.isInvalid())
5958 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005959
John McCall31168b02011-06-15 23:02:42 +00005960 // If nothing changed, just retain this statement.
5961 if (!getDerived().AlwaysRebuild() &&
5962 Body.get() == S->getSubStmt())
5963 return SemaRef.Owned(S);
5964
5965 // Build a new statement.
5966 return getDerived().RebuildObjCAutoreleasePoolStmt(
5967 S->getAtLoc(), Body.get());
5968}
5969
5970template<typename Derived>
5971StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005972TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00005973 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00005974 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00005975 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005976 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005977 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005978
Douglas Gregorf68a5082010-04-22 23:10:45 +00005979 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00005980 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005981 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005982 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005983
Douglas Gregorf68a5082010-04-22 23:10:45 +00005984 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005985 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005986 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005987 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005988
Douglas Gregorf68a5082010-04-22 23:10:45 +00005989 // If nothing changed, just retain this statement.
5990 if (!getDerived().AlwaysRebuild() &&
5991 Element.get() == S->getElement() &&
5992 Collection.get() == S->getCollection() &&
5993 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005994 return SemaRef.Owned(S);
Chad Rosier1dcde962012-08-08 18:46:20 +00005995
Douglas Gregorf68a5082010-04-22 23:10:45 +00005996 // Build a new statement.
5997 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00005998 Element.get(),
5999 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00006000 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006001 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006002}
6003
David Majnemer5f7efef2013-10-15 09:50:08 +00006004template <typename Derived>
6005StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006006 // Transform the exception declaration, if any.
6007 VarDecl *Var = 0;
David Majnemer5f7efef2013-10-15 09:50:08 +00006008 if (VarDecl *ExceptionDecl = S->getExceptionDecl()) {
6009 TypeSourceInfo *T =
6010 getDerived().TransformType(ExceptionDecl->getTypeSourceInfo());
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00006011 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006012 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006013
David Majnemer5f7efef2013-10-15 09:50:08 +00006014 Var = getDerived().RebuildExceptionDecl(
6015 ExceptionDecl, T, ExceptionDecl->getInnerLocStart(),
6016 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
Douglas Gregorb412e172010-07-25 18:17:45 +00006017 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00006018 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00006019 }
Mike Stump11289f42009-09-09 15:08:12 +00006020
Douglas Gregorebe10102009-08-20 07:17:43 +00006021 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00006022 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00006023 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006024 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006025
David Majnemer5f7efef2013-10-15 09:50:08 +00006026 if (!getDerived().AlwaysRebuild() && !Var &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006027 Handler.get() == S->getHandlerBlock())
John McCallc3007a22010-10-26 07:05:15 +00006028 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00006029
David Majnemer5f7efef2013-10-15 09:50:08 +00006030 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006031}
Mike Stump11289f42009-09-09 15:08:12 +00006032
David Majnemer5f7efef2013-10-15 09:50:08 +00006033template <typename Derived>
6034StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006035 // Transform the try block itself.
David Majnemer5f7efef2013-10-15 09:50:08 +00006036 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
Douglas Gregorebe10102009-08-20 07:17:43 +00006037 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006038 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006039
Douglas Gregorebe10102009-08-20 07:17:43 +00006040 // Transform the handlers.
6041 bool HandlerChanged = false;
David Majnemer5f7efef2013-10-15 09:50:08 +00006042 SmallVector<Stmt *, 8> Handlers;
Douglas Gregorebe10102009-08-20 07:17:43 +00006043 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
David Majnemer5f7efef2013-10-15 09:50:08 +00006044 StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I));
Douglas Gregorebe10102009-08-20 07:17:43 +00006045 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006046 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006047
Douglas Gregorebe10102009-08-20 07:17:43 +00006048 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
6049 Handlers.push_back(Handler.takeAs<Stmt>());
6050 }
Mike Stump11289f42009-09-09 15:08:12 +00006051
David Majnemer5f7efef2013-10-15 09:50:08 +00006052 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006053 !HandlerChanged)
John McCallc3007a22010-10-26 07:05:15 +00006054 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00006055
John McCallb268a282010-08-23 23:25:46 +00006056 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006057 Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00006058}
Mike Stump11289f42009-09-09 15:08:12 +00006059
Richard Smith02e85f32011-04-14 22:09:26 +00006060template<typename Derived>
6061StmtResult
6062TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
6063 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
6064 if (Range.isInvalid())
6065 return StmtError();
6066
6067 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
6068 if (BeginEnd.isInvalid())
6069 return StmtError();
6070
6071 ExprResult Cond = getDerived().TransformExpr(S->getCond());
6072 if (Cond.isInvalid())
6073 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006074 if (Cond.get())
6075 Cond = SemaRef.CheckBooleanCondition(Cond.take(), S->getColonLoc());
6076 if (Cond.isInvalid())
6077 return StmtError();
6078 if (Cond.get())
6079 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.take());
Richard Smith02e85f32011-04-14 22:09:26 +00006080
6081 ExprResult Inc = getDerived().TransformExpr(S->getInc());
6082 if (Inc.isInvalid())
6083 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006084 if (Inc.get())
6085 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.take());
Richard Smith02e85f32011-04-14 22:09:26 +00006086
6087 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
6088 if (LoopVar.isInvalid())
6089 return StmtError();
6090
6091 StmtResult NewStmt = S;
6092 if (getDerived().AlwaysRebuild() ||
6093 Range.get() != S->getRangeStmt() ||
6094 BeginEnd.get() != S->getBeginEndStmt() ||
6095 Cond.get() != S->getCond() ||
6096 Inc.get() != S->getInc() ||
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006097 LoopVar.get() != S->getLoopVarStmt()) {
Richard Smith02e85f32011-04-14 22:09:26 +00006098 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6099 S->getColonLoc(), Range.get(),
6100 BeginEnd.get(), Cond.get(),
6101 Inc.get(), LoopVar.get(),
6102 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006103 if (NewStmt.isInvalid())
6104 return StmtError();
6105 }
Richard Smith02e85f32011-04-14 22:09:26 +00006106
6107 StmtResult Body = getDerived().TransformStmt(S->getBody());
6108 if (Body.isInvalid())
6109 return StmtError();
6110
6111 // Body has changed but we didn't rebuild the for-range statement. Rebuild
6112 // it now so we have a new statement to attach the body to.
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006113 if (Body.get() != S->getBody() && NewStmt.get() == S) {
Richard Smith02e85f32011-04-14 22:09:26 +00006114 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6115 S->getColonLoc(), Range.get(),
6116 BeginEnd.get(), Cond.get(),
6117 Inc.get(), LoopVar.get(),
6118 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006119 if (NewStmt.isInvalid())
6120 return StmtError();
6121 }
Richard Smith02e85f32011-04-14 22:09:26 +00006122
6123 if (NewStmt.get() == S)
6124 return SemaRef.Owned(S);
6125
6126 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
6127}
6128
John Wiegley1c0675e2011-04-28 01:08:34 +00006129template<typename Derived>
6130StmtResult
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006131TreeTransform<Derived>::TransformMSDependentExistsStmt(
6132 MSDependentExistsStmt *S) {
6133 // Transform the nested-name-specifier, if any.
6134 NestedNameSpecifierLoc QualifierLoc;
6135 if (S->getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006136 QualifierLoc
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006137 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
6138 if (!QualifierLoc)
6139 return StmtError();
6140 }
6141
6142 // Transform the declaration name.
6143 DeclarationNameInfo NameInfo = S->getNameInfo();
6144 if (NameInfo.getName()) {
6145 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6146 if (!NameInfo.getName())
6147 return StmtError();
6148 }
6149
6150 // Check whether anything changed.
6151 if (!getDerived().AlwaysRebuild() &&
6152 QualifierLoc == S->getQualifierLoc() &&
6153 NameInfo.getName() == S->getNameInfo().getName())
6154 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006155
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006156 // Determine whether this name exists, if we can.
6157 CXXScopeSpec SS;
6158 SS.Adopt(QualifierLoc);
6159 bool Dependent = false;
6160 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/0, SS, NameInfo)) {
6161 case Sema::IER_Exists:
6162 if (S->isIfExists())
6163 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006164
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006165 return new (getSema().Context) NullStmt(S->getKeywordLoc());
6166
6167 case Sema::IER_DoesNotExist:
6168 if (S->isIfNotExists())
6169 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006170
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006171 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00006172
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006173 case Sema::IER_Dependent:
6174 Dependent = true;
6175 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006176
Douglas Gregor4a2a8f72011-10-25 03:44:56 +00006177 case Sema::IER_Error:
6178 return StmtError();
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006179 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006180
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006181 // We need to continue with the instantiation, so do so now.
6182 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
6183 if (SubStmt.isInvalid())
6184 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006185
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006186 // If we have resolved the name, just transform to the substatement.
6187 if (!Dependent)
6188 return SubStmt;
Chad Rosier1dcde962012-08-08 18:46:20 +00006189
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006190 // The name is still dependent, so build a dependent expression again.
6191 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
6192 S->isIfExists(),
6193 QualifierLoc,
6194 NameInfo,
6195 SubStmt.get());
6196}
6197
6198template<typename Derived>
John McCall5e77d762013-04-16 07:28:30 +00006199ExprResult
6200TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
6201 NestedNameSpecifierLoc QualifierLoc;
6202 if (E->getQualifierLoc()) {
6203 QualifierLoc
6204 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6205 if (!QualifierLoc)
6206 return ExprError();
6207 }
6208
6209 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
6210 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
6211 if (!PD)
6212 return ExprError();
6213
6214 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
6215 if (Base.isInvalid())
6216 return ExprError();
6217
6218 return new (SemaRef.getASTContext())
6219 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
6220 SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
6221 QualifierLoc, E->getMemberLoc());
6222}
6223
David Majnemerfad8f482013-10-15 09:33:02 +00006224template <typename Derived>
6225StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00006226 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006227 if (TryBlock.isInvalid())
6228 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006229
6230 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
David Majnemer7e755502013-10-15 09:30:14 +00006231 if (Handler.isInvalid())
6232 return StmtError();
6233
David Majnemerfad8f482013-10-15 09:33:02 +00006234 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
6235 Handler.get() == S->getHandler())
John Wiegley1c0675e2011-04-28 01:08:34 +00006236 return SemaRef.Owned(S);
6237
David Majnemerfad8f482013-10-15 09:33:02 +00006238 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(),
6239 TryBlock.take(), Handler.take());
John Wiegley1c0675e2011-04-28 01:08:34 +00006240}
6241
David Majnemerfad8f482013-10-15 09:33:02 +00006242template <typename Derived>
6243StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00006244 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006245 if (Block.isInvalid())
6246 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006247
David Majnemerfad8f482013-10-15 09:33:02 +00006248 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.take());
John Wiegley1c0675e2011-04-28 01:08:34 +00006249}
6250
David Majnemerfad8f482013-10-15 09:33:02 +00006251template <typename Derived>
6252StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
John Wiegley1c0675e2011-04-28 01:08:34 +00006253 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
David Majnemerfad8f482013-10-15 09:33:02 +00006254 if (FilterExpr.isInvalid())
6255 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006256
David Majnemer7e755502013-10-15 09:30:14 +00006257 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006258 if (Block.isInvalid())
6259 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006260
David Majnemerfad8f482013-10-15 09:33:02 +00006261 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.take(),
John Wiegley1c0675e2011-04-28 01:08:34 +00006262 Block.take());
6263}
6264
David Majnemerfad8f482013-10-15 09:33:02 +00006265template <typename Derived>
6266StmtResult TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
6267 if (isa<SEHFinallyStmt>(Handler))
John Wiegley1c0675e2011-04-28 01:08:34 +00006268 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
6269 else
6270 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
6271}
6272
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006273template<typename Derived>
6274StmtResult
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006275TreeTransform<Derived>::TransformOMPExecutableDirective(
6276 OMPExecutableDirective *D) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00006277
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006278 // Transform the clauses
Alexey Bataev758e55e2013-09-06 18:03:48 +00006279 llvm::SmallVector<OMPClause *, 16> TClauses;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006280 ArrayRef<OMPClause *> Clauses = D->clauses();
6281 TClauses.reserve(Clauses.size());
6282 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
6283 I != E; ++I) {
6284 if (*I) {
6285 OMPClause *Clause = getDerived().TransformOMPClause(*I);
Alexey Bataev758e55e2013-09-06 18:03:48 +00006286 if (!Clause) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006287 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00006288 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006289 TClauses.push_back(Clause);
6290 }
6291 else {
6292 TClauses.push_back(0);
6293 }
6294 }
Alexey Bataev758e55e2013-09-06 18:03:48 +00006295 if (!D->getAssociatedStmt()) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006296 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00006297 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006298 StmtResult AssociatedStmt =
6299 getDerived().TransformStmt(D->getAssociatedStmt());
Alexey Bataev758e55e2013-09-06 18:03:48 +00006300 if (AssociatedStmt.isInvalid()) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006301 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00006302 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006303
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006304 return getDerived().RebuildOMPExecutableDirective(D->getDirectiveKind(),
6305 TClauses,
6306 AssociatedStmt.take(),
6307 D->getLocStart(),
6308 D->getLocEnd());
6309}
6310
6311template<typename Derived>
6312StmtResult
6313TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
6314 DeclarationNameInfo DirName;
Alexey Bataev3d76e772014-03-07 04:01:56 +00006315 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, 0);
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006316 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6317 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6318 return Res;
6319}
6320
6321template<typename Derived>
6322StmtResult
6323TreeTransform<Derived>::TransformOMPSimdDirective(OMPSimdDirective *D) {
6324 DeclarationNameInfo DirName;
Alexey Bataev96d15102014-03-07 04:16:48 +00006325 getDerived().getSema().StartOpenMPDSABlock(OMPD_simd, DirName, 0);
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006326 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6327 getDerived().getSema().EndOpenMPDSABlock(Res.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00006328 return Res;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006329}
6330
6331template<typename Derived>
6332OMPClause *
Alexey Bataevaadd52e2014-02-13 05:29:23 +00006333TreeTransform<Derived>::TransformOMPIfClause(OMPIfClause *C) {
Alexey Bataevaf7849e2014-03-05 06:45:14 +00006334 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
6335 if (Cond.isInvalid())
6336 return 0;
6337 return getDerived().RebuildOMPIfClause(Cond.take(), C->getLocStart(),
Alexey Bataevaadd52e2014-02-13 05:29:23 +00006338 C->getLParenLoc(), C->getLocEnd());
6339}
6340
6341template<typename Derived>
6342OMPClause *
Alexey Bataev568a8332014-03-06 06:15:19 +00006343TreeTransform<Derived>::TransformOMPNumThreadsClause(OMPNumThreadsClause *C) {
6344 ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads());
6345 if (NumThreads.isInvalid())
6346 return 0;
6347 return getDerived().RebuildOMPNumThreadsClause(NumThreads.take(),
6348 C->getLocStart(),
6349 C->getLParenLoc(),
6350 C->getLocEnd());
6351}
6352
Alexey Bataev62c87d22014-03-21 04:51:18 +00006353template <typename Derived>
6354OMPClause *
6355TreeTransform<Derived>::TransformOMPSafelenClause(OMPSafelenClause *C) {
6356 ExprResult E = getDerived().TransformExpr(C->getSafelen());
6357 if (E.isInvalid())
6358 return 0;
6359 return getDerived().RebuildOMPSafelenClause(
6360 E.take(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
6361}
6362
Alexey Bataev568a8332014-03-06 06:15:19 +00006363template<typename Derived>
6364OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006365TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
6366 return getDerived().RebuildOMPDefaultClause(C->getDefaultKind(),
6367 C->getDefaultKindKwLoc(),
6368 C->getLocStart(),
6369 C->getLParenLoc(),
6370 C->getLocEnd());
6371}
6372
6373template<typename Derived>
6374OMPClause *
6375TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00006376 llvm::SmallVector<Expr *, 16> Vars;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006377 Vars.reserve(C->varlist_size());
Aaron Ballman2205d2a2014-03-14 15:55:35 +00006378 for (auto *I : C->varlists()) {
6379 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(I));
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006380 if (EVar.isInvalid())
6381 return 0;
6382 Vars.push_back(EVar.take());
6383 }
6384 return getDerived().RebuildOMPPrivateClause(Vars,
6385 C->getLocStart(),
6386 C->getLParenLoc(),
6387 C->getLocEnd());
6388}
6389
Alexey Bataev758e55e2013-09-06 18:03:48 +00006390template<typename Derived>
6391OMPClause *
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006392TreeTransform<Derived>::TransformOMPFirstprivateClause(
6393 OMPFirstprivateClause *C) {
6394 llvm::SmallVector<Expr *, 16> Vars;
6395 Vars.reserve(C->varlist_size());
Aaron Ballman2205d2a2014-03-14 15:55:35 +00006396 for (auto *I : C->varlists()) {
6397 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(I));
Alexey Bataevd5af8e42013-10-01 05:32:34 +00006398 if (EVar.isInvalid())
6399 return 0;
6400 Vars.push_back(EVar.take());
6401 }
6402 return getDerived().RebuildOMPFirstprivateClause(Vars,
6403 C->getLocStart(),
6404 C->getLParenLoc(),
6405 C->getLocEnd());
6406}
6407
6408template<typename Derived>
6409OMPClause *
Alexey Bataev758e55e2013-09-06 18:03:48 +00006410TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
6411 llvm::SmallVector<Expr *, 16> Vars;
6412 Vars.reserve(C->varlist_size());
Aaron Ballman2205d2a2014-03-14 15:55:35 +00006413 for (auto *I : C->varlists()) {
6414 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(I));
Alexey Bataev758e55e2013-09-06 18:03:48 +00006415 if (EVar.isInvalid())
6416 return 0;
6417 Vars.push_back(EVar.take());
6418 }
6419 return getDerived().RebuildOMPSharedClause(Vars,
6420 C->getLocStart(),
6421 C->getLParenLoc(),
6422 C->getLocEnd());
6423}
6424
Douglas Gregorebe10102009-08-20 07:17:43 +00006425//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00006426// Expression transformation
6427//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00006428template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006429ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006430TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006431 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006432}
Mike Stump11289f42009-09-09 15:08:12 +00006433
6434template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006435ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006436TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregorea972d32011-02-28 21:54:11 +00006437 NestedNameSpecifierLoc QualifierLoc;
6438 if (E->getQualifierLoc()) {
6439 QualifierLoc
6440 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6441 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00006442 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00006443 }
John McCallce546572009-12-08 09:08:17 +00006444
6445 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006446 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6447 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006448 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00006449 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006450
John McCall815039a2010-08-17 21:27:17 +00006451 DeclarationNameInfo NameInfo = E->getNameInfo();
6452 if (NameInfo.getName()) {
6453 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6454 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00006455 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00006456 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006457
6458 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00006459 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00006460 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006461 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00006462 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00006463
6464 // Mark it referenced in the new context regardless.
6465 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00006466 SemaRef.MarkDeclRefReferenced(E);
John McCallce546572009-12-08 09:08:17 +00006467
John McCallc3007a22010-10-26 07:05:15 +00006468 return SemaRef.Owned(E);
Douglas Gregor4bd90e52009-10-23 18:54:35 +00006469 }
John McCallce546572009-12-08 09:08:17 +00006470
6471 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCallb3774b52010-08-19 23:49:38 +00006472 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00006473 TemplateArgs = &TransArgs;
6474 TransArgs.setLAngleLoc(E->getLAngleLoc());
6475 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006476 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6477 E->getNumTemplateArgs(),
6478 TransArgs))
6479 return ExprError();
John McCallce546572009-12-08 09:08:17 +00006480 }
6481
Chad Rosier1dcde962012-08-08 18:46:20 +00006482 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregorea972d32011-02-28 21:54:11 +00006483 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00006484}
Mike Stump11289f42009-09-09 15:08:12 +00006485
Douglas Gregora16548e2009-08-11 05:31:07 +00006486template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006487ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006488TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00006489 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006490}
Mike Stump11289f42009-09-09 15:08:12 +00006491
Douglas Gregora16548e2009-08-11 05:31:07 +00006492template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006493ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006494TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00006495 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006496}
Mike Stump11289f42009-09-09 15:08:12 +00006497
Douglas Gregora16548e2009-08-11 05:31:07 +00006498template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006499ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006500TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00006501 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006502}
Mike Stump11289f42009-09-09 15:08:12 +00006503
Douglas Gregora16548e2009-08-11 05:31:07 +00006504template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006505ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006506TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00006507 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006508}
Mike Stump11289f42009-09-09 15:08:12 +00006509
Douglas Gregora16548e2009-08-11 05:31:07 +00006510template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006511ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006512TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00006513 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006514}
6515
6516template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006517ExprResult
Richard Smithc67fdd42012-03-07 08:35:16 +00006518TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
Argyrios Kyrtzidis25049092013-04-09 01:17:02 +00006519 if (FunctionDecl *FD = E->getDirectCallee())
6520 SemaRef.MarkFunctionReferenced(E->getLocStart(), FD);
Richard Smithc67fdd42012-03-07 08:35:16 +00006521 return SemaRef.MaybeBindToTemporary(E);
6522}
6523
6524template<typename Derived>
6525ExprResult
Peter Collingbourne91147592011-04-15 00:35:48 +00006526TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
6527 ExprResult ControllingExpr =
6528 getDerived().TransformExpr(E->getControllingExpr());
6529 if (ControllingExpr.isInvalid())
6530 return ExprError();
6531
Chris Lattner01cf8db2011-07-20 06:58:45 +00006532 SmallVector<Expr *, 4> AssocExprs;
6533 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbourne91147592011-04-15 00:35:48 +00006534 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
6535 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
6536 if (TS) {
6537 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
6538 if (!AssocType)
6539 return ExprError();
6540 AssocTypes.push_back(AssocType);
6541 } else {
6542 AssocTypes.push_back(0);
6543 }
6544
6545 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
6546 if (AssocExpr.isInvalid())
6547 return ExprError();
6548 AssocExprs.push_back(AssocExpr.release());
6549 }
6550
6551 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
6552 E->getDefaultLoc(),
6553 E->getRParenLoc(),
6554 ControllingExpr.release(),
Dmitri Gribenko82360372013-05-10 13:06:58 +00006555 AssocTypes,
6556 AssocExprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00006557}
6558
6559template<typename Derived>
6560ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006561TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006562 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006563 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006564 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006565
Douglas Gregora16548e2009-08-11 05:31:07 +00006566 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006567 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006568
John McCallb268a282010-08-23 23:25:46 +00006569 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006570 E->getRParen());
6571}
6572
Richard Smithdb2630f2012-10-21 03:28:35 +00006573/// \brief The operand of a unary address-of operator has special rules: it's
6574/// allowed to refer to a non-static member of a class even if there's no 'this'
6575/// object available.
6576template<typename Derived>
6577ExprResult
6578TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
6579 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
6580 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true);
6581 else
6582 return getDerived().TransformExpr(E);
6583}
6584
Mike Stump11289f42009-09-09 15:08:12 +00006585template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006586ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006587TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smitheebe125f2013-05-21 23:29:46 +00006588 ExprResult SubExpr;
6589 if (E->getOpcode() == UO_AddrOf)
6590 SubExpr = TransformAddressOfOperand(E->getSubExpr());
6591 else
6592 SubExpr = TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006593 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006594 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006595
Douglas Gregora16548e2009-08-11 05:31:07 +00006596 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006597 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006598
Douglas Gregora16548e2009-08-11 05:31:07 +00006599 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
6600 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00006601 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006602}
Mike Stump11289f42009-09-09 15:08:12 +00006603
Douglas Gregora16548e2009-08-11 05:31:07 +00006604template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006605ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00006606TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
6607 // Transform the type.
6608 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
6609 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00006610 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006611
Douglas Gregor882211c2010-04-28 22:16:22 +00006612 // Transform all of the components into components similar to what the
6613 // parser uses.
Chad Rosier1dcde962012-08-08 18:46:20 +00006614 // FIXME: It would be slightly more efficient in the non-dependent case to
6615 // just map FieldDecls, rather than requiring the rebuilder to look for
6616 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00006617 // template code that we don't care.
6618 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00006619 typedef Sema::OffsetOfComponent Component;
Douglas Gregor882211c2010-04-28 22:16:22 +00006620 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner01cf8db2011-07-20 06:58:45 +00006621 SmallVector<Component, 4> Components;
Douglas Gregor882211c2010-04-28 22:16:22 +00006622 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
6623 const Node &ON = E->getComponent(I);
6624 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00006625 Comp.isBrackets = true;
Abramo Bagnara6b6f0512011-03-12 09:45:03 +00006626 Comp.LocStart = ON.getSourceRange().getBegin();
6627 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor882211c2010-04-28 22:16:22 +00006628 switch (ON.getKind()) {
6629 case Node::Array: {
6630 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00006631 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00006632 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006633 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006634
Douglas Gregor882211c2010-04-28 22:16:22 +00006635 ExprChanged = ExprChanged || Index.get() != FromIndex;
6636 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00006637 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00006638 break;
6639 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006640
Douglas Gregor882211c2010-04-28 22:16:22 +00006641 case Node::Field:
6642 case Node::Identifier:
6643 Comp.isBrackets = false;
6644 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00006645 if (!Comp.U.IdentInfo)
6646 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00006647
Douglas Gregor882211c2010-04-28 22:16:22 +00006648 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006649
Douglas Gregord1702062010-04-29 00:18:15 +00006650 case Node::Base:
6651 // Will be recomputed during the rebuild.
6652 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00006653 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006654
Douglas Gregor882211c2010-04-28 22:16:22 +00006655 Components.push_back(Comp);
6656 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006657
Douglas Gregor882211c2010-04-28 22:16:22 +00006658 // If nothing changed, retain the existing expression.
6659 if (!getDerived().AlwaysRebuild() &&
6660 Type == E->getTypeSourceInfo() &&
6661 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00006662 return SemaRef.Owned(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00006663
Douglas Gregor882211c2010-04-28 22:16:22 +00006664 // Build a new offsetof expression.
6665 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
6666 Components.data(), Components.size(),
6667 E->getRParenLoc());
6668}
6669
6670template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006671ExprResult
John McCall8d69a212010-11-15 23:31:06 +00006672TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
6673 assert(getDerived().AlreadyTransformed(E->getType()) &&
6674 "opaque value expression requires transformation");
6675 return SemaRef.Owned(E);
6676}
6677
6678template<typename Derived>
6679ExprResult
John McCallfe96e0b2011-11-06 09:01:30 +00006680TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCalle9290822011-11-30 04:42:31 +00006681 // Rebuild the syntactic form. The original syntactic form has
6682 // opaque-value expressions in it, so strip those away and rebuild
6683 // the result. This is a really awful way of doing this, but the
6684 // better solution (rebuilding the semantic expressions and
6685 // rebinding OVEs as necessary) doesn't work; we'd need
6686 // TreeTransform to not strip away implicit conversions.
6687 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
6688 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCallfe96e0b2011-11-06 09:01:30 +00006689 if (result.isInvalid()) return ExprError();
6690
6691 // If that gives us a pseudo-object result back, the pseudo-object
6692 // expression must have been an lvalue-to-rvalue conversion which we
6693 // should reapply.
6694 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
6695 result = SemaRef.checkPseudoObjectRValue(result.take());
6696
6697 return result;
6698}
6699
6700template<typename Derived>
6701ExprResult
Peter Collingbournee190dee2011-03-11 19:24:49 +00006702TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
6703 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006704 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00006705 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00006706
John McCallbcd03502009-12-07 02:54:59 +00006707 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00006708 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00006709 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006710
John McCall4c98fd82009-11-04 07:28:41 +00006711 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCallc3007a22010-10-26 07:05:15 +00006712 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006713
Peter Collingbournee190dee2011-03-11 19:24:49 +00006714 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
6715 E->getKind(),
6716 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00006717 }
Mike Stump11289f42009-09-09 15:08:12 +00006718
Eli Friedmane4f22df2012-02-29 04:03:55 +00006719 // C++0x [expr.sizeof]p1:
6720 // The operand is either an expression, which is an unevaluated operand
6721 // [...]
Eli Friedman15681d62012-09-26 04:34:21 +00006722 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
6723 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00006724
Eli Friedmane4f22df2012-02-29 04:03:55 +00006725 ExprResult SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
6726 if (SubExpr.isInvalid())
6727 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006728
Eli Friedmane4f22df2012-02-29 04:03:55 +00006729 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
6730 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006731
Peter Collingbournee190dee2011-03-11 19:24:49 +00006732 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
6733 E->getOperatorLoc(),
6734 E->getKind(),
6735 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00006736}
Mike Stump11289f42009-09-09 15:08:12 +00006737
Douglas Gregora16548e2009-08-11 05:31:07 +00006738template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006739ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006740TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006741 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006742 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006743 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006744
John McCalldadc5752010-08-24 06:29:42 +00006745 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006746 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006747 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006748
6749
Douglas Gregora16548e2009-08-11 05:31:07 +00006750 if (!getDerived().AlwaysRebuild() &&
6751 LHS.get() == E->getLHS() &&
6752 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00006753 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006754
John McCallb268a282010-08-23 23:25:46 +00006755 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006756 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00006757 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006758 E->getRBracketLoc());
6759}
Mike Stump11289f42009-09-09 15:08:12 +00006760
6761template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006762ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006763TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006764 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00006765 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00006766 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006767 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006768
6769 // Transform arguments.
6770 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006771 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00006772 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00006773 &ArgChanged))
6774 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006775
Douglas Gregora16548e2009-08-11 05:31:07 +00006776 if (!getDerived().AlwaysRebuild() &&
6777 Callee.get() == E->getCallee() &&
6778 !ArgChanged)
Dmitri Gribenko76bb5cabfa2012-09-10 21:20:09 +00006779 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00006780
Douglas Gregora16548e2009-08-11 05:31:07 +00006781 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00006782 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00006783 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00006784 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006785 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00006786 E->getRParenLoc());
6787}
Mike Stump11289f42009-09-09 15:08:12 +00006788
6789template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006790ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006791TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006792 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00006793 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006794 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006795
Douglas Gregorea972d32011-02-28 21:54:11 +00006796 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorf405d7e2009-08-31 23:41:50 +00006797 if (E->hasQualifier()) {
Douglas Gregorea972d32011-02-28 21:54:11 +00006798 QualifierLoc
6799 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00006800
Douglas Gregorea972d32011-02-28 21:54:11 +00006801 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00006802 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00006803 }
Abramo Bagnara7945c982012-01-27 09:46:47 +00006804 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00006805
Eli Friedman2cfcef62009-12-04 06:40:45 +00006806 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006807 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
6808 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006809 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00006810 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006811
John McCall16df1e52010-03-30 21:47:33 +00006812 NamedDecl *FoundDecl = E->getFoundDecl();
6813 if (FoundDecl == E->getMemberDecl()) {
6814 FoundDecl = Member;
6815 } else {
6816 FoundDecl = cast_or_null<NamedDecl>(
6817 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
6818 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00006819 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00006820 }
6821
Douglas Gregora16548e2009-08-11 05:31:07 +00006822 if (!getDerived().AlwaysRebuild() &&
6823 Base.get() == E->getBase() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00006824 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00006825 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00006826 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00006827 !E->hasExplicitTemplateArgs()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006828
Anders Carlsson9c45ad72009-12-22 05:24:09 +00006829 // Mark it referenced in the new context regardless.
6830 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00006831 SemaRef.MarkMemberReferenced(E);
6832
John McCallc3007a22010-10-26 07:05:15 +00006833 return SemaRef.Owned(E);
Anders Carlsson9c45ad72009-12-22 05:24:09 +00006834 }
Douglas Gregora16548e2009-08-11 05:31:07 +00006835
John McCall6b51f282009-11-23 01:53:49 +00006836 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00006837 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00006838 TransArgs.setLAngleLoc(E->getLAngleLoc());
6839 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006840 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6841 E->getNumTemplateArgs(),
6842 TransArgs))
6843 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00006844 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006845
Douglas Gregora16548e2009-08-11 05:31:07 +00006846 // FIXME: Bogus source location for the operator
6847 SourceLocation FakeOperatorLoc
6848 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
6849
John McCall38836f02010-01-15 08:34:02 +00006850 // FIXME: to do this check properly, we will need to preserve the
6851 // first-qualifier-in-scope here, just in case we had a dependent
6852 // base (and therefore couldn't do the check) and a
6853 // nested-name-qualifier (and therefore could do the lookup).
6854 NamedDecl *FirstQualifierInScope = 0;
6855
John McCallb268a282010-08-23 23:25:46 +00006856 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00006857 E->isArrow(),
Douglas Gregorea972d32011-02-28 21:54:11 +00006858 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00006859 TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006860 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00006861 Member,
John McCall16df1e52010-03-30 21:47:33 +00006862 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00006863 (E->hasExplicitTemplateArgs()
John McCall6b51f282009-11-23 01:53:49 +00006864 ? &TransArgs : 0),
John McCall38836f02010-01-15 08:34:02 +00006865 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00006866}
Mike Stump11289f42009-09-09 15:08:12 +00006867
Douglas Gregora16548e2009-08-11 05:31:07 +00006868template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006869ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006870TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00006871 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006872 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006873 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006874
John McCalldadc5752010-08-24 06:29:42 +00006875 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006876 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006877 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006878
Douglas Gregora16548e2009-08-11 05:31:07 +00006879 if (!getDerived().AlwaysRebuild() &&
6880 LHS.get() == E->getLHS() &&
6881 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00006882 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006883
Lang Hames5de91cc2012-10-02 04:45:10 +00006884 Sema::FPContractStateRAII FPContractState(getSema());
6885 getSema().FPFeatures.fp_contract = E->isFPContractable();
6886
Douglas Gregora16548e2009-08-11 05:31:07 +00006887 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00006888 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006889}
6890
Mike Stump11289f42009-09-09 15:08:12 +00006891template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006892ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006893TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00006894 CompoundAssignOperator *E) {
6895 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006896}
Mike Stump11289f42009-09-09 15:08:12 +00006897
Douglas Gregora16548e2009-08-11 05:31:07 +00006898template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00006899ExprResult TreeTransform<Derived>::
6900TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
6901 // Just rebuild the common and RHS expressions and see whether we
6902 // get any changes.
6903
6904 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
6905 if (commonExpr.isInvalid())
6906 return ExprError();
6907
6908 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
6909 if (rhs.isInvalid())
6910 return ExprError();
6911
6912 if (!getDerived().AlwaysRebuild() &&
6913 commonExpr.get() == e->getCommon() &&
6914 rhs.get() == e->getFalseExpr())
6915 return SemaRef.Owned(e);
6916
6917 return getDerived().RebuildConditionalOperator(commonExpr.take(),
6918 e->getQuestionLoc(),
6919 0,
6920 e->getColonLoc(),
6921 rhs.get());
6922}
6923
6924template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006925ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006926TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00006927 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00006928 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006929 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006930
John McCalldadc5752010-08-24 06:29:42 +00006931 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006932 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006933 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006934
John McCalldadc5752010-08-24 06:29:42 +00006935 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006936 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006937 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006938
Douglas Gregora16548e2009-08-11 05:31:07 +00006939 if (!getDerived().AlwaysRebuild() &&
6940 Cond.get() == E->getCond() &&
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
John McCallb268a282010-08-23 23:25:46 +00006945 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00006946 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00006947 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00006948 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00006949 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006950}
Mike Stump11289f42009-09-09 15:08:12 +00006951
6952template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006953ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006954TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00006955 // Implicit casts are eliminated during transformation, since they
6956 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00006957 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006958}
Mike Stump11289f42009-09-09 15:08:12 +00006959
Douglas Gregora16548e2009-08-11 05:31:07 +00006960template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006961ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006962TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006963 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6964 if (!Type)
6965 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006966
John McCalldadc5752010-08-24 06:29:42 +00006967 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00006968 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006969 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006970 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006971
Douglas Gregora16548e2009-08-11 05:31:07 +00006972 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006973 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006974 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006975 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006976
John McCall97513962010-01-15 18:39:57 +00006977 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006978 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00006979 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006980 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006981}
Mike Stump11289f42009-09-09 15:08:12 +00006982
Douglas Gregora16548e2009-08-11 05:31:07 +00006983template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006984ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006985TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00006986 TypeSourceInfo *OldT = E->getTypeSourceInfo();
6987 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
6988 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00006989 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006990
John McCalldadc5752010-08-24 06:29:42 +00006991 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00006992 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006993 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006994
Douglas Gregora16548e2009-08-11 05:31:07 +00006995 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00006996 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006997 Init.get() == E->getInitializer())
Douglas Gregorc7f46f22011-12-10 00:23:21 +00006998 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006999
John McCall5d7aa7f2010-01-19 22:33:45 +00007000 // Note: the expression type doesn't necessarily match the
7001 // type-as-written, but that's okay, because it should always be
7002 // derivable from the initializer.
7003
John McCalle15bbff2010-01-18 19:35:47 +00007004 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00007005 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00007006 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007007}
Mike Stump11289f42009-09-09 15:08:12 +00007008
Douglas Gregora16548e2009-08-11 05:31:07 +00007009template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007010ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007011TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007012 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00007013 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007014 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007015
Douglas Gregora16548e2009-08-11 05:31:07 +00007016 if (!getDerived().AlwaysRebuild() &&
7017 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007018 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007019
Douglas Gregora16548e2009-08-11 05:31:07 +00007020 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00007021 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00007022 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00007023 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00007024 E->getAccessorLoc(),
7025 E->getAccessor());
7026}
Mike Stump11289f42009-09-09 15:08:12 +00007027
Douglas Gregora16548e2009-08-11 05:31:07 +00007028template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007029ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007030TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007031 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00007032
Benjamin Kramerf0623432012-08-23 22:51:59 +00007033 SmallVector<Expr*, 4> Inits;
Chad Rosier1dcde962012-08-08 18:46:20 +00007034 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00007035 Inits, &InitChanged))
7036 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007037
Douglas Gregora16548e2009-08-11 05:31:07 +00007038 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCallc3007a22010-10-26 07:05:15 +00007039 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007040
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007041 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00007042 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00007043}
Mike Stump11289f42009-09-09 15:08:12 +00007044
Douglas Gregora16548e2009-08-11 05:31:07 +00007045template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007046ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007047TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007048 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00007049
Douglas Gregorebe10102009-08-20 07:17:43 +00007050 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00007051 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00007052 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007053 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007054
Douglas Gregorebe10102009-08-20 07:17:43 +00007055 // transform the designators.
Benjamin Kramerf0623432012-08-23 22:51:59 +00007056 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregora16548e2009-08-11 05:31:07 +00007057 bool ExprChanged = false;
7058 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
7059 DEnd = E->designators_end();
7060 D != DEnd; ++D) {
7061 if (D->isFieldDesignator()) {
7062 Desig.AddDesignator(Designator::getField(D->getFieldName(),
7063 D->getDotLoc(),
7064 D->getFieldLoc()));
7065 continue;
7066 }
Mike Stump11289f42009-09-09 15:08:12 +00007067
Douglas Gregora16548e2009-08-11 05:31:07 +00007068 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00007069 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00007070 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007071 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007072
7073 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007074 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00007075
Douglas Gregora16548e2009-08-11 05:31:07 +00007076 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
7077 ArrayExprs.push_back(Index.release());
7078 continue;
7079 }
Mike Stump11289f42009-09-09 15:08:12 +00007080
Douglas Gregora16548e2009-08-11 05:31:07 +00007081 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00007082 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00007083 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
7084 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007085 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007086
John McCalldadc5752010-08-24 06:29:42 +00007087 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00007088 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007089 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007090
7091 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007092 End.get(),
7093 D->getLBracketLoc(),
7094 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00007095
Douglas Gregora16548e2009-08-11 05:31:07 +00007096 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
7097 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00007098
Douglas Gregora16548e2009-08-11 05:31:07 +00007099 ArrayExprs.push_back(Start.release());
7100 ArrayExprs.push_back(End.release());
7101 }
Mike Stump11289f42009-09-09 15:08:12 +00007102
Douglas Gregora16548e2009-08-11 05:31:07 +00007103 if (!getDerived().AlwaysRebuild() &&
7104 Init.get() == E->getInit() &&
7105 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00007106 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007107
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007108 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00007109 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00007110 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007111}
Mike Stump11289f42009-09-09 15:08:12 +00007112
Douglas Gregora16548e2009-08-11 05:31:07 +00007113template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007114ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007115TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007116 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00007117 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier1dcde962012-08-08 18:46:20 +00007118
Douglas Gregor3da3c062009-10-28 00:29:27 +00007119 // FIXME: Will we ever have proper type location here? Will we actually
7120 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00007121 QualType T = getDerived().TransformType(E->getType());
7122 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00007123 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007124
Douglas Gregora16548e2009-08-11 05:31:07 +00007125 if (!getDerived().AlwaysRebuild() &&
7126 T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00007127 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007128
Douglas Gregora16548e2009-08-11 05:31:07 +00007129 return getDerived().RebuildImplicitValueInitExpr(T);
7130}
Mike Stump11289f42009-09-09 15:08:12 +00007131
Douglas Gregora16548e2009-08-11 05:31:07 +00007132template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007133ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007134TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00007135 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
7136 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007137 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007138
John McCalldadc5752010-08-24 06:29:42 +00007139 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007140 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007141 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007142
Douglas Gregora16548e2009-08-11 05:31:07 +00007143 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00007144 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007145 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00007146 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007147
John McCallb268a282010-08-23 23:25:46 +00007148 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00007149 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007150}
7151
7152template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007153ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007154TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007155 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007156 SmallVector<Expr*, 4> Inits;
Douglas Gregora3efea12011-01-03 19:04:46 +00007157 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
7158 &ArgumentChanged))
7159 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007160
Douglas Gregora16548e2009-08-11 05:31:07 +00007161 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007162 Inits,
Douglas Gregora16548e2009-08-11 05:31:07 +00007163 E->getRParenLoc());
7164}
Mike Stump11289f42009-09-09 15:08:12 +00007165
Douglas Gregora16548e2009-08-11 05:31:07 +00007166/// \brief Transform an address-of-label expression.
7167///
7168/// By default, the transformation of an address-of-label expression always
7169/// rebuilds the expression, so that the label identifier can be resolved to
7170/// the corresponding label statement by semantic analysis.
7171template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007172ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007173TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +00007174 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
7175 E->getLabel());
7176 if (!LD)
7177 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007178
Douglas Gregora16548e2009-08-11 05:31:07 +00007179 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00007180 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +00007181}
Mike Stump11289f42009-09-09 15:08:12 +00007182
7183template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00007184ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007185TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalled7b2782012-04-06 18:20:53 +00007186 SemaRef.ActOnStartStmtExpr();
John McCalldadc5752010-08-24 06:29:42 +00007187 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00007188 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCalled7b2782012-04-06 18:20:53 +00007189 if (SubStmt.isInvalid()) {
7190 SemaRef.ActOnStmtExprError();
John McCallfaf5fb42010-08-26 23:41:50 +00007191 return ExprError();
John McCalled7b2782012-04-06 18:20:53 +00007192 }
Mike Stump11289f42009-09-09 15:08:12 +00007193
Douglas Gregora16548e2009-08-11 05:31:07 +00007194 if (!getDerived().AlwaysRebuild() &&
John McCalled7b2782012-04-06 18:20:53 +00007195 SubStmt.get() == E->getSubStmt()) {
7196 // Calling this an 'error' is unintuitive, but it does the right thing.
7197 SemaRef.ActOnStmtExprError();
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007198 return SemaRef.MaybeBindToTemporary(E);
John McCalled7b2782012-04-06 18:20:53 +00007199 }
Mike Stump11289f42009-09-09 15:08:12 +00007200
7201 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007202 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007203 E->getRParenLoc());
7204}
Mike Stump11289f42009-09-09 15:08:12 +00007205
Douglas Gregora16548e2009-08-11 05:31:07 +00007206template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007207ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007208TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007209 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00007210 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007211 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007212
John McCalldadc5752010-08-24 06:29:42 +00007213 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007214 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007215 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007216
John McCalldadc5752010-08-24 06:29:42 +00007217 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007218 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007219 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007220
Douglas Gregora16548e2009-08-11 05:31:07 +00007221 if (!getDerived().AlwaysRebuild() &&
7222 Cond.get() == E->getCond() &&
7223 LHS.get() == E->getLHS() &&
7224 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00007225 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007226
Douglas Gregora16548e2009-08-11 05:31:07 +00007227 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00007228 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007229 E->getRParenLoc());
7230}
Mike Stump11289f42009-09-09 15:08:12 +00007231
Douglas Gregora16548e2009-08-11 05:31:07 +00007232template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007233ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007234TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007235 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007236}
7237
7238template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007239ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007240TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007241 switch (E->getOperator()) {
7242 case OO_New:
7243 case OO_Delete:
7244 case OO_Array_New:
7245 case OO_Array_Delete:
7246 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier1dcde962012-08-08 18:46:20 +00007247
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007248 case OO_Call: {
7249 // This is a call to an object's operator().
7250 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
7251
7252 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00007253 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007254 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007255 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007256
7257 // FIXME: Poor location information
7258 SourceLocation FakeLParenLoc
7259 = SemaRef.PP.getLocForEndOfToken(
7260 static_cast<Expr *>(Object.get())->getLocEnd());
7261
7262 // Transform the call arguments.
Benjamin Kramerf0623432012-08-23 22:51:59 +00007263 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00007264 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregora3efea12011-01-03 19:04:46 +00007265 Args))
7266 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007267
John McCallb268a282010-08-23 23:25:46 +00007268 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007269 Args,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007270 E->getLocEnd());
7271 }
7272
7273#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
7274 case OO_##Name:
7275#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
7276#include "clang/Basic/OperatorKinds.def"
7277 case OO_Subscript:
7278 // Handled below.
7279 break;
7280
7281 case OO_Conditional:
7282 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007283
7284 case OO_None:
7285 case NUM_OVERLOADED_OPERATORS:
7286 llvm_unreachable("not an overloaded operator?");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00007287 }
7288
John McCalldadc5752010-08-24 06:29:42 +00007289 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00007290 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007291 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007292
Richard Smithdb2630f2012-10-21 03:28:35 +00007293 ExprResult First;
7294 if (E->getOperator() == OO_Amp)
7295 First = getDerived().TransformAddressOfOperand(E->getArg(0));
7296 else
7297 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00007298 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007299 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007300
John McCalldadc5752010-08-24 06:29:42 +00007301 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00007302 if (E->getNumArgs() == 2) {
7303 Second = getDerived().TransformExpr(E->getArg(1));
7304 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007305 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007306 }
Mike Stump11289f42009-09-09 15:08:12 +00007307
Douglas Gregora16548e2009-08-11 05:31:07 +00007308 if (!getDerived().AlwaysRebuild() &&
7309 Callee.get() == E->getCallee() &&
7310 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00007311 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007312 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00007313
Lang Hames5de91cc2012-10-02 04:45:10 +00007314 Sema::FPContractStateRAII FPContractState(getSema());
7315 getSema().FPFeatures.fp_contract = E->isFPContractable();
7316
Douglas Gregora16548e2009-08-11 05:31:07 +00007317 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
7318 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00007319 Callee.get(),
7320 First.get(),
7321 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007322}
Mike Stump11289f42009-09-09 15:08:12 +00007323
Douglas Gregora16548e2009-08-11 05:31:07 +00007324template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007325ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007326TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
7327 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007328}
Mike Stump11289f42009-09-09 15:08:12 +00007329
Douglas Gregora16548e2009-08-11 05:31:07 +00007330template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007331ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +00007332TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
7333 // Transform the callee.
7334 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
7335 if (Callee.isInvalid())
7336 return ExprError();
7337
7338 // Transform exec config.
7339 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
7340 if (EC.isInvalid())
7341 return ExprError();
7342
7343 // Transform arguments.
7344 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007345 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00007346 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00007347 &ArgChanged))
7348 return ExprError();
7349
7350 if (!getDerived().AlwaysRebuild() &&
7351 Callee.get() == E->getCallee() &&
7352 !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00007353 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbourne41f85462011-02-09 21:07:24 +00007354
7355 // FIXME: Wrong source location information for the '('.
7356 SourceLocation FakeLParenLoc
7357 = ((Expr *)Callee.get())->getSourceRange().getBegin();
7358 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007359 Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00007360 E->getRParenLoc(), EC.get());
7361}
7362
7363template<typename Derived>
7364ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007365TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007366 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7367 if (!Type)
7368 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007369
John McCalldadc5752010-08-24 06:29:42 +00007370 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00007371 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007372 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007373 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007374
Douglas Gregora16548e2009-08-11 05:31:07 +00007375 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007376 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007377 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00007378 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007379 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00007380 E->getStmtClass(),
Fariborz Jahanianf0738712013-02-22 22:02:53 +00007381 E->getAngleBrackets().getBegin(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007382 Type,
Fariborz Jahanianf0738712013-02-22 22:02:53 +00007383 E->getAngleBrackets().getEnd(),
7384 // FIXME. this should be '(' location
7385 E->getAngleBrackets().getEnd(),
John McCallb268a282010-08-23 23:25:46 +00007386 SubExpr.get(),
Abramo Bagnara9fb43862012-10-15 21:08:58 +00007387 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007388}
Mike Stump11289f42009-09-09 15:08:12 +00007389
Douglas Gregora16548e2009-08-11 05:31:07 +00007390template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007391ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007392TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
7393 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007394}
Mike Stump11289f42009-09-09 15:08:12 +00007395
7396template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007397ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007398TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
7399 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00007400}
7401
Douglas Gregora16548e2009-08-11 05:31:07 +00007402template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007403ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007404TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007405 CXXReinterpretCastExpr *E) {
7406 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007407}
Mike Stump11289f42009-09-09 15:08:12 +00007408
Douglas Gregora16548e2009-08-11 05:31:07 +00007409template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007410ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007411TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
7412 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007413}
Mike Stump11289f42009-09-09 15:08:12 +00007414
Douglas Gregora16548e2009-08-11 05:31:07 +00007415template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007416ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007417TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007418 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007419 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7420 if (!Type)
7421 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007422
John McCalldadc5752010-08-24 06:29:42 +00007423 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00007424 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00007425 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007426 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007427
Douglas Gregora16548e2009-08-11 05:31:07 +00007428 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007429 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007430 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00007431 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007432
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00007433 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Eli Friedman89fe0d52013-08-15 22:02:56 +00007434 E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007435 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007436 E->getRParenLoc());
7437}
Mike Stump11289f42009-09-09 15:08:12 +00007438
Douglas Gregora16548e2009-08-11 05:31:07 +00007439template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007440ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007441TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007442 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00007443 TypeSourceInfo *TInfo
7444 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7445 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007446 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007447
Douglas Gregora16548e2009-08-11 05:31:07 +00007448 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00007449 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00007450 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007451
Douglas Gregor9da64192010-04-26 22:37:10 +00007452 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7453 E->getLocStart(),
7454 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00007455 E->getLocEnd());
7456 }
Mike Stump11289f42009-09-09 15:08:12 +00007457
Eli Friedman456f0182012-01-20 01:26:23 +00007458 // We don't know whether the subexpression is potentially evaluated until
7459 // after we perform semantic analysis. We speculatively assume it is
7460 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregora16548e2009-08-11 05:31:07 +00007461 // potentially evaluated.
Eli Friedman15681d62012-09-26 04:34:21 +00007462 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
7463 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00007464
John McCalldadc5752010-08-24 06:29:42 +00007465 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00007466 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007467 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007468
Douglas Gregora16548e2009-08-11 05:31:07 +00007469 if (!getDerived().AlwaysRebuild() &&
7470 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00007471 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007472
Douglas Gregor9da64192010-04-26 22:37:10 +00007473 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7474 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00007475 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007476 E->getLocEnd());
7477}
7478
7479template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007480ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00007481TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
7482 if (E->isTypeOperand()) {
7483 TypeSourceInfo *TInfo
7484 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7485 if (!TInfo)
7486 return ExprError();
7487
7488 if (!getDerived().AlwaysRebuild() &&
7489 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00007490 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00007491
Douglas Gregor69735112011-03-06 17:40:41 +00007492 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet9f4f2072010-09-08 12:20:18 +00007493 E->getLocStart(),
7494 TInfo,
7495 E->getLocEnd());
7496 }
7497
Francois Pichet9f4f2072010-09-08 12:20:18 +00007498 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7499
7500 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
7501 if (SubExpr.isInvalid())
7502 return ExprError();
7503
7504 if (!getDerived().AlwaysRebuild() &&
7505 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00007506 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00007507
7508 return getDerived().RebuildCXXUuidofExpr(E->getType(),
7509 E->getLocStart(),
7510 SubExpr.get(),
7511 E->getLocEnd());
7512}
7513
7514template<typename Derived>
7515ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007516TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007517 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007518}
Mike Stump11289f42009-09-09 15:08:12 +00007519
Douglas Gregora16548e2009-08-11 05:31:07 +00007520template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007521ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007522TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007523 CXXNullPtrLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007524 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007525}
Mike Stump11289f42009-09-09 15:08:12 +00007526
Douglas Gregora16548e2009-08-11 05:31:07 +00007527template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007528ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007529TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Richard Smithc3d2ebb2013-06-07 02:33:37 +00007530 QualType T = getSema().getCurrentThisType();
Mike Stump11289f42009-09-09 15:08:12 +00007531
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00007532 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
7533 // Make sure that we capture 'this'.
7534 getSema().CheckCXXThisCapture(E->getLocStart());
John McCallc3007a22010-10-26 07:05:15 +00007535 return SemaRef.Owned(E);
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00007536 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007537
Douglas Gregorb15af892010-01-07 23:12:05 +00007538 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00007539}
Mike Stump11289f42009-09-09 15:08:12 +00007540
Douglas Gregora16548e2009-08-11 05:31:07 +00007541template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007542ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007543TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007544 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007545 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007546 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007547
Douglas Gregora16548e2009-08-11 05:31:07 +00007548 if (!getDerived().AlwaysRebuild() &&
7549 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00007550 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007551
Douglas Gregor53e191ed2011-07-06 22:04:06 +00007552 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
7553 E->isThrownVariableInScope());
Douglas Gregora16548e2009-08-11 05:31:07 +00007554}
Mike Stump11289f42009-09-09 15:08:12 +00007555
Douglas Gregora16548e2009-08-11 05:31:07 +00007556template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007557ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007558TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00007559 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007560 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
7561 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007562 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00007563 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007564
Chandler Carruth794da4c2010-02-08 06:42:49 +00007565 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007566 Param == E->getParam())
John McCallc3007a22010-10-26 07:05:15 +00007567 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007568
Douglas Gregor033f6752009-12-23 23:03:06 +00007569 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00007570}
Mike Stump11289f42009-09-09 15:08:12 +00007571
Douglas Gregora16548e2009-08-11 05:31:07 +00007572template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007573ExprResult
Richard Smith852c9db2013-04-20 22:23:05 +00007574TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
7575 FieldDecl *Field
7576 = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(),
7577 E->getField()));
7578 if (!Field)
7579 return ExprError();
7580
7581 if (!getDerived().AlwaysRebuild() && Field == E->getField())
7582 return SemaRef.Owned(E);
7583
7584 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
7585}
7586
7587template<typename Derived>
7588ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00007589TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
7590 CXXScalarValueInitExpr *E) {
7591 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7592 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007593 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007594
Douglas Gregora16548e2009-08-11 05:31:07 +00007595 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00007596 T == E->getTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00007597 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007598
Chad Rosier1dcde962012-08-08 18:46:20 +00007599 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregor2b88c112010-09-08 00:15:04 +00007600 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00007601 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007602}
Mike Stump11289f42009-09-09 15:08:12 +00007603
Douglas Gregora16548e2009-08-11 05:31:07 +00007604template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007605ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007606TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007607 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00007608 TypeSourceInfo *AllocTypeInfo
7609 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
7610 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007611 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007612
Douglas Gregora16548e2009-08-11 05:31:07 +00007613 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00007614 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00007615 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007616 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007617
Douglas Gregora16548e2009-08-11 05:31:07 +00007618 // Transform the placement arguments (if any).
7619 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007620 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier1dcde962012-08-08 18:46:20 +00007621 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregora3efea12011-01-03 19:04:46 +00007622 E->getNumPlacementArgs(), true,
7623 PlacementArgs, &ArgumentChanged))
Sebastian Redl6047f072012-02-16 12:22:20 +00007624 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007625
Sebastian Redl6047f072012-02-16 12:22:20 +00007626 // Transform the initializer (if any).
7627 Expr *OldInit = E->getInitializer();
7628 ExprResult NewInit;
7629 if (OldInit)
7630 NewInit = getDerived().TransformExpr(OldInit);
7631 if (NewInit.isInvalid())
7632 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007633
Sebastian Redl6047f072012-02-16 12:22:20 +00007634 // Transform new operator and delete operator.
Douglas Gregord2d9da02010-02-26 00:38:10 +00007635 FunctionDecl *OperatorNew = 0;
7636 if (E->getOperatorNew()) {
7637 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007638 getDerived().TransformDecl(E->getLocStart(),
7639 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00007640 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00007641 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00007642 }
7643
7644 FunctionDecl *OperatorDelete = 0;
7645 if (E->getOperatorDelete()) {
7646 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007647 getDerived().TransformDecl(E->getLocStart(),
7648 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00007649 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00007650 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00007651 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007652
Douglas Gregora16548e2009-08-11 05:31:07 +00007653 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00007654 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007655 ArraySize.get() == E->getArraySize() &&
Sebastian Redl6047f072012-02-16 12:22:20 +00007656 NewInit.get() == OldInit &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00007657 OperatorNew == E->getOperatorNew() &&
7658 OperatorDelete == E->getOperatorDelete() &&
7659 !ArgumentChanged) {
7660 // Mark any declarations we need as referenced.
7661 // FIXME: instantiation-specific.
Douglas Gregord2d9da02010-02-26 00:38:10 +00007662 if (OperatorNew)
Eli Friedmanfa0df832012-02-02 03:46:19 +00007663 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregord2d9da02010-02-26 00:38:10 +00007664 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00007665 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00007666
Sebastian Redl6047f072012-02-16 12:22:20 +00007667 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor72912fb2011-07-26 15:11:03 +00007668 QualType ElementType
7669 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
7670 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
7671 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
7672 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedmanfa0df832012-02-02 03:46:19 +00007673 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor72912fb2011-07-26 15:11:03 +00007674 }
7675 }
7676 }
Sebastian Redl6047f072012-02-16 12:22:20 +00007677
John McCallc3007a22010-10-26 07:05:15 +00007678 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00007679 }
Mike Stump11289f42009-09-09 15:08:12 +00007680
Douglas Gregor0744ef62010-09-07 21:49:58 +00007681 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00007682 if (!ArraySize.get()) {
7683 // If no array size was specified, but the new expression was
7684 // instantiated with an array type (e.g., "new T" where T is
7685 // instantiated with "int[4]"), extract the outer bound from the
7686 // array type as our array size. We do this with constant and
7687 // dependently-sized array types.
7688 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
7689 if (!ArrayT) {
7690 // Do nothing
7691 } else if (const ConstantArrayType *ConsArrayT
7692 = dyn_cast<ConstantArrayType>(ArrayT)) {
Chad Rosier1dcde962012-08-08 18:46:20 +00007693 ArraySize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00007694 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
Chad Rosier1dcde962012-08-08 18:46:20 +00007695 ConsArrayT->getSize(),
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00007696 SemaRef.Context.getSizeType(),
7697 /*FIXME:*/E->getLocStart()));
Douglas Gregor2e9c7952009-12-22 17:13:37 +00007698 AllocType = ConsArrayT->getElementType();
7699 } else if (const DependentSizedArrayType *DepArrayT
7700 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
7701 if (DepArrayT->getSizeExpr()) {
John McCallc3007a22010-10-26 07:05:15 +00007702 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00007703 AllocType = DepArrayT->getElementType();
7704 }
7705 }
7706 }
Sebastian Redl6047f072012-02-16 12:22:20 +00007707
Douglas Gregora16548e2009-08-11 05:31:07 +00007708 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
7709 E->isGlobalNew(),
7710 /*FIXME:*/E->getLocStart(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007711 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00007712 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00007713 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007714 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00007715 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00007716 ArraySize.get(),
Sebastian Redl6047f072012-02-16 12:22:20 +00007717 E->getDirectInitRange(),
7718 NewInit.take());
Douglas Gregora16548e2009-08-11 05:31:07 +00007719}
Mike Stump11289f42009-09-09 15:08:12 +00007720
Douglas Gregora16548e2009-08-11 05:31:07 +00007721template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007722ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007723TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007724 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00007725 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007726 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007727
Douglas Gregord2d9da02010-02-26 00:38:10 +00007728 // Transform the delete operator, if known.
7729 FunctionDecl *OperatorDelete = 0;
7730 if (E->getOperatorDelete()) {
7731 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007732 getDerived().TransformDecl(E->getLocStart(),
7733 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00007734 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00007735 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00007736 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007737
Douglas Gregora16548e2009-08-11 05:31:07 +00007738 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00007739 Operand.get() == E->getArgument() &&
7740 OperatorDelete == E->getOperatorDelete()) {
7741 // Mark any declarations we need as referenced.
7742 // FIXME: instantiation-specific.
7743 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00007744 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00007745
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00007746 if (!E->getArgument()->isTypeDependent()) {
7747 QualType Destroyed = SemaRef.Context.getBaseElementType(
7748 E->getDestroyedType());
7749 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
7750 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +00007751 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedmanfa0df832012-02-02 03:46:19 +00007752 SemaRef.LookupDestructor(Record));
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00007753 }
7754 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007755
John McCallc3007a22010-10-26 07:05:15 +00007756 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00007757 }
Mike Stump11289f42009-09-09 15:08:12 +00007758
Douglas Gregora16548e2009-08-11 05:31:07 +00007759 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
7760 E->isGlobalDelete(),
7761 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00007762 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007763}
Mike Stump11289f42009-09-09 15:08:12 +00007764
Douglas Gregora16548e2009-08-11 05:31:07 +00007765template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007766ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00007767TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007768 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007769 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00007770 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007771 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007772
John McCallba7bf592010-08-24 05:47:05 +00007773 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00007774 bool MayBePseudoDestructor = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00007775 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00007776 E->getOperatorLoc(),
7777 E->isArrow()? tok::arrow : tok::period,
7778 ObjectTypePtr,
7779 MayBePseudoDestructor);
7780 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007781 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007782
John McCallba7bf592010-08-24 05:47:05 +00007783 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +00007784 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
7785 if (QualifierLoc) {
7786 QualifierLoc
7787 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
7788 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +00007789 return ExprError();
7790 }
Douglas Gregora6ce6082011-02-25 18:19:59 +00007791 CXXScopeSpec SS;
7792 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00007793
Douglas Gregor678f90d2010-02-25 01:56:36 +00007794 PseudoDestructorTypeStorage Destroyed;
7795 if (E->getDestroyedTypeInfo()) {
7796 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00007797 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregor579c15f2011-03-02 18:32:08 +00007798 ObjectType, 0, SS);
Douglas Gregor678f90d2010-02-25 01:56:36 +00007799 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007800 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00007801 Destroyed = DestroyedTypeInfo;
Douglas Gregorf39a8dd2011-11-09 02:19:47 +00007802 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregor678f90d2010-02-25 01:56:36 +00007803 // We aren't likely to be able to resolve the identifier down to a type
7804 // now anyway, so just retain the identifier.
7805 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
7806 E->getDestroyedTypeLoc());
7807 } else {
7808 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +00007809 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00007810 *E->getDestroyedTypeIdentifier(),
7811 E->getDestroyedTypeLoc(),
7812 /*Scope=*/0,
7813 SS, ObjectTypePtr,
7814 false);
7815 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007816 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007817
Douglas Gregor678f90d2010-02-25 01:56:36 +00007818 Destroyed
7819 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
7820 E->getDestroyedTypeLoc());
7821 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007822
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007823 TypeSourceInfo *ScopeTypeInfo = 0;
7824 if (E->getScopeTypeInfo()) {
Douglas Gregora88c55b2013-03-08 21:25:01 +00007825 CXXScopeSpec EmptySS;
7826 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
7827 E->getScopeTypeInfo(), ObjectType, 0, EmptySS);
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007828 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007829 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00007830 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007831
John McCallb268a282010-08-23 23:25:46 +00007832 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00007833 E->getOperatorLoc(),
7834 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +00007835 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007836 ScopeTypeInfo,
7837 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00007838 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00007839 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00007840}
Mike Stump11289f42009-09-09 15:08:12 +00007841
Douglas Gregorad8a3362009-09-04 17:36:40 +00007842template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007843ExprResult
John McCalld14a8642009-11-21 08:51:07 +00007844TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007845 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00007846 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
7847 Sema::LookupOrdinaryName);
7848
7849 // Transform all the decls.
7850 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
7851 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007852 NamedDecl *InstD = static_cast<NamedDecl*>(
7853 getDerived().TransformDecl(Old->getNameLoc(),
7854 *I));
John McCall84d87672009-12-10 09:41:52 +00007855 if (!InstD) {
7856 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7857 // This can happen because of dependent hiding.
7858 if (isa<UsingShadowDecl>(*I))
7859 continue;
Serge Pavlov82605302013-09-04 04:50:29 +00007860 else {
7861 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00007862 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00007863 }
John McCall84d87672009-12-10 09:41:52 +00007864 }
John McCalle66edc12009-11-24 19:00:30 +00007865
7866 // Expand using declarations.
7867 if (isa<UsingDecl>(InstD)) {
7868 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +00007869 for (auto *I : UD->shadows())
7870 R.addDecl(I);
John McCalle66edc12009-11-24 19:00:30 +00007871 continue;
7872 }
7873
7874 R.addDecl(InstD);
7875 }
7876
7877 // Resolve a kind, but don't do any further analysis. If it's
7878 // ambiguous, the callee needs to deal with it.
7879 R.resolveKind();
7880
7881 // Rebuild the nested-name qualifier, if present.
7882 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00007883 if (Old->getQualifierLoc()) {
7884 NestedNameSpecifierLoc QualifierLoc
7885 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7886 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007887 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007888
Douglas Gregor0da1d432011-02-28 20:01:57 +00007889 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00007890 }
7891
Douglas Gregor9262f472010-04-27 18:19:34 +00007892 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00007893 CXXRecordDecl *NamingClass
7894 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
7895 Old->getNameLoc(),
7896 Old->getNamingClass()));
Serge Pavlov82605302013-09-04 04:50:29 +00007897 if (!NamingClass) {
7898 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00007899 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00007900 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007901
Douglas Gregorda7be082010-04-27 16:10:10 +00007902 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00007903 }
7904
Abramo Bagnara7945c982012-01-27 09:46:47 +00007905 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
7906
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00007907 // If we have neither explicit template arguments, nor the template keyword,
7908 // it's a normal declaration name.
7909 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
John McCalle66edc12009-11-24 19:00:30 +00007910 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
7911
7912 // If we have template arguments, rebuild them, then rebuild the
7913 // templateid expression.
7914 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola3dd531d2012-08-28 04:13:54 +00007915 if (Old->hasExplicitTemplateArgs() &&
7916 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregor62e06f22010-12-20 17:31:10 +00007917 Old->getNumTemplateArgs(),
Serge Pavlov82605302013-09-04 04:50:29 +00007918 TransArgs)) {
7919 R.clear();
Douglas Gregor62e06f22010-12-20 17:31:10 +00007920 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00007921 }
John McCalle66edc12009-11-24 19:00:30 +00007922
Abramo Bagnara7945c982012-01-27 09:46:47 +00007923 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00007924 Old->requiresADL(), &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00007925}
Mike Stump11289f42009-09-09 15:08:12 +00007926
Douglas Gregora16548e2009-08-11 05:31:07 +00007927template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007928ExprResult
Douglas Gregor29c42f22012-02-24 07:38:34 +00007929TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
7930 bool ArgChanged = false;
Dmitri Gribenkof8579502013-01-12 19:30:44 +00007931 SmallVector<TypeSourceInfo *, 4> Args;
Douglas Gregor29c42f22012-02-24 07:38:34 +00007932 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
7933 TypeSourceInfo *From = E->getArg(I);
7934 TypeLoc FromTL = From->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00007935 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
Douglas Gregor29c42f22012-02-24 07:38:34 +00007936 TypeLocBuilder TLB;
7937 TLB.reserve(FromTL.getFullDataSize());
7938 QualType To = getDerived().TransformType(TLB, FromTL);
7939 if (To.isNull())
7940 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007941
Douglas Gregor29c42f22012-02-24 07:38:34 +00007942 if (To == From->getType())
7943 Args.push_back(From);
7944 else {
7945 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7946 ArgChanged = true;
7947 }
7948 continue;
7949 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007950
Douglas Gregor29c42f22012-02-24 07:38:34 +00007951 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00007952
Douglas Gregor29c42f22012-02-24 07:38:34 +00007953 // We have a pack expansion. Instantiate it.
David Blaikie6adc78e2013-02-18 22:06:02 +00007954 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
Douglas Gregor29c42f22012-02-24 07:38:34 +00007955 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
7956 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
7957 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00007958
Douglas Gregor29c42f22012-02-24 07:38:34 +00007959 // Determine whether the set of unexpanded parameter packs can and should
7960 // be expanded.
7961 bool Expand = true;
7962 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00007963 Optional<unsigned> OrigNumExpansions =
7964 ExpansionTL.getTypePtr()->getNumExpansions();
7965 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor29c42f22012-02-24 07:38:34 +00007966 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
7967 PatternTL.getSourceRange(),
7968 Unexpanded,
7969 Expand, RetainExpansion,
7970 NumExpansions))
7971 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007972
Douglas Gregor29c42f22012-02-24 07:38:34 +00007973 if (!Expand) {
7974 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00007975 // transformation on the pack expansion, producing another pack
Douglas Gregor29c42f22012-02-24 07:38:34 +00007976 // expansion.
7977 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier1dcde962012-08-08 18:46:20 +00007978
Douglas Gregor29c42f22012-02-24 07:38:34 +00007979 TypeLocBuilder TLB;
7980 TLB.reserve(From->getTypeLoc().getFullDataSize());
7981
7982 QualType To = getDerived().TransformType(TLB, PatternTL);
7983 if (To.isNull())
7984 return ExprError();
7985
Chad Rosier1dcde962012-08-08 18:46:20 +00007986 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00007987 PatternTL.getSourceRange(),
7988 ExpansionTL.getEllipsisLoc(),
7989 NumExpansions);
7990 if (To.isNull())
7991 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007992
Douglas Gregor29c42f22012-02-24 07:38:34 +00007993 PackExpansionTypeLoc ToExpansionTL
7994 = TLB.push<PackExpansionTypeLoc>(To);
7995 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7996 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7997 continue;
7998 }
7999
8000 // Expand the pack expansion by substituting for each argument in the
8001 // pack(s).
8002 for (unsigned I = 0; I != *NumExpansions; ++I) {
8003 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
8004 TypeLocBuilder TLB;
8005 TLB.reserve(PatternTL.getFullDataSize());
8006 QualType To = getDerived().TransformType(TLB, PatternTL);
8007 if (To.isNull())
8008 return ExprError();
8009
Eli Friedman5e05c4a2013-07-19 21:49:32 +00008010 if (To->containsUnexpandedParameterPack()) {
8011 To = getDerived().RebuildPackExpansionType(To,
8012 PatternTL.getSourceRange(),
8013 ExpansionTL.getEllipsisLoc(),
8014 NumExpansions);
8015 if (To.isNull())
8016 return ExprError();
8017
8018 PackExpansionTypeLoc ToExpansionTL
8019 = TLB.push<PackExpansionTypeLoc>(To);
8020 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8021 }
8022
Douglas Gregor29c42f22012-02-24 07:38:34 +00008023 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8024 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008025
Douglas Gregor29c42f22012-02-24 07:38:34 +00008026 if (!RetainExpansion)
8027 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00008028
Douglas Gregor29c42f22012-02-24 07:38:34 +00008029 // If we're supposed to retain a pack expansion, do so by temporarily
8030 // forgetting the partially-substituted parameter pack.
8031 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
8032
8033 TypeLocBuilder TLB;
8034 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00008035
Douglas Gregor29c42f22012-02-24 07:38:34 +00008036 QualType To = getDerived().TransformType(TLB, PatternTL);
8037 if (To.isNull())
8038 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008039
8040 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00008041 PatternTL.getSourceRange(),
8042 ExpansionTL.getEllipsisLoc(),
8043 NumExpansions);
8044 if (To.isNull())
8045 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008046
Douglas Gregor29c42f22012-02-24 07:38:34 +00008047 PackExpansionTypeLoc ToExpansionTL
8048 = TLB.push<PackExpansionTypeLoc>(To);
8049 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8050 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8051 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008052
Douglas Gregor29c42f22012-02-24 07:38:34 +00008053 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8054 return SemaRef.Owned(E);
8055
8056 return getDerived().RebuildTypeTrait(E->getTrait(),
8057 E->getLocStart(),
8058 Args,
8059 E->getLocEnd());
8060}
8061
8062template<typename Derived>
8063ExprResult
John Wiegley6242b6a2011-04-28 00:16:57 +00008064TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
8065 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
8066 if (!T)
8067 return ExprError();
8068
8069 if (!getDerived().AlwaysRebuild() &&
8070 T == E->getQueriedTypeSourceInfo())
8071 return SemaRef.Owned(E);
8072
8073 ExprResult SubExpr;
8074 {
8075 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8076 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
8077 if (SubExpr.isInvalid())
8078 return ExprError();
8079
8080 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
8081 return SemaRef.Owned(E);
8082 }
8083
8084 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
8085 E->getLocStart(),
8086 T,
8087 SubExpr.get(),
8088 E->getLocEnd());
8089}
8090
8091template<typename Derived>
8092ExprResult
John Wiegleyf9f65842011-04-25 06:54:41 +00008093TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
8094 ExprResult SubExpr;
8095 {
8096 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8097 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
8098 if (SubExpr.isInvalid())
8099 return ExprError();
8100
8101 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
8102 return SemaRef.Owned(E);
8103 }
8104
8105 return getDerived().RebuildExpressionTrait(
8106 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
8107}
8108
8109template<typename Derived>
8110ExprResult
John McCall8cd78132009-11-19 22:55:06 +00008111TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008112 DependentScopeDeclRefExpr *E) {
Richard Smithdb2630f2012-10-21 03:28:35 +00008113 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand*/false);
8114}
8115
8116template<typename Derived>
8117ExprResult
8118TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
8119 DependentScopeDeclRefExpr *E,
8120 bool IsAddressOfOperand) {
Reid Kleckner916ac4d2013-10-15 18:38:02 +00008121 assert(E->getQualifierLoc());
Douglas Gregor3a43fd62011-02-25 20:49:16 +00008122 NestedNameSpecifierLoc QualifierLoc
8123 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
8124 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008125 return ExprError();
Abramo Bagnara7945c982012-01-27 09:46:47 +00008126 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00008127
John McCall31f82722010-11-12 08:19:04 +00008128 // TODO: If this is a conversion-function-id, verify that the
8129 // destination type name (if present) resolves the same way after
8130 // instantiation as it did in the local scope.
8131
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008132 DeclarationNameInfo NameInfo
8133 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
8134 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00008135 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008136
John McCalle66edc12009-11-24 19:00:30 +00008137 if (!E->hasExplicitTemplateArgs()) {
8138 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3a43fd62011-02-25 20:49:16 +00008139 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008140 // Note: it is sufficient to compare the Name component of NameInfo:
8141 // if name has not changed, DNLoc has not changed either.
8142 NameInfo.getName() == E->getDeclName())
John McCallc3007a22010-10-26 07:05:15 +00008143 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00008144
Douglas Gregor3a43fd62011-02-25 20:49:16 +00008145 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008146 TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008147 NameInfo,
Richard Smithdb2630f2012-10-21 03:28:35 +00008148 /*TemplateArgs*/ 0,
8149 IsAddressOfOperand);
Douglas Gregord019ff62009-10-22 17:20:55 +00008150 }
John McCall6b51f282009-11-23 01:53:49 +00008151
8152 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008153 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8154 E->getNumTemplateArgs(),
8155 TransArgs))
8156 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008157
Douglas Gregor3a43fd62011-02-25 20:49:16 +00008158 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008159 TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008160 NameInfo,
Richard Smithdb2630f2012-10-21 03:28:35 +00008161 &TransArgs,
8162 IsAddressOfOperand);
Douglas Gregora16548e2009-08-11 05:31:07 +00008163}
8164
8165template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008166ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008167TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithd59b8322012-12-19 01:39:02 +00008168 // CXXConstructExprs other than for list-initialization and
8169 // CXXTemporaryObjectExpr are always implicit, so when we have
8170 // a 1-argument construction we just transform that argument.
Richard Smithdd2ca572012-11-26 08:32:48 +00008171 if ((E->getNumArgs() == 1 ||
8172 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithd59b8322012-12-19 01:39:02 +00008173 (!getDerived().DropCallArgument(E->getArg(0))) &&
8174 !E->isListInitialization())
Douglas Gregordb56b912010-02-03 03:01:57 +00008175 return getDerived().TransformExpr(E->getArg(0));
8176
Douglas Gregora16548e2009-08-11 05:31:07 +00008177 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
8178
8179 QualType T = getDerived().TransformType(E->getType());
8180 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00008181 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008182
8183 CXXConstructorDecl *Constructor
8184 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008185 getDerived().TransformDecl(E->getLocStart(),
8186 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008187 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00008188 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008189
Douglas Gregora16548e2009-08-11 05:31:07 +00008190 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008191 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00008192 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00008193 &ArgumentChanged))
8194 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008195
Douglas Gregora16548e2009-08-11 05:31:07 +00008196 if (!getDerived().AlwaysRebuild() &&
8197 T == E->getType() &&
8198 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00008199 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00008200 // Mark the constructor as referenced.
8201 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00008202 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00008203 return SemaRef.Owned(E);
Douglas Gregorde550352010-02-26 00:01:57 +00008204 }
Mike Stump11289f42009-09-09 15:08:12 +00008205
Douglas Gregordb121ba2009-12-14 16:27:04 +00008206 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
8207 Constructor, E->isElidable(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008208 Args,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00008209 E->hadMultipleCandidates(),
Richard Smithd59b8322012-12-19 01:39:02 +00008210 E->isListInitialization(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00008211 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00008212 E->getConstructionKind(),
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00008213 E->getParenOrBraceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00008214}
Mike Stump11289f42009-09-09 15:08:12 +00008215
Douglas Gregora16548e2009-08-11 05:31:07 +00008216/// \brief Transform a C++ temporary-binding expression.
8217///
Douglas Gregor363b1512009-12-24 18:51:59 +00008218/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
8219/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00008220template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008221ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008222TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00008223 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008224}
Mike Stump11289f42009-09-09 15:08:12 +00008225
John McCall5d413782010-12-06 08:20:24 +00008226/// \brief Transform a C++ expression that contains cleanups that should
8227/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +00008228///
John McCall5d413782010-12-06 08:20:24 +00008229/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +00008230/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00008231template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008232ExprResult
John McCall5d413782010-12-06 08:20:24 +00008233TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00008234 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008235}
Mike Stump11289f42009-09-09 15:08:12 +00008236
Douglas Gregora16548e2009-08-11 05:31:07 +00008237template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008238ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008239TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00008240 CXXTemporaryObjectExpr *E) {
8241 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8242 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00008243 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008244
Douglas Gregora16548e2009-08-11 05:31:07 +00008245 CXXConstructorDecl *Constructor
8246 = cast_or_null<CXXConstructorDecl>(
Chad Rosier1dcde962012-08-08 18:46:20 +00008247 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008248 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008249 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00008250 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008251
Douglas Gregora16548e2009-08-11 05:31:07 +00008252 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008253 SmallVector<Expr*, 8> Args;
Douglas Gregora16548e2009-08-11 05:31:07 +00008254 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +00008255 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00008256 &ArgumentChanged))
8257 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008258
Douglas Gregora16548e2009-08-11 05:31:07 +00008259 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00008260 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008261 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00008262 !ArgumentChanged) {
8263 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00008264 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00008265 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00008266 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008267
Richard Smithd59b8322012-12-19 01:39:02 +00008268 // FIXME: Pass in E->isListInitialization().
Douglas Gregor2b88c112010-09-08 00:15:04 +00008269 return getDerived().RebuildCXXTemporaryObjectExpr(T,
8270 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008271 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00008272 E->getLocEnd());
8273}
Mike Stump11289f42009-09-09 15:08:12 +00008274
Douglas Gregora16548e2009-08-11 05:31:07 +00008275template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008276ExprResult
Douglas Gregore31e6062012-02-07 10:09:13 +00008277TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008278
8279 // Transform any init-capture expressions before entering the scope of the
8280 // lambda body, because they are not semantically within that scope.
8281 SmallVector<InitCaptureInfoTy, 8> InitCaptureExprsAndTypes;
8282 InitCaptureExprsAndTypes.resize(E->explicit_capture_end() -
8283 E->explicit_capture_begin());
8284
8285 for (LambdaExpr::capture_iterator C = E->capture_begin(),
8286 CEnd = E->capture_end();
8287 C != CEnd; ++C) {
8288 if (!C->isInitCapture())
8289 continue;
8290 EnterExpressionEvaluationContext EEEC(getSema(),
8291 Sema::PotentiallyEvaluated);
8292 ExprResult NewExprInitResult = getDerived().TransformInitializer(
8293 C->getCapturedVar()->getInit(),
8294 C->getCapturedVar()->getInitStyle() == VarDecl::CallInit);
8295
8296 if (NewExprInitResult.isInvalid())
8297 return ExprError();
8298 Expr *NewExprInit = NewExprInitResult.get();
8299
8300 VarDecl *OldVD = C->getCapturedVar();
8301 QualType NewInitCaptureType =
8302 getSema().performLambdaInitCaptureInitialization(C->getLocation(),
8303 OldVD->getType()->isReferenceType(), OldVD->getIdentifier(),
8304 NewExprInit);
8305 NewExprInitResult = NewExprInit;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008306 InitCaptureExprsAndTypes[C - E->capture_begin()] =
8307 std::make_pair(NewExprInitResult, NewInitCaptureType);
8308
8309 }
8310
Faisal Vali524ca282013-11-12 01:40:44 +00008311 LambdaScopeInfo *LSI = getSema().PushLambdaScope();
Faisal Vali2cba1332013-10-23 06:44:28 +00008312 // Transform the template parameters, and add them to the current
8313 // instantiation scope. The null case is handled correctly.
8314 LSI->GLTemplateParameterList = getDerived().TransformTemplateParameterList(
8315 E->getTemplateParameterList());
8316
8317 // Check to see if the TypeSourceInfo of the call operator needs to
8318 // be transformed, and if so do the transformation in the
8319 // CurrentInstantiationScope.
8320
8321 TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo();
8322 FunctionProtoTypeLoc OldCallOpFPTL =
8323 OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>();
8324 TypeSourceInfo *NewCallOpTSI = 0;
8325
8326 const bool CallOpWasAlreadyTransformed =
8327 getDerived().AlreadyTransformed(OldCallOpTSI->getType());
8328
8329 // Use the Old Call Operator's TypeSourceInfo if it is already transformed.
8330 if (CallOpWasAlreadyTransformed)
8331 NewCallOpTSI = OldCallOpTSI;
8332 else {
8333 // Transform the TypeSourceInfo of the Original Lambda's Call Operator.
8334 // The transformation MUST be done in the CurrentInstantiationScope since
8335 // it introduces a mapping of the original to the newly created
8336 // transformed parameters.
8337
8338 TypeLocBuilder NewCallOpTLBuilder;
8339 QualType NewCallOpType = TransformFunctionProtoType(NewCallOpTLBuilder,
8340 OldCallOpFPTL,
8341 0, 0);
8342 NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context,
8343 NewCallOpType);
Faisal Vali2b391ab2013-09-26 19:54:12 +00008344 }
Faisal Vali2cba1332013-10-23 06:44:28 +00008345 // Extract the ParmVarDecls from the NewCallOpTSI and add them to
8346 // the vector below - this will be used to synthesize the
8347 // NewCallOperator. Additionally, add the parameters of the untransformed
8348 // lambda call operator to the CurrentInstantiationScope.
8349 SmallVector<ParmVarDecl *, 4> Params;
8350 {
8351 FunctionProtoTypeLoc NewCallOpFPTL =
8352 NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>();
8353 ParmVarDecl **NewParamDeclArray = NewCallOpFPTL.getParmArray();
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00008354 const unsigned NewNumArgs = NewCallOpFPTL.getNumParams();
Faisal Vali2cba1332013-10-23 06:44:28 +00008355
8356 for (unsigned I = 0; I < NewNumArgs; ++I) {
8357 // If this call operator's type does not require transformation,
8358 // the parameters do not get added to the current instantiation scope,
8359 // - so ADD them! This allows the following to compile when the enclosing
8360 // template is specialized and the entire lambda expression has to be
8361 // transformed.
8362 // template<class T> void foo(T t) {
8363 // auto L = [](auto a) {
8364 // auto M = [](char b) { <-- note: non-generic lambda
8365 // auto N = [](auto c) {
8366 // int x = sizeof(a);
8367 // x = sizeof(b); <-- specifically this line
8368 // x = sizeof(c);
8369 // };
8370 // };
8371 // };
8372 // }
8373 // foo('a')
8374 if (CallOpWasAlreadyTransformed)
8375 getDerived().transformedLocalDecl(NewParamDeclArray[I],
8376 NewParamDeclArray[I]);
8377 // Add to Params array, so these parameters can be used to create
8378 // the newly transformed call operator.
8379 Params.push_back(NewParamDeclArray[I]);
8380 }
8381 }
8382
8383 if (!NewCallOpTSI)
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008384 return ExprError();
8385
Eli Friedmand564afb2012-09-19 01:18:11 +00008386 // Create the local class that will describe the lambda.
8387 CXXRecordDecl *Class
8388 = getSema().createLambdaClosureType(E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +00008389 NewCallOpTSI,
Faisal Valic1a6dc42013-10-23 16:10:50 +00008390 /*KnownDependent=*/false,
8391 E->getCaptureDefault());
8392
Eli Friedmand564afb2012-09-19 01:18:11 +00008393 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
8394
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008395 // Build the call operator.
Faisal Vali2cba1332013-10-23 06:44:28 +00008396 CXXMethodDecl *NewCallOperator
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008397 = getSema().startLambdaDefinition(Class, E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +00008398 NewCallOpTSI,
Douglas Gregoradb376e2012-02-14 22:28:59 +00008399 E->getCallOperator()->getLocEnd(),
Richard Smith505df232012-07-22 23:45:10 +00008400 Params);
Faisal Vali2cba1332013-10-23 06:44:28 +00008401 LSI->CallOperator = NewCallOperator;
Rafael Espindola4b35f272013-10-04 14:28:51 +00008402
Faisal Vali2cba1332013-10-23 06:44:28 +00008403 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
8404
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008405 return getDerived().TransformLambdaScope(E, NewCallOperator,
8406 InitCaptureExprsAndTypes);
Richard Smith2589b9802012-07-25 03:56:55 +00008407}
8408
8409template<typename Derived>
8410ExprResult
8411TreeTransform<Derived>::TransformLambdaScope(LambdaExpr *E,
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008412 CXXMethodDecl *CallOperator,
8413 ArrayRef<InitCaptureInfoTy> InitCaptureExprsAndTypes) {
Richard Smithba71c082013-05-16 06:20:58 +00008414 bool Invalid = false;
8415
Douglas Gregorb4328232012-02-14 00:00:48 +00008416 // Introduce the context of the call operator.
Richard Smith7ff2bcb2014-01-24 01:54:52 +00008417 Sema::ContextRAII SavedContext(getSema(), CallOperator,
8418 /*NewThisContext*/false);
Douglas Gregorb4328232012-02-14 00:00:48 +00008419
Faisal Vali2b391ab2013-09-26 19:54:12 +00008420 LambdaScopeInfo *const LSI = getSema().getCurLambda();
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008421 // Enter the scope of the lambda.
Faisal Vali2b391ab2013-09-26 19:54:12 +00008422 getSema().buildLambdaScope(LSI, CallOperator, E->getIntroducerRange(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008423 E->getCaptureDefault(),
James Dennettddd36ff2013-08-09 23:08:25 +00008424 E->getCaptureDefaultLoc(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008425 E->hasExplicitParameters(),
8426 E->hasExplicitResultType(),
8427 E->isMutable());
Chad Rosier1dcde962012-08-08 18:46:20 +00008428
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008429 // Transform captures.
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008430 bool FinishedExplicitCaptures = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00008431 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008432 CEnd = E->capture_end();
8433 C != CEnd; ++C) {
8434 // When we hit the first implicit capture, tell Sema that we've finished
8435 // the list of explicit captures.
8436 if (!FinishedExplicitCaptures && C->isImplicit()) {
8437 getSema().finishLambdaExplicitCaptures(LSI);
8438 FinishedExplicitCaptures = true;
8439 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008440
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008441 // Capturing 'this' is trivial.
8442 if (C->capturesThis()) {
8443 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
8444 continue;
8445 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008446
Richard Smithba71c082013-05-16 06:20:58 +00008447 // Rebuild init-captures, including the implied field declaration.
8448 if (C->isInitCapture()) {
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008449
8450 InitCaptureInfoTy InitExprTypePair =
8451 InitCaptureExprsAndTypes[C - E->capture_begin()];
8452 ExprResult Init = InitExprTypePair.first;
8453 QualType InitQualType = InitExprTypePair.second;
8454 if (Init.isInvalid() || InitQualType.isNull()) {
Richard Smithba71c082013-05-16 06:20:58 +00008455 Invalid = true;
8456 continue;
8457 }
Richard Smithbb13c9a2013-09-28 04:02:39 +00008458 VarDecl *OldVD = C->getCapturedVar();
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008459 VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl(
8460 OldVD->getLocation(), InitExprTypePair.second,
8461 OldVD->getIdentifier(), Init.get());
Richard Smithbb13c9a2013-09-28 04:02:39 +00008462 if (!NewVD)
Richard Smithba71c082013-05-16 06:20:58 +00008463 Invalid = true;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008464 else {
Richard Smithbb13c9a2013-09-28 04:02:39 +00008465 getDerived().transformedLocalDecl(OldVD, NewVD);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00008466 }
Richard Smithbb13c9a2013-09-28 04:02:39 +00008467 getSema().buildInitCaptureField(LSI, NewVD);
Richard Smithba71c082013-05-16 06:20:58 +00008468 continue;
8469 }
8470
8471 assert(C->capturesVariable() && "unexpected kind of lambda capture");
8472
Douglas Gregor3e308b12012-02-14 19:27:52 +00008473 // Determine the capture kind for Sema.
8474 Sema::TryCaptureKind Kind
8475 = C->isImplicit()? Sema::TryCapture_Implicit
8476 : C->getCaptureKind() == LCK_ByCopy
8477 ? Sema::TryCapture_ExplicitByVal
8478 : Sema::TryCapture_ExplicitByRef;
8479 SourceLocation EllipsisLoc;
8480 if (C->isPackExpansion()) {
8481 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
8482 bool ShouldExpand = false;
8483 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00008484 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +00008485 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
8486 C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +00008487 Unexpanded,
8488 ShouldExpand, RetainExpansion,
Richard Smithba71c082013-05-16 06:20:58 +00008489 NumExpansions)) {
8490 Invalid = true;
8491 continue;
8492 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008493
Douglas Gregor3e308b12012-02-14 19:27:52 +00008494 if (ShouldExpand) {
8495 // The transform has determined that we should perform an expansion;
8496 // transform and capture each of the arguments.
8497 // expansion of the pattern. Do so.
8498 VarDecl *Pack = C->getCapturedVar();
8499 for (unsigned I = 0; I != *NumExpansions; ++I) {
8500 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8501 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +00008502 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +00008503 Pack));
8504 if (!CapturedVar) {
8505 Invalid = true;
8506 continue;
8507 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008508
Douglas Gregor3e308b12012-02-14 19:27:52 +00008509 // Capture the transformed variable.
Chad Rosier1dcde962012-08-08 18:46:20 +00008510 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
8511 }
Douglas Gregor3e308b12012-02-14 19:27:52 +00008512 continue;
8513 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008514
Douglas Gregor3e308b12012-02-14 19:27:52 +00008515 EllipsisLoc = C->getEllipsisLoc();
8516 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008517
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008518 // Transform the captured variable.
8519 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +00008520 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008521 C->getCapturedVar()));
8522 if (!CapturedVar) {
8523 Invalid = true;
8524 continue;
8525 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008526
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008527 // Capture the transformed variable.
Douglas Gregorfdf598e2012-02-18 09:37:24 +00008528 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008529 }
8530 if (!FinishedExplicitCaptures)
8531 getSema().finishLambdaExplicitCaptures(LSI);
8532
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008533
8534 // Enter a new evaluation context to insulate the lambda from any
8535 // cleanups from the enclosing full-expression.
Chad Rosier1dcde962012-08-08 18:46:20 +00008536 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008537
8538 if (Invalid) {
Chad Rosier1dcde962012-08-08 18:46:20 +00008539 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00008540 /*IsInstantiation=*/true);
8541 return ExprError();
8542 }
8543
8544 // Instantiate the body of the lambda expression.
Douglas Gregorb4328232012-02-14 00:00:48 +00008545 StmtResult Body = getDerived().TransformStmt(E->getBody());
8546 if (Body.isInvalid()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00008547 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
Douglas Gregorb4328232012-02-14 00:00:48 +00008548 /*IsInstantiation=*/true);
Chad Rosier1dcde962012-08-08 18:46:20 +00008549 return ExprError();
Douglas Gregorb4328232012-02-14 00:00:48 +00008550 }
Douglas Gregor7fcbd902012-02-21 00:37:24 +00008551
Chad Rosier1dcde962012-08-08 18:46:20 +00008552 return getSema().ActOnLambdaExpr(E->getLocStart(), Body.take(),
Douglas Gregorb61e8092012-04-04 17:40:10 +00008553 /*CurScope=*/0, /*IsInstantiation=*/true);
Douglas Gregore31e6062012-02-07 10:09:13 +00008554}
8555
8556template<typename Derived>
8557ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008558TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008559 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00008560 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8561 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00008562 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008563
Douglas Gregora16548e2009-08-11 05:31:07 +00008564 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008565 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +00008566 Args.reserve(E->arg_size());
Chad Rosier1dcde962012-08-08 18:46:20 +00008567 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00008568 &ArgumentChanged))
8569 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008570
Douglas Gregora16548e2009-08-11 05:31:07 +00008571 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00008572 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008573 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00008574 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00008575
Douglas Gregora16548e2009-08-11 05:31:07 +00008576 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +00008577 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +00008578 E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008579 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00008580 E->getRParenLoc());
8581}
Mike Stump11289f42009-09-09 15:08:12 +00008582
Douglas Gregora16548e2009-08-11 05:31:07 +00008583template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008584ExprResult
John McCall8cd78132009-11-19 22:55:06 +00008585TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008586 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008587 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00008588 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00008589 Expr *OldBase;
8590 QualType BaseType;
8591 QualType ObjectType;
8592 if (!E->isImplicitAccess()) {
8593 OldBase = E->getBase();
8594 Base = getDerived().TransformExpr(OldBase);
8595 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008596 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008597
John McCall2d74de92009-12-01 22:10:20 +00008598 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +00008599 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +00008600 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00008601 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00008602 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00008603 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00008604 ObjectTy,
8605 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00008606 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008607 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00008608
John McCallba7bf592010-08-24 05:47:05 +00008609 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +00008610 BaseType = ((Expr*) Base.get())->getType();
8611 } else {
8612 OldBase = 0;
8613 BaseType = getDerived().TransformType(E->getBaseType());
8614 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
8615 }
Mike Stump11289f42009-09-09 15:08:12 +00008616
Douglas Gregora5cb6da2009-10-20 05:58:46 +00008617 // Transform the first part of the nested-name-specifier that qualifies
8618 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00008619 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00008620 = getDerived().TransformFirstQualifierInScope(
Douglas Gregore16af532011-02-28 18:50:33 +00008621 E->getFirstQualifierFoundInScope(),
8622 E->getQualifierLoc().getBeginLoc());
Mike Stump11289f42009-09-09 15:08:12 +00008623
Douglas Gregore16af532011-02-28 18:50:33 +00008624 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00008625 if (E->getQualifier()) {
Douglas Gregore16af532011-02-28 18:50:33 +00008626 QualifierLoc
8627 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
8628 ObjectType,
8629 FirstQualifierInScope);
8630 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008631 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +00008632 }
Mike Stump11289f42009-09-09 15:08:12 +00008633
Abramo Bagnara7945c982012-01-27 09:46:47 +00008634 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
8635
John McCall31f82722010-11-12 08:19:04 +00008636 // TODO: If this is a conversion-function-id, verify that the
8637 // destination type name (if present) resolves the same way after
8638 // instantiation as it did in the local scope.
8639
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008640 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +00008641 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008642 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00008643 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008644
John McCall2d74de92009-12-01 22:10:20 +00008645 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00008646 // This is a reference to a member without an explicitly-specified
8647 // template argument list. Optimize for this common case.
8648 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00008649 Base.get() == OldBase &&
8650 BaseType == E->getBaseType() &&
Douglas Gregore16af532011-02-28 18:50:33 +00008651 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008652 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00008653 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCallc3007a22010-10-26 07:05:15 +00008654 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00008655
John McCallb268a282010-08-23 23:25:46 +00008656 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00008657 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00008658 E->isArrow(),
8659 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00008660 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008661 TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00008662 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008663 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00008664 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00008665 }
8666
John McCall6b51f282009-11-23 01:53:49 +00008667 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008668 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8669 E->getNumTemplateArgs(),
8670 TransArgs))
8671 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008672
John McCallb268a282010-08-23 23:25:46 +00008673 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00008674 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00008675 E->isArrow(),
8676 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00008677 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008678 TemplateKWLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +00008679 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008680 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00008681 &TransArgs);
8682}
8683
8684template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008685ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008686TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00008687 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00008688 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00008689 QualType BaseType;
8690 if (!Old->isImplicitAccess()) {
8691 Base = getDerived().TransformExpr(Old->getBase());
8692 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008693 return ExprError();
Richard Smithcab9a7d2011-10-26 19:06:56 +00008694 Base = getSema().PerformMemberExprBaseConversion(Base.take(),
8695 Old->isArrow());
8696 if (Base.isInvalid())
8697 return ExprError();
8698 BaseType = Base.get()->getType();
John McCall2d74de92009-12-01 22:10:20 +00008699 } else {
8700 BaseType = getDerived().TransformType(Old->getBaseType());
8701 }
John McCall10eae182009-11-30 22:42:35 +00008702
Douglas Gregor0da1d432011-02-28 20:01:57 +00008703 NestedNameSpecifierLoc QualifierLoc;
8704 if (Old->getQualifierLoc()) {
8705 QualifierLoc
8706 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
8707 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008708 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00008709 }
8710
Abramo Bagnara7945c982012-01-27 09:46:47 +00008711 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
8712
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008713 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +00008714 Sema::LookupOrdinaryName);
8715
8716 // Transform all the decls.
8717 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
8718 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008719 NamedDecl *InstD = static_cast<NamedDecl*>(
8720 getDerived().TransformDecl(Old->getMemberLoc(),
8721 *I));
John McCall84d87672009-12-10 09:41:52 +00008722 if (!InstD) {
8723 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
8724 // This can happen because of dependent hiding.
8725 if (isa<UsingShadowDecl>(*I))
8726 continue;
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00008727 else {
8728 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00008729 return ExprError();
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00008730 }
John McCall84d87672009-12-10 09:41:52 +00008731 }
John McCall10eae182009-11-30 22:42:35 +00008732
8733 // Expand using declarations.
8734 if (isa<UsingDecl>(InstD)) {
8735 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +00008736 for (auto *I : UD->shadows())
8737 R.addDecl(I);
John McCall10eae182009-11-30 22:42:35 +00008738 continue;
8739 }
8740
8741 R.addDecl(InstD);
8742 }
8743
8744 R.resolveKind();
8745
Douglas Gregor9262f472010-04-27 18:19:34 +00008746 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00008747 if (Old->getNamingClass()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00008748 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00008749 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00008750 Old->getMemberLoc(),
8751 Old->getNamingClass()));
8752 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00008753 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008754
Douglas Gregorda7be082010-04-27 16:10:10 +00008755 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00008756 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008757
John McCall10eae182009-11-30 22:42:35 +00008758 TemplateArgumentListInfo TransArgs;
8759 if (Old->hasExplicitTemplateArgs()) {
8760 TransArgs.setLAngleLoc(Old->getLAngleLoc());
8761 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008762 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
8763 Old->getNumTemplateArgs(),
8764 TransArgs))
8765 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00008766 }
John McCall38836f02010-01-15 08:34:02 +00008767
8768 // FIXME: to do this check properly, we will need to preserve the
8769 // first-qualifier-in-scope here, just in case we had a dependent
8770 // base (and therefore couldn't do the check) and a
8771 // nested-name-qualifier (and therefore could do the lookup).
8772 NamedDecl *FirstQualifierInScope = 0;
Chad Rosier1dcde962012-08-08 18:46:20 +00008773
John McCallb268a282010-08-23 23:25:46 +00008774 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00008775 BaseType,
John McCall10eae182009-11-30 22:42:35 +00008776 Old->getOperatorLoc(),
8777 Old->isArrow(),
Douglas Gregor0da1d432011-02-28 20:01:57 +00008778 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008779 TemplateKWLoc,
John McCall38836f02010-01-15 08:34:02 +00008780 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00008781 R,
8782 (Old->hasExplicitTemplateArgs()
8783 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00008784}
8785
8786template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008787ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +00008788TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Alexis Hunt414e3e32011-05-31 19:54:49 +00008789 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00008790 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
8791 if (SubExpr.isInvalid())
8792 return ExprError();
8793
8794 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCallc3007a22010-10-26 07:05:15 +00008795 return SemaRef.Owned(E);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00008796
8797 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
8798}
8799
8800template<typename Derived>
8801ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +00008802TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +00008803 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
8804 if (Pattern.isInvalid())
8805 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008806
Douglas Gregor0f836ea2011-01-13 00:19:55 +00008807 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
8808 return SemaRef.Owned(E);
8809
Douglas Gregorb8840002011-01-14 21:20:45 +00008810 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
8811 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +00008812}
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008813
8814template<typename Derived>
8815ExprResult
8816TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
8817 // If E is not value-dependent, then nothing will change when we transform it.
8818 // Note: This is an instantiation-centric view.
8819 if (!E->isValueDependent())
8820 return SemaRef.Owned(E);
8821
8822 // Note: None of the implementations of TryExpandParameterPacks can ever
8823 // produce a diagnostic when given only a single unexpanded parameter pack,
Chad Rosier1dcde962012-08-08 18:46:20 +00008824 // so
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008825 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
8826 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00008827 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00008828 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +00008829 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikieb9c168a2011-09-22 02:34:54 +00008830 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00008831 ShouldExpand, RetainExpansion,
8832 NumExpansions))
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008833 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008834
Douglas Gregorab96bcf2011-10-10 18:59:29 +00008835 if (RetainExpansion)
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008836 return SemaRef.Owned(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00008837
Douglas Gregorab96bcf2011-10-10 18:59:29 +00008838 NamedDecl *Pack = E->getPack();
8839 if (!ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00008840 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
Douglas Gregorab96bcf2011-10-10 18:59:29 +00008841 Pack));
8842 if (!Pack)
8843 return ExprError();
8844 }
8845
Chad Rosier1dcde962012-08-08 18:46:20 +00008846
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008847 // We now know the length of the parameter pack, so build a new expression
8848 // that stores that length.
Chad Rosier1dcde962012-08-08 18:46:20 +00008849 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
8850 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregorab96bcf2011-10-10 18:59:29 +00008851 NumExpansions);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00008852}
8853
Douglas Gregore8e9dd62011-01-03 17:17:50 +00008854template<typename Derived>
8855ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +00008856TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
8857 SubstNonTypeTemplateParmPackExpr *E) {
8858 // Default behavior is to do nothing with this transformation.
8859 return SemaRef.Owned(E);
8860}
8861
8862template<typename Derived>
8863ExprResult
John McCall7c454bb2011-07-15 05:09:51 +00008864TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
8865 SubstNonTypeTemplateParmExpr *E) {
8866 // Default behavior is to do nothing with this transformation.
8867 return SemaRef.Owned(E);
8868}
8869
8870template<typename Derived>
8871ExprResult
Richard Smithb15fe3a2012-09-12 00:56:43 +00008872TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
8873 // Default behavior is to do nothing with this transformation.
8874 return SemaRef.Owned(E);
8875}
8876
8877template<typename Derived>
8878ExprResult
Douglas Gregorfe314812011-06-21 17:03:29 +00008879TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
8880 MaterializeTemporaryExpr *E) {
8881 return getDerived().TransformExpr(E->GetTemporaryExpr());
8882}
Chad Rosier1dcde962012-08-08 18:46:20 +00008883
Douglas Gregorfe314812011-06-21 17:03:29 +00008884template<typename Derived>
8885ExprResult
Richard Smithcc1b96d2013-06-12 22:31:48 +00008886TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
8887 CXXStdInitializerListExpr *E) {
8888 return getDerived().TransformExpr(E->getSubExpr());
8889}
8890
8891template<typename Derived>
8892ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008893TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00008894 return SemaRef.MaybeBindToTemporary(E);
8895}
8896
8897template<typename Derived>
8898ExprResult
8899TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Jordy Rose8986c5992012-03-12 17:53:02 +00008900 return SemaRef.Owned(E);
Ted Kremeneke65b0862012-03-06 20:05:56 +00008901}
8902
8903template<typename Derived>
8904ExprResult
Patrick Beard0caa3942012-04-19 00:25:12 +00008905TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
8906 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
8907 if (SubExpr.isInvalid())
8908 return ExprError();
8909
8910 if (!getDerived().AlwaysRebuild() &&
8911 SubExpr.get() == E->getSubExpr())
8912 return SemaRef.Owned(E);
8913
8914 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremeneke65b0862012-03-06 20:05:56 +00008915}
8916
8917template<typename Derived>
8918ExprResult
8919TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
8920 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +00008921 SmallVector<Expr *, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +00008922 bool ArgChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00008923 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremeneke65b0862012-03-06 20:05:56 +00008924 /*IsCall=*/false, Elements, &ArgChanged))
8925 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008926
Ted Kremeneke65b0862012-03-06 20:05:56 +00008927 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8928 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00008929
Ted Kremeneke65b0862012-03-06 20:05:56 +00008930 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
8931 Elements.data(),
8932 Elements.size());
8933}
8934
8935template<typename Derived>
8936ExprResult
8937TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier1dcde962012-08-08 18:46:20 +00008938 ObjCDictionaryLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00008939 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +00008940 SmallVector<ObjCDictionaryElement, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +00008941 bool ArgChanged = false;
8942 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
8943 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier1dcde962012-08-08 18:46:20 +00008944
Ted Kremeneke65b0862012-03-06 20:05:56 +00008945 if (OrigElement.isPackExpansion()) {
8946 // This key/value element is a pack expansion.
8947 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
8948 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
8949 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
8950 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
8951
8952 // Determine whether the set of unexpanded parameter packs can
8953 // and should be expanded.
8954 bool Expand = true;
8955 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00008956 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
8957 Optional<unsigned> NumExpansions = OrigNumExpansions;
Ted Kremeneke65b0862012-03-06 20:05:56 +00008958 SourceRange PatternRange(OrigElement.Key->getLocStart(),
8959 OrigElement.Value->getLocEnd());
8960 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
8961 PatternRange,
8962 Unexpanded,
8963 Expand, RetainExpansion,
8964 NumExpansions))
8965 return ExprError();
8966
8967 if (!Expand) {
8968 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00008969 // transformation on the pack expansion, producing another pack
Ted Kremeneke65b0862012-03-06 20:05:56 +00008970 // expansion.
8971 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
8972 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8973 if (Key.isInvalid())
8974 return ExprError();
8975
8976 if (Key.get() != OrigElement.Key)
8977 ArgChanged = true;
8978
8979 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8980 if (Value.isInvalid())
8981 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008982
Ted Kremeneke65b0862012-03-06 20:05:56 +00008983 if (Value.get() != OrigElement.Value)
8984 ArgChanged = true;
8985
Chad Rosier1dcde962012-08-08 18:46:20 +00008986 ObjCDictionaryElement Expansion = {
Ted Kremeneke65b0862012-03-06 20:05:56 +00008987 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
8988 };
8989 Elements.push_back(Expansion);
8990 continue;
8991 }
8992
8993 // Record right away that the argument was changed. This needs
8994 // to happen even if the array expands to nothing.
8995 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00008996
Ted Kremeneke65b0862012-03-06 20:05:56 +00008997 // The transform has determined that we should perform an elementwise
8998 // expansion of the pattern. Do so.
8999 for (unsigned I = 0; I != *NumExpansions; ++I) {
9000 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
9001 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
9002 if (Key.isInvalid())
9003 return ExprError();
9004
9005 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
9006 if (Value.isInvalid())
9007 return ExprError();
9008
Chad Rosier1dcde962012-08-08 18:46:20 +00009009 ObjCDictionaryElement Element = {
Ted Kremeneke65b0862012-03-06 20:05:56 +00009010 Key.get(), Value.get(), SourceLocation(), NumExpansions
9011 };
9012
9013 // If any unexpanded parameter packs remain, we still have a
9014 // pack expansion.
9015 if (Key.get()->containsUnexpandedParameterPack() ||
9016 Value.get()->containsUnexpandedParameterPack())
9017 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier1dcde962012-08-08 18:46:20 +00009018
Ted Kremeneke65b0862012-03-06 20:05:56 +00009019 Elements.push_back(Element);
9020 }
9021
9022 // We've finished with this pack expansion.
9023 continue;
9024 }
9025
9026 // Transform and check key.
9027 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
9028 if (Key.isInvalid())
9029 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009030
Ted Kremeneke65b0862012-03-06 20:05:56 +00009031 if (Key.get() != OrigElement.Key)
9032 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009033
Ted Kremeneke65b0862012-03-06 20:05:56 +00009034 // Transform and check value.
9035 ExprResult Value
9036 = getDerived().TransformExpr(OrigElement.Value);
9037 if (Value.isInvalid())
9038 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009039
Ted Kremeneke65b0862012-03-06 20:05:56 +00009040 if (Value.get() != OrigElement.Value)
9041 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009042
9043 ObjCDictionaryElement Element = {
David Blaikie7a30dc52013-02-21 01:47:18 +00009044 Key.get(), Value.get(), SourceLocation(), None
Ted Kremeneke65b0862012-03-06 20:05:56 +00009045 };
9046 Elements.push_back(Element);
9047 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009048
Ted Kremeneke65b0862012-03-06 20:05:56 +00009049 if (!getDerived().AlwaysRebuild() && !ArgChanged)
9050 return SemaRef.MaybeBindToTemporary(E);
9051
9052 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
9053 Elements.data(),
9054 Elements.size());
Douglas Gregora16548e2009-08-11 05:31:07 +00009055}
9056
Mike Stump11289f42009-09-09 15:08:12 +00009057template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009058ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009059TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00009060 TypeSourceInfo *EncodedTypeInfo
9061 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
9062 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009063 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009064
Douglas Gregora16548e2009-08-11 05:31:07 +00009065 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00009066 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00009067 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009068
9069 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00009070 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00009071 E->getRParenLoc());
9072}
Mike Stump11289f42009-09-09 15:08:12 +00009073
Douglas Gregora16548e2009-08-11 05:31:07 +00009074template<typename Derived>
John McCall31168b02011-06-15 23:02:42 +00009075ExprResult TreeTransform<Derived>::
9076TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
John McCallbc489892013-04-11 02:14:26 +00009077 // This is a kind of implicit conversion, and it needs to get dropped
9078 // and recomputed for the same general reasons that ImplicitCastExprs
9079 // do, as well a more specific one: this expression is only valid when
9080 // it appears *immediately* as an argument expression.
9081 return getDerived().TransformExpr(E->getSubExpr());
John McCall31168b02011-06-15 23:02:42 +00009082}
9083
9084template<typename Derived>
9085ExprResult TreeTransform<Derived>::
9086TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier1dcde962012-08-08 18:46:20 +00009087 TypeSourceInfo *TSInfo
John McCall31168b02011-06-15 23:02:42 +00009088 = getDerived().TransformType(E->getTypeInfoAsWritten());
9089 if (!TSInfo)
9090 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009091
John McCall31168b02011-06-15 23:02:42 +00009092 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier1dcde962012-08-08 18:46:20 +00009093 if (Result.isInvalid())
John McCall31168b02011-06-15 23:02:42 +00009094 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009095
John McCall31168b02011-06-15 23:02:42 +00009096 if (!getDerived().AlwaysRebuild() &&
9097 TSInfo == E->getTypeInfoAsWritten() &&
9098 Result.get() == E->getSubExpr())
9099 return SemaRef.Owned(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009100
John McCall31168b02011-06-15 23:02:42 +00009101 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier1dcde962012-08-08 18:46:20 +00009102 E->getBridgeKeywordLoc(), TSInfo,
John McCall31168b02011-06-15 23:02:42 +00009103 Result.get());
9104}
9105
9106template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009107ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009108TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009109 // Transform arguments.
9110 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009111 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +00009112 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +00009113 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009114 &ArgChanged))
9115 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009116
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009117 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
9118 // Class message: transform the receiver type.
9119 TypeSourceInfo *ReceiverTypeInfo
9120 = getDerived().TransformType(E->getClassReceiverTypeInfo());
9121 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009122 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009123
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009124 // If nothing changed, just retain the existing message send.
9125 if (!getDerived().AlwaysRebuild() &&
9126 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009127 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009128
9129 // Build a new class message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009130 SmallVector<SourceLocation, 16> SelLocs;
9131 E->getSelectorLocs(SelLocs);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009132 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
9133 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009134 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009135 E->getMethodDecl(),
9136 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009137 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009138 E->getRightLoc());
9139 }
9140
9141 // Instance message: transform the receiver
9142 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
9143 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +00009144 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009145 = getDerived().TransformExpr(E->getInstanceReceiver());
9146 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009147 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009148
9149 // If nothing changed, just retain the existing message send.
9150 if (!getDerived().AlwaysRebuild() &&
9151 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009152 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009153
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009154 // Build a new instance message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009155 SmallVector<SourceLocation, 16> SelLocs;
9156 E->getSelectorLocs(SelLocs);
John McCallb268a282010-08-23 23:25:46 +00009157 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009158 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00009159 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009160 E->getMethodDecl(),
9161 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009162 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009163 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00009164}
9165
Mike Stump11289f42009-09-09 15:08:12 +00009166template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009167ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009168TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00009169 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009170}
9171
Mike Stump11289f42009-09-09 15:08:12 +00009172template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009173ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009174TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00009175 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009176}
9177
Mike Stump11289f42009-09-09 15:08:12 +00009178template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009179ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009180TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00009181 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00009182 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00009183 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009184 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +00009185
9186 // We don't need to transform the ivar; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +00009187
Douglas Gregord51d90d2010-04-26 20:11:03 +00009188 // If nothing changed, just retain the existing expression.
9189 if (!getDerived().AlwaysRebuild() &&
9190 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00009191 return SemaRef.Owned(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009192
John McCallb268a282010-08-23 23:25:46 +00009193 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00009194 E->getLocation(),
9195 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +00009196}
9197
Mike Stump11289f42009-09-09 15:08:12 +00009198template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009199ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009200TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +00009201 // 'super' and types never change. Property never changes. Just
9202 // retain the existing expression.
9203 if (!E->isObjectReceiver())
John McCallc3007a22010-10-26 07:05:15 +00009204 return SemaRef.Owned(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009205
Douglas Gregor9faee212010-04-26 20:47:02 +00009206 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00009207 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +00009208 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009209 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009210
Douglas Gregor9faee212010-04-26 20:47:02 +00009211 // We don't need to transform the property; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +00009212
Douglas Gregor9faee212010-04-26 20:47:02 +00009213 // If nothing changed, just retain the existing expression.
9214 if (!getDerived().AlwaysRebuild() &&
9215 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00009216 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009217
John McCallb7bd14f2010-12-02 01:19:52 +00009218 if (E->isExplicitProperty())
9219 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
9220 E->getExplicitProperty(),
9221 E->getLocation());
9222
9223 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall526ab472011-10-25 17:37:35 +00009224 SemaRef.Context.PseudoObjectTy,
John McCallb7bd14f2010-12-02 01:19:52 +00009225 E->getImplicitPropertyGetter(),
9226 E->getImplicitPropertySetter(),
9227 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00009228}
9229
Mike Stump11289f42009-09-09 15:08:12 +00009230template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009231ExprResult
Ted Kremeneke65b0862012-03-06 20:05:56 +00009232TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
9233 // Transform the base expression.
9234 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
9235 if (Base.isInvalid())
9236 return ExprError();
9237
9238 // Transform the key expression.
9239 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
9240 if (Key.isInvalid())
9241 return ExprError();
9242
9243 // If nothing changed, just retain the existing expression.
9244 if (!getDerived().AlwaysRebuild() &&
9245 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
9246 return SemaRef.Owned(E);
9247
Chad Rosier1dcde962012-08-08 18:46:20 +00009248 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremeneke65b0862012-03-06 20:05:56 +00009249 Base.get(), Key.get(),
9250 E->getAtIndexMethodDecl(),
9251 E->setAtIndexMethodDecl());
9252}
9253
9254template<typename Derived>
9255ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009256TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00009257 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00009258 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00009259 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009260 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009261
Douglas Gregord51d90d2010-04-26 20:11:03 +00009262 // If nothing changed, just retain the existing expression.
9263 if (!getDerived().AlwaysRebuild() &&
9264 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00009265 return SemaRef.Owned(E);
Chad Rosier1dcde962012-08-08 18:46:20 +00009266
John McCallb268a282010-08-23 23:25:46 +00009267 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00009268 E->getOpLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00009269 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +00009270}
9271
Mike Stump11289f42009-09-09 15:08:12 +00009272template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009273ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009274TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009275 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009276 SmallVector<Expr*, 8> SubExprs;
Douglas Gregora3efea12011-01-03 19:04:46 +00009277 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier1dcde962012-08-08 18:46:20 +00009278 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00009279 SubExprs, &ArgumentChanged))
9280 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009281
Douglas Gregora16548e2009-08-11 05:31:07 +00009282 if (!getDerived().AlwaysRebuild() &&
9283 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00009284 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00009285
Douglas Gregora16548e2009-08-11 05:31:07 +00009286 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009287 SubExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00009288 E->getRParenLoc());
9289}
9290
Mike Stump11289f42009-09-09 15:08:12 +00009291template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009292ExprResult
Hal Finkelc4d7c822013-09-18 03:29:45 +00009293TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) {
9294 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
9295 if (SrcExpr.isInvalid())
9296 return ExprError();
9297
9298 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
9299 if (!Type)
9300 return ExprError();
9301
9302 if (!getDerived().AlwaysRebuild() &&
9303 Type == E->getTypeSourceInfo() &&
9304 SrcExpr.get() == E->getSrcExpr())
9305 return SemaRef.Owned(E);
9306
9307 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
9308 SrcExpr.get(), Type,
9309 E->getRParenLoc());
9310}
9311
9312template<typename Derived>
9313ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009314TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +00009315 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier1dcde962012-08-08 18:46:20 +00009316
John McCall490112f2011-02-04 18:33:18 +00009317 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
9318 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
9319
9320 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahaniandd5eb9d2011-12-03 17:47:53 +00009321 blockScope->TheDecl->setBlockMissingReturnType(
9322 oldBlock->blockMissingReturnType());
Chad Rosier1dcde962012-08-08 18:46:20 +00009323
Chris Lattner01cf8db2011-07-20 06:58:45 +00009324 SmallVector<ParmVarDecl*, 4> params;
9325 SmallVector<QualType, 4> paramTypes;
Chad Rosier1dcde962012-08-08 18:46:20 +00009326
Fariborz Jahanian1babe772010-07-09 18:44:02 +00009327 // Parameter substitution.
John McCall490112f2011-02-04 18:33:18 +00009328 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
9329 oldBlock->param_begin(),
9330 oldBlock->param_size(),
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +00009331 0, paramTypes, &params)) {
9332 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009333 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +00009334 }
John McCall490112f2011-02-04 18:33:18 +00009335
Jordan Rosea0a86be2013-03-08 22:25:36 +00009336 const FunctionProtoType *exprFunctionType = E->getFunctionType();
Eli Friedman34b49062012-01-26 03:00:14 +00009337 QualType exprResultType =
Alp Toker314cc812014-01-25 16:55:45 +00009338 getDerived().TransformType(exprFunctionType->getReturnType());
Douglas Gregor476e3022011-01-19 21:32:01 +00009339
Jordan Rose5c382722013-03-08 21:51:21 +00009340 QualType functionType =
9341 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +00009342 exprFunctionType->getExtProtoInfo());
John McCall490112f2011-02-04 18:33:18 +00009343 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +00009344
9345 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +00009346 if (!params.empty())
David Blaikie9c70e042011-09-21 18:16:56 +00009347 blockScope->TheDecl->setParams(params);
Eli Friedman34b49062012-01-26 03:00:14 +00009348
9349 if (!oldBlock->blockMissingReturnType()) {
9350 blockScope->HasImplicitReturnType = false;
9351 blockScope->ReturnType = exprResultType;
9352 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009353
John McCall3882ace2011-01-05 12:14:39 +00009354 // Transform the body
John McCall490112f2011-02-04 18:33:18 +00009355 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +00009356 if (body.isInvalid()) {
9357 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
John McCall3882ace2011-01-05 12:14:39 +00009358 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +00009359 }
John McCall3882ace2011-01-05 12:14:39 +00009360
John McCall490112f2011-02-04 18:33:18 +00009361#ifndef NDEBUG
9362 // In builds with assertions, make sure that we captured everything we
9363 // captured before.
Douglas Gregor4385d8b2011-05-20 15:32:55 +00009364 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
Aaron Ballman9371dd22014-03-14 18:34:04 +00009365 for (const auto &I : oldBlock->captures()) {
9366 VarDecl *oldCapture = I.getVariable();
John McCall490112f2011-02-04 18:33:18 +00009367
Douglas Gregor4385d8b2011-05-20 15:32:55 +00009368 // Ignore parameter packs.
9369 if (isa<ParmVarDecl>(oldCapture) &&
9370 cast<ParmVarDecl>(oldCapture)->isParameterPack())
9371 continue;
John McCall490112f2011-02-04 18:33:18 +00009372
Douglas Gregor4385d8b2011-05-20 15:32:55 +00009373 VarDecl *newCapture =
9374 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
9375 oldCapture));
9376 assert(blockScope->CaptureMap.count(newCapture));
9377 }
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00009378 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCall490112f2011-02-04 18:33:18 +00009379 }
9380#endif
9381
9382 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
9383 /*Scope=*/0);
Douglas Gregora16548e2009-08-11 05:31:07 +00009384}
9385
Mike Stump11289f42009-09-09 15:08:12 +00009386template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009387ExprResult
Tanya Lattner55808c12011-06-04 00:47:47 +00009388TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikie83d382b2011-09-23 05:06:16 +00009389 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner55808c12011-06-04 00:47:47 +00009390}
Eli Friedmandf14b3a2011-10-11 02:20:01 +00009391
9392template<typename Derived>
9393ExprResult
9394TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedman8d3e43f2011-10-14 22:48:56 +00009395 QualType RetTy = getDerived().TransformType(E->getType());
9396 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009397 SmallVector<Expr*, 8> SubExprs;
Eli Friedman8d3e43f2011-10-14 22:48:56 +00009398 SubExprs.reserve(E->getNumSubExprs());
9399 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
9400 SubExprs, &ArgumentChanged))
9401 return ExprError();
9402
9403 if (!getDerived().AlwaysRebuild() &&
9404 !ArgumentChanged)
9405 return SemaRef.Owned(E);
9406
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009407 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedman8d3e43f2011-10-14 22:48:56 +00009408 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedmandf14b3a2011-10-11 02:20:01 +00009409}
Chad Rosier1dcde962012-08-08 18:46:20 +00009410
Douglas Gregora16548e2009-08-11 05:31:07 +00009411//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00009412// Type reconstruction
9413//===----------------------------------------------------------------------===//
9414
Mike Stump11289f42009-09-09 15:08:12 +00009415template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00009416QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
9417 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00009418 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009419 getDerived().getBaseEntity());
9420}
9421
Mike Stump11289f42009-09-09 15:08:12 +00009422template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00009423QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
9424 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00009425 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009426 getDerived().getBaseEntity());
9427}
9428
Mike Stump11289f42009-09-09 15:08:12 +00009429template<typename Derived>
9430QualType
John McCall70dd5f62009-10-30 00:06:24 +00009431TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
9432 bool WrittenAsLValue,
9433 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00009434 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +00009435 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00009436}
9437
9438template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009439QualType
John McCall70dd5f62009-10-30 00:06:24 +00009440TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
9441 QualType ClassType,
9442 SourceLocation Sigil) {
Reid Kleckner0503a872013-12-05 01:23:43 +00009443 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil,
9444 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00009445}
9446
9447template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009448QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00009449TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
9450 ArrayType::ArraySizeModifier SizeMod,
9451 const llvm::APInt *Size,
9452 Expr *SizeExpr,
9453 unsigned IndexTypeQuals,
9454 SourceRange BracketsRange) {
9455 if (SizeExpr || !Size)
9456 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
9457 IndexTypeQuals, BracketsRange,
9458 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00009459
9460 QualType Types[] = {
9461 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
9462 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
9463 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00009464 };
Craig Toppere5ce8312013-07-15 03:38:40 +00009465 const unsigned NumTypes = llvm::array_lengthof(Types);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009466 QualType SizeType;
9467 for (unsigned I = 0; I != NumTypes; ++I)
9468 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
9469 SizeType = Types[I];
9470 break;
9471 }
Mike Stump11289f42009-09-09 15:08:12 +00009472
Eli Friedman9562f392012-01-25 23:20:27 +00009473 // Note that we can return a VariableArrayType here in the case where
9474 // the element type was a dependent VariableArrayType.
9475 IntegerLiteral *ArraySize
9476 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
9477 /*FIXME*/BracketsRange.getBegin());
9478 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009479 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00009480 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00009481}
Mike Stump11289f42009-09-09 15:08:12 +00009482
Douglas Gregord6ff3322009-08-04 16:50:30 +00009483template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009484QualType
9485TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009486 ArrayType::ArraySizeModifier SizeMod,
9487 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00009488 unsigned IndexTypeQuals,
9489 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00009490 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00009491 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009492}
9493
9494template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009495QualType
Mike Stump11289f42009-09-09 15:08:12 +00009496TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009497 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00009498 unsigned IndexTypeQuals,
9499 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00009500 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00009501 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009502}
Mike Stump11289f42009-09-09 15:08:12 +00009503
Douglas Gregord6ff3322009-08-04 16:50:30 +00009504template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009505QualType
9506TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009507 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00009508 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009509 unsigned IndexTypeQuals,
9510 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00009511 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00009512 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009513 IndexTypeQuals, BracketsRange);
9514}
9515
9516template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009517QualType
9518TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009519 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00009520 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009521 unsigned IndexTypeQuals,
9522 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00009523 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00009524 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009525 IndexTypeQuals, BracketsRange);
9526}
9527
9528template<typename Derived>
9529QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +00009530 unsigned NumElements,
9531 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00009532 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +00009533 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009534}
Mike Stump11289f42009-09-09 15:08:12 +00009535
Douglas Gregord6ff3322009-08-04 16:50:30 +00009536template<typename Derived>
9537QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
9538 unsigned NumElements,
9539 SourceLocation AttributeLoc) {
9540 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
9541 NumElements, true);
9542 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00009543 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
9544 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +00009545 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009546}
Mike Stump11289f42009-09-09 15:08:12 +00009547
Douglas Gregord6ff3322009-08-04 16:50:30 +00009548template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009549QualType
9550TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +00009551 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009552 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +00009553 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009554}
Mike Stump11289f42009-09-09 15:08:12 +00009555
Douglas Gregord6ff3322009-08-04 16:50:30 +00009556template<typename Derived>
Jordan Rose5c382722013-03-08 21:51:21 +00009557QualType TreeTransform<Derived>::RebuildFunctionProtoType(
9558 QualType T,
9559 llvm::MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +00009560 const FunctionProtoType::ExtProtoInfo &EPI) {
9561 return SemaRef.BuildFunctionType(T, ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00009562 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +00009563 getDerived().getBaseEntity(),
Jordan Rosea0a86be2013-03-08 22:25:36 +00009564 EPI);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009565}
Mike Stump11289f42009-09-09 15:08:12 +00009566
Douglas Gregord6ff3322009-08-04 16:50:30 +00009567template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00009568QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
9569 return SemaRef.Context.getFunctionNoProtoType(T);
9570}
9571
9572template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00009573QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
9574 assert(D && "no decl found");
9575 if (D->isInvalidDecl()) return QualType();
9576
Douglas Gregorc298ffc2010-04-22 16:44:27 +00009577 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +00009578 TypeDecl *Ty;
9579 if (isa<UsingDecl>(D)) {
9580 UsingDecl *Using = cast<UsingDecl>(D);
Enea Zaffanellae05a3cf2013-07-22 10:54:09 +00009581 assert(Using->hasTypename() &&
John McCallb96ec562009-12-04 22:46:56 +00009582 "UnresolvedUsingTypenameDecl transformed to non-typename using");
9583
9584 // A valid resolved using typename decl points to exactly one type decl.
9585 assert(++Using->shadow_begin() == Using->shadow_end());
9586 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +00009587
John McCallb96ec562009-12-04 22:46:56 +00009588 } else {
9589 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
9590 "UnresolvedUsingTypenameDecl transformed to non-using decl");
9591 Ty = cast<UnresolvedUsingTypenameDecl>(D);
9592 }
9593
9594 return SemaRef.Context.getTypeDeclType(Ty);
9595}
9596
9597template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00009598QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
9599 SourceLocation Loc) {
9600 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009601}
9602
9603template<typename Derived>
9604QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
9605 return SemaRef.Context.getTypeOfType(Underlying);
9606}
9607
9608template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00009609QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
9610 SourceLocation Loc) {
9611 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009612}
9613
9614template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00009615QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
9616 UnaryTransformType::UTTKind UKind,
9617 SourceLocation Loc) {
9618 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
9619}
9620
9621template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00009622QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00009623 TemplateName Template,
9624 SourceLocation TemplateNameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +00009625 TemplateArgumentListInfo &TemplateArgs) {
John McCall6b51f282009-11-23 01:53:49 +00009626 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00009627}
Mike Stump11289f42009-09-09 15:08:12 +00009628
Douglas Gregor1135c352009-08-06 05:28:30 +00009629template<typename Derived>
Eli Friedman0dfb8892011-10-06 23:00:33 +00009630QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
9631 SourceLocation KWLoc) {
9632 return SemaRef.BuildAtomicType(ValueType, KWLoc);
9633}
9634
9635template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009636TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00009637TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +00009638 bool TemplateKW,
9639 TemplateDecl *Template) {
Douglas Gregor9db53502011-03-02 18:07:45 +00009640 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00009641 Template);
9642}
9643
9644template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00009645TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00009646TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
9647 const IdentifierInfo &Name,
9648 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +00009649 QualType ObjectType,
9650 NamedDecl *FirstQualifierInScope) {
Douglas Gregor9db53502011-03-02 18:07:45 +00009651 UnqualifiedId TemplateName;
9652 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregorbb119652010-06-16 23:00:59 +00009653 Sema::TemplateTy Template;
Abramo Bagnara7945c982012-01-27 09:46:47 +00009654 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregorbb119652010-06-16 23:00:59 +00009655 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009656 SS, TemplateKWLoc, TemplateName,
John McCallba7bf592010-08-24 05:47:05 +00009657 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00009658 /*EnteringContext=*/false,
9659 Template);
John McCall31f82722010-11-12 08:19:04 +00009660 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +00009661}
Mike Stump11289f42009-09-09 15:08:12 +00009662
Douglas Gregora16548e2009-08-11 05:31:07 +00009663template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00009664TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00009665TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +00009666 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +00009667 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +00009668 QualType ObjectType) {
Douglas Gregor71395fa2009-11-04 00:56:37 +00009669 UnqualifiedId Name;
Douglas Gregor9db53502011-03-02 18:07:45 +00009670 // FIXME: Bogus location information.
Abramo Bagnara7945c982012-01-27 09:46:47 +00009671 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregor9db53502011-03-02 18:07:45 +00009672 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnara7945c982012-01-27 09:46:47 +00009673 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregorbb119652010-06-16 23:00:59 +00009674 Sema::TemplateTy Template;
9675 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009676 SS, TemplateKWLoc, Name,
John McCallba7bf592010-08-24 05:47:05 +00009677 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00009678 /*EnteringContext=*/false,
9679 Template);
Serge Pavlov9ddb76e2013-08-27 13:15:56 +00009680 return Template.get();
Douglas Gregor71395fa2009-11-04 00:56:37 +00009681}
Chad Rosier1dcde962012-08-08 18:46:20 +00009682
Douglas Gregor71395fa2009-11-04 00:56:37 +00009683template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009684ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009685TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
9686 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00009687 Expr *OrigCallee,
9688 Expr *First,
9689 Expr *Second) {
9690 Expr *Callee = OrigCallee->IgnoreParenCasts();
9691 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00009692
Douglas Gregora16548e2009-08-11 05:31:07 +00009693 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00009694 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +00009695 if (!First->getType()->isOverloadableType() &&
9696 !Second->getType()->isOverloadableType())
9697 return getSema().CreateBuiltinArraySubscriptExpr(First,
9698 Callee->getLocStart(),
9699 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00009700 } else if (Op == OO_Arrow) {
9701 // -> is never a builtin operation.
John McCallb268a282010-08-23 23:25:46 +00009702 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
9703 } else if (Second == 0 || isPostIncDec) {
9704 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009705 // The argument is not of overloadable type, so try to create a
9706 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +00009707 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00009708 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00009709
John McCallb268a282010-08-23 23:25:46 +00009710 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00009711 }
9712 } else {
John McCallb268a282010-08-23 23:25:46 +00009713 if (!First->getType()->isOverloadableType() &&
9714 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009715 // Neither of the arguments is an overloadable type, so try to
9716 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +00009717 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00009718 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00009719 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +00009720 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009721 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009722
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009723 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00009724 }
9725 }
Mike Stump11289f42009-09-09 15:08:12 +00009726
9727 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00009728 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00009729 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00009730
John McCallb268a282010-08-23 23:25:46 +00009731 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +00009732 assert(ULE->requiresADL());
9733
9734 // FIXME: Do we have to check
9735 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall4c4c1df2010-01-26 03:27:55 +00009736 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00009737 } else {
Richard Smith58db83d2012-11-28 21:47:39 +00009738 // If we've resolved this to a particular non-member function, just call
9739 // that function. If we resolved it to a member function,
9740 // CreateOverloaded* will find that function for us.
9741 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
9742 if (!isa<CXXMethodDecl>(ND))
9743 Functions.addDecl(ND);
John McCalld14a8642009-11-21 08:51:07 +00009744 }
Mike Stump11289f42009-09-09 15:08:12 +00009745
Douglas Gregora16548e2009-08-11 05:31:07 +00009746 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +00009747 Expr *Args[2] = { First, Second };
9748 unsigned NumArgs = 1 + (Second != 0);
Mike Stump11289f42009-09-09 15:08:12 +00009749
Douglas Gregora16548e2009-08-11 05:31:07 +00009750 // Create the overloaded operator invocation for unary operators.
9751 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +00009752 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00009753 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +00009754 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00009755 }
Mike Stump11289f42009-09-09 15:08:12 +00009756
Douglas Gregore9d62932011-07-15 16:25:15 +00009757 if (Op == OO_Subscript) {
9758 SourceLocation LBrace;
9759 SourceLocation RBrace;
9760
9761 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
9762 DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
9763 LBrace = SourceLocation::getFromRawEncoding(
9764 NameLoc.CXXOperatorName.BeginOpNameLoc);
9765 RBrace = SourceLocation::getFromRawEncoding(
9766 NameLoc.CXXOperatorName.EndOpNameLoc);
9767 } else {
9768 LBrace = Callee->getLocStart();
9769 RBrace = OpLoc;
9770 }
9771
9772 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
9773 First, Second);
9774 }
Sebastian Redladba46e2009-10-29 20:17:01 +00009775
Douglas Gregora16548e2009-08-11 05:31:07 +00009776 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +00009777 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00009778 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00009779 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
9780 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009781 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009782
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009783 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00009784}
Mike Stump11289f42009-09-09 15:08:12 +00009785
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009786template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00009787ExprResult
John McCallb268a282010-08-23 23:25:46 +00009788TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009789 SourceLocation OperatorLoc,
9790 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +00009791 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009792 TypeSourceInfo *ScopeType,
9793 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00009794 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00009795 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +00009796 QualType BaseType = Base->getType();
9797 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009798 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier1dcde962012-08-08 18:46:20 +00009799 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +00009800 !BaseType->getAs<PointerType>()->getPointeeType()
9801 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009802 // This pseudo-destructor expression is still a pseudo-destructor.
John McCallb268a282010-08-23 23:25:46 +00009803 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009804 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00009805 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00009806 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009807 /*FIXME?*/true);
9808 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009809
Douglas Gregor678f90d2010-02-25 01:56:36 +00009810 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009811 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
9812 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
9813 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
9814 NameInfo.setNamedTypeInfo(DestroyedType);
9815
Richard Smith8e4a3862012-05-15 06:15:11 +00009816 // The scope type is now known to be a valid nested name specifier
9817 // component. Tack it on to the end of the nested name specifier.
9818 if (ScopeType)
9819 SS.Extend(SemaRef.Context, SourceLocation(),
9820 ScopeType->getTypeLoc(), CCLoc);
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009821
Abramo Bagnara7945c982012-01-27 09:46:47 +00009822 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCallb268a282010-08-23 23:25:46 +00009823 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009824 OperatorLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009825 SS, TemplateKWLoc,
9826 /*FIXME: FirstQualifier*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009827 NameInfo,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009828 /*TemplateArgs*/ 0);
9829}
9830
Tareq A. Siraj24110cc2013-04-16 18:53:08 +00009831template<typename Derived>
9832StmtResult
9833TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
Wei Pan17fbf6e2013-05-04 03:59:06 +00009834 SourceLocation Loc = S->getLocStart();
9835 unsigned NumParams = S->getCapturedDecl()->getNumParams();
9836 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/0,
9837 S->getCapturedRegionKind(), NumParams);
9838 StmtResult Body = getDerived().TransformStmt(S->getCapturedStmt());
9839
9840 if (Body.isInvalid()) {
9841 getSema().ActOnCapturedRegionError();
9842 return StmtError();
9843 }
9844
9845 return getSema().ActOnCapturedRegionEnd(Body.take());
Tareq A. Siraj24110cc2013-04-16 18:53:08 +00009846}
9847
Douglas Gregord6ff3322009-08-04 16:50:30 +00009848} // end namespace clang
9849
9850#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H